Class UnitsTest

java.lang.Object
org.djunits.unit.UnitsTest

public class UnitsTest extends Object
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
  • Constructor Details

    • UnitsTest

      public UnitsTest()
  • Method Details

    • testResolveUsLocaleParsing

      @Test public <U extends UnitInterface<U, ?>> void testResolveUsLocaleParsing()
      Verify US-locale resolution of common unit abbreviations via Units.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()
      Verify Units.unitClassName(Class) returns nested names (e.g., "Length.Unit") rather than just "Unit", and trims package name.
    • testLocalizedQuantityNameFallback

      @Test public void testLocalizedQuantityNameFallback()
      Verify Units.localizedQuantityName(Locale, String) falls back to the provided default when the key is missing for a given locale.
    • testRegisteredUnitsSafeTopLevelCopy

      @Test public void testRegisteredUnitsSafeTopLevelCopy()
      Verify Units.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.