Package org.djunits.unit
Class UnitsTest
java.lang.Object
org.djunits.unit.UnitsTest
Unit tests for the
Units utility covering US parsing, localization lookups, bundle loading, nested-class naming, and
safe-copy behavior.
Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
- Author:
- Alexander Verbraeck
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classUnitInterface class that does not register itself.(package private) static classQuantity Q.(package private) static classUnitInterface Length class that does not register itself. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVerify the UTF-8 ResourceBundle loader can read localized files and retrieve non-ASCII content.voidVerify localized display and name lookup and fallback behavior. - Present localized display (e.g., DE Ångström has display U+212B) - Fallback to stored display/name when not present in the bundle.voidVerifyUnits.localizedQuantityName(Locale, String)falls back to the provided default when the key is missing for a given locale.voidVerify localized resolution for French and German where abbreviations differ from US. - FR:unit.Frequency.rpm.abbr = tr/min- DE:unit.Power.hp(M).abbr = PS,unit.Speed.kt.abbr = knvoidVerifyUnits.registeredUnits()returns a safe top-level copy: mutating the returned map does not affect the internal UNIT_MAP.voidTest register/unregister and retrieving localication for unknown quantities.<U extends UnitInterface<U,?>>
voidVerify US-locale resolution of common unit abbreviations viaUnits.resolve(Class, String).voidVerifyUnits.unitClassName(Class)returns nested names (e.g., "Length.Unit") rather than just "Unit", and trims package name.
-
Constructor Details
-
UnitsTest
public UnitsTest()
-
-
Method Details
-
testResolveUsLocaleParsing
Verify US-locale resolution of common unit abbreviations viaUnits.resolve(Class, String). Stores and restores the original default locale.- Type Parameters:
U- a n anonymous unit type
-
testLocalizedResolveFrAndDe
@Test public void testLocalizedResolveFrAndDe()Verify localized resolution for French and German where abbreviations differ from US. - FR:unit.Frequency.rpm.abbr = tr/min- DE:unit.Power.hp(M).abbr = PS,unit.Speed.kt.abbr = kn -
testLocalizedDisplayAndName
@Test public void testLocalizedDisplayAndName()Verify localized display and name lookup and fallback behavior. - Present localized display (e.g., DE Ångström has display U+212B) - Fallback to stored display/name when not present in the bundle. -
testUnitClassNameForNested
@Test public void testUnitClassNameForNested()VerifyUnits.unitClassName(Class)returns nested names (e.g., "Length.Unit") rather than just "Unit", and trims package name. -
testLocalizedQuantityNameFallback
@Test public void testLocalizedQuantityNameFallback()VerifyUnits.localizedQuantityName(Locale, String)falls back to the provided default when the key is missing for a given locale. -
testRegisteredUnitsSafeTopLevelCopy
@Test public void testRegisteredUnitsSafeTopLevelCopy()VerifyUnits.registeredUnits()returns a safe top-level copy: mutating the returned map does not affect the internal UNIT_MAP. -
testBundleUtf8ControlLoadsFiles
@Test public void testBundleUtf8ControlLoadsFiles()Verify the UTF-8 ResourceBundle loader can read localized files and retrieve non-ASCII content. -
testRegisterUnregister
@Test public void testRegisterUnregister()Test register/unregister and retrieving localication for unknown quantities.
-