Class SIQuantityTest

java.lang.Object
org.djunits.quantity.SIQuantityTest

public class SIQuantityTest extends Object
Unit tests for SIQuantity. This class focuses on the SI-agnostic scalar whose display unit is any SIUnit. The tests cover:

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 Details

    • SIQuantityTest

      public SIQuantityTest()
  • Method Details

    • pinLocale

      @BeforeAll static void pinLocale()
      Pin the default Locale for predictable formatting/parsing behavior across environments.
    • restoreLocale

      @AfterAll static void restoreLocale()
      Restore the default Locale for the FORMAT category after all tests complete.
    • constructorWithSIUnit

      @Test void constructorWithSIUnit()
      Verifies the primary constructor new SIQuantity(double, SIUnit).
      • Accepts a valid non-null SIUnit (e.g., m) and stores SI and display unit consistently
      • Rejects null unit (exception thrown by the Quantity base constructor)
    • constructorWithStringAbbreviation

      @Test void constructorWithStringAbbreviation()
      Verifies the string-abbreviation constructor new SIQuantity(double, String).
      • Resolves a valid SI unit string (e.g., "kg")
      • Builds a correctly-typed SIQuantity with consistent SI and display unit
    • copyConstructor

      @Test void copyConstructor()
      Verifies the copy constructor new SIQuantity(SIQuantity) produces an equal instance: same SI value and same display unit.
    • instantiateUsesCurrentDisplayUnit

      @Test void instantiateUsesCurrentDisplayUnit()
      Verifies SIQuantity.instantiate(double) creates a new instance with the same display unit as the receiver at call time (i.e., reflects the current getDisplayUnit() value).
    • siUnitReturnsCurrentUnit

      @Test void siUnitReturnsCurrentUnit()
      Verifies SIQuantity.siUnit() returns the current display unit (for SIQuantity this is its own SI unit).
    • getNamePrettyFormatting

      @Test void getNamePrettyFormatting()
      Verifies the "pretty name" behavior inherited from Quantity.getName() for the class name SIQuantity (camel case with internal capitals).

      Expected: "SIQuantity" becomes "S i quantity".

    • valueOfParsesAndValidates

      @Test void valueOfParsesAndValidates()
      Verifies SIQuantity.valueOf(String) happy path and error handling.
      • Parses "12.5 m" and " 12.5 m " (lenient spacing)
      • Rejects null text, empty text, and unknown unit
    • ofParsesAndValidates

      @Test void ofParsesAndValidates()
      Verifies SIQuantity.of(double, String) happy path and error handling.
      • Parses a known SI unit string (e.g., "kg")
      • Rejects null unit string, empty unit string, and unknown unit
    • toStringVariants

      @Test void toStringVariants()
      Verifies representative Quantity.toString() variants for an SIQuantity: default form, explicit target unit, verbose flag, and unit suppression.
    • displayUnitFluentAndEquality

      @Test void displayUnitFluentAndEquality()
      Verifies fluent Quantity.setDisplayUnit(org.djunits.unit.UnitInterface) returns this and that equals/hashCode include both SI bits and the display unit.
    • arithmeticProducesCorrectSIValues

      @Test void arithmeticProducesCorrectSIValues()
      Verifies Quantity.multiply(Quantity), Quantity.divide(Quantity), and Quantity.reciprocal() when applied to SIQuantity produce correct SI values (the unit algebra is validated in SIUnit tests).