Package org.djunits.quantity.def
Class ReferenceTest
java.lang.Object
org.djunits.quantity.def.ReferenceTest
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 ClassesModifier and TypeClassDescription(package private) static classEmpty reference class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidVerifiesequals,hashCode,toString(),containsId().(package private) final voidsetup()Set Locale.US for consistent formatting.(package private) voidVerify 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) voidAdding two references with the same id to the same Reference subclass must throw an IllegalArgumentException on the second attempt.(package private) voidgetReferenceMap() must return a snapshot (defensive copy) of the internal registry of the corresponding Reference subclass.(package private) voidSanity-check a single-level offset: define B = A + 10 m (for Position), and verify that 0 @ B equals +10 relative to A.
-
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()Verifiesequals,hashCode,toString(),containsId().
-