Class ReferenceTest

java.lang.Object
org.djunits.quantity.def.ReferenceTest

class ReferenceTest extends Object
ReferenceTest tests the AbstractReference registry, including per-class isolation of reference ids, duplicate detection within a class, and snapshot behavior of the returned reference map.

The tests use Position.Reference (and a small check with Time.Reference) to validate the per-class registry and collision handling of AbstractReference. 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.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static class 
    Empty reference class.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    Verifies equals, hashCode, toString(), containsId().
    (package private) final void
    Set Locale.US for consistent formatting.
    (package private) void
    Verify that references can be added and retrieved by id for a specific Reference subclass, and that the same id can be reused safely in a different Reference subclass (per-class isolation; no cross-quantity collisions).
    (package private) void
    Adding two references with the same id to the same Reference subclass must throw an IllegalArgumentException on the second attempt.
    (package private) void
    getReferenceMap() must return a snapshot (defensive copy) of the internal registry of the corresponding Reference subclass.
    (package private) void
    Sanity-check a single-level offset: define B = A + 10 m (for Position), and verify that 0 @ B equals +10 relative to A.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ReferenceTest

      ReferenceTest()
  • Method Details

    • setup

      @BeforeEach final void setup()
      Set Locale.US for consistent formatting.
    • testAddGetAndPerClassIsolation

      @Test void testAddGetAndPerClassIsolation()
      Verify that references can be added and retrieved by id for a specific Reference subclass, and that the same id can be reused safely in a different Reference subclass (per-class isolation; no cross-quantity collisions).
    • testDuplicateIdWithinSameClassThrows

      @Test void testDuplicateIdWithinSameClassThrows()
      Adding two references with the same id to the same Reference subclass must throw an IllegalArgumentException on the second attempt.
    • testGetReferenceMapIsSnapshot

      @Test void testGetReferenceMapIsSnapshot()
      getReferenceMap() must return a snapshot (defensive copy) of the internal registry of the corresponding Reference subclass. Modifying the returned map must not affect the registry itself.
    • testSingleLevelOffsetStillWorks

      @Test void testSingleLevelOffsetStillWorks()
      Sanity-check a single-level offset: define B = A + 10 m (for Position), and verify that 0 @ B equals +10 relative to A. (This verifies that the registry changes do not disturb reference semantics.)
    • equalsHashCode

      @Test void equalsHashCode()
      Verifies equals, hashCode, toString(), containsId().