Package org.djunits.quantity
Class SIQuantityTest
java.lang.Object
org.djunits.quantity.SIQuantityTest
Unit tests for
SIQuantity. This class focuses on the SI-agnostic scalar whose display unit is any SIUnit. The
tests cover:
- All constructors (value+unit, value+string-abbreviation, copy constructor)
SIQuantity.instantiate(double)andSIQuantity.siUnit()- Parsing helpers:
SIQuantity.valueOf(String)andSIQuantity.of(double, String) - Formatting and pretty name (
Quantity.getName()) behavior for the "SIQuantity" camel-case class name - Fluent
setDisplayUnitbehavior and equals/hashCode semantics - Representative arithmetic inherited from
Quantity: multiply/divide/reciprocal producingSIQuantity
Out of scope: we do not re-test SIUnit parsing/formatting logic in depth—those are covered by the
dedicated SIUnit test suite. Here we only verify interactions required by SIQuantity.
Locale pinning: The tests pin Locale.Category.FORMAT to Locale.US for deterministic number
parsing/formatting and restore it afterwards.
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 (specifications); Test implementation by Copilot.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidVerifiesQuantity.multiply(Quantity),Quantity.divide(Quantity), andQuantity.reciprocal()when applied toSIQuantityproduce correct SI values (the unit algebra is validated inSIUnittests).(package private) voidVerifies the primary constructornew SIQuantity(double, SIUnit).(package private) voidVerifies the string-abbreviation constructornew SIQuantity(double, String).(package private) voidVerifies the copy constructornew SIQuantity(SIQuantity)produces an equal instance: same SI value and same display unit.(package private) voidVerifies fluentQuantity.setDisplayUnit(org.djunits.unit.UnitInterface)returnsthisand that equals/hashCode include both SI bits and the display unit.(package private) voidVerifies the "pretty name" behavior inherited fromQuantity.getName()for the class nameSIQuantity(camel case with internal capitals).(package private) voidVerifiesSIQuantity.instantiate(double)creates a new instance with the same display unit as the receiver at call time (i.e., reflects the currentgetDisplayUnit()value).(package private) voidVerifiesSIQuantity.of(double, String)happy path and error handling.(package private) static voidPin the defaultLocalefor predictable formatting/parsing behavior across environments.(package private) static voidRestore the defaultLocalefor the FORMAT category after all tests complete.(package private) voidVerifiesSIQuantity.siUnit()returns the current display unit (for SIQuantity this is its own SI unit).(package private) voidVerifies representativeQuantity.toString()variants for anSIQuantity: default form, explicit target unit, verbose flag, and unit suppression.(package private) voidVerifiesSIQuantity.valueOf(String)happy path and error handling.
-
Constructor Details
-
SIQuantityTest
public SIQuantityTest()
-
-
Method Details
-
pinLocale
@BeforeAll static void pinLocale()Pin the defaultLocalefor predictable formatting/parsing behavior across environments. -
restoreLocale
@AfterAll static void restoreLocale()Restore the defaultLocalefor the FORMAT category after all tests complete. -
constructorWithSIUnit
@Test void constructorWithSIUnit() -
constructorWithStringAbbreviation
@Test void constructorWithStringAbbreviation()Verifies the string-abbreviation constructornew SIQuantity(double, String).- Resolves a valid SI unit string (e.g.,
"kg") - Builds a correctly-typed SIQuantity with consistent SI and display unit
- Resolves a valid SI unit string (e.g.,
-
copyConstructor
@Test void copyConstructor()Verifies the copy constructornew SIQuantity(SIQuantity)produces an equal instance: same SI value and same display unit. -
instantiateUsesCurrentDisplayUnit
@Test void instantiateUsesCurrentDisplayUnit()VerifiesSIQuantity.instantiate(double)creates a new instance with the same display unit as the receiver at call time (i.e., reflects the currentgetDisplayUnit()value). -
siUnitReturnsCurrentUnit
@Test void siUnitReturnsCurrentUnit()VerifiesSIQuantity.siUnit()returns the current display unit (for SIQuantity this is its own SI unit). -
getNamePrettyFormatting
@Test void getNamePrettyFormatting()Verifies the "pretty name" behavior inherited fromQuantity.getName()for the class nameSIQuantity(camel case with internal capitals).Expected:
"SIQuantity"becomes"S i quantity". -
valueOfParsesAndValidates
@Test void valueOfParsesAndValidates()VerifiesSIQuantity.valueOf(String)happy path and error handling.- Parses
"12.5 m"and" 12.5 m "(lenient spacing) - Rejects
nulltext, empty text, and unknown unit
- Parses
-
ofParsesAndValidates
@Test void ofParsesAndValidates()VerifiesSIQuantity.of(double, String)happy path and error handling.- Parses a known SI unit string (e.g.,
"kg") - Rejects
nullunit string, empty unit string, and unknown unit
- Parses a known SI unit string (e.g.,
-
toStringVariants
@Test void toStringVariants()Verifies representativeQuantity.toString()variants for anSIQuantity: default form, explicit target unit, verbose flag, and unit suppression. -
displayUnitFluentAndEquality
@Test void displayUnitFluentAndEquality()Verifies fluentQuantity.setDisplayUnit(org.djunits.unit.UnitInterface)returnsthisand that equals/hashCode include both SI bits and the display unit. -
arithmeticProducesCorrectSIValues
@Test void arithmeticProducesCorrectSIValues()VerifiesQuantity.multiply(Quantity),Quantity.divide(Quantity), andQuantity.reciprocal()when applied toSIQuantityproduce correct SI values (the unit algebra is validated inSIUnittests).
-