diff --git a/pipeline/pipeline.core/src/main/java/fiftyone/pipeline/core/typed/TypedKeyMapBuilder.java b/pipeline/pipeline.core/src/main/java/fiftyone/pipeline/core/typed/TypedKeyMapBuilder.java index 72e87bd3d..86c2f22c2 100644 --- a/pipeline/pipeline.core/src/main/java/fiftyone/pipeline/core/typed/TypedKeyMapBuilder.java +++ b/pipeline/pipeline.core/src/main/java/fiftyone/pipeline/core/typed/TypedKeyMapBuilder.java @@ -106,11 +106,11 @@ private static class TypedKeyMapInternal implements TypedKeyMap, Map) flowData -> new TestElementData(mock(Logger.class), flowData)); + + assertEquals(data, flowData.get("Device")); + assertEquals(data, flowData.get("DEVICE")); + } + + @Test + public void FlowData_GetOrAddOtherCase_SameData() { + flowData.process(); + ElementData data = flowData.getOrAdd( + "device", + (FlowElement.DataFactory) flowData -> new TestElementData(mock(Logger.class), flowData)); + + ElementData again = flowData.getOrAdd( + "Device", + (FlowElement.DataFactory) flowData -> new TestElementData(mock(Logger.class), flowData)); + + assertSame(data, again); + } + @Test public void FlowData_AddDataString_GetDataTypedKey() { flowData.process(); diff --git a/pipeline/pipeline.core/src/test/java/fiftyone/pipeline/core/typed/TypedKeyMapKeyCaseTests.java b/pipeline/pipeline.core/src/test/java/fiftyone/pipeline/core/typed/TypedKeyMapKeyCaseTests.java new file mode 100644 index 000000000..d11442221 --- /dev/null +++ b/pipeline/pipeline.core/src/test/java/fiftyone/pipeline/core/typed/TypedKeyMapKeyCaseTests.java @@ -0,0 +1,77 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.pipeline.core.typed; + +import org.junit.Test; + +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Keys ignore case, as the specification's access to results asks of + * string keys, in both kinds of map the builder makes. + */ +public class TypedKeyMapKeyCaseTests { + + private static final boolean[] CONCURRENT = {false, true}; + + @Test + public void get_OtherCase_FindsTheValue() { + for (boolean concurrent : CONCURRENT) { + TypedKeyMap map = new TypedKeyMapBuilder(concurrent).build(); + map.put(new TypedKeyDefault<>("device", String.class), "value"); + + assertEquals("value", + map.get(new TypedKeyDefault<>("Device", String.class))); + assertEquals("value", + map.get(new TypedKeyDefault<>("DEVICE", String.class))); + assertTrue(map.containsKey("Device")); + } + } + + @Test + public void put_OtherCase_ReplacesTheValue() { + for (boolean concurrent : CONCURRENT) { + TypedKeyMap map = new TypedKeyMapBuilder(concurrent).build(); + map.put(new TypedKeyDefault<>("device", String.class), "first"); + map.put(new TypedKeyDefault<>("Device", String.class), "second"); + + assertEquals(1, map.getKeys().size()); + assertEquals("second", + map.get(new TypedKeyDefault<>("device", String.class))); + } + } + + @Test + public void getKeys_KeepsTheSpellingFirstGiven() { + for (boolean concurrent : CONCURRENT) { + TypedKeyMap map = new TypedKeyMapBuilder(concurrent).build(); + map.put(new TypedKeyDefault<>("device", String.class), "first"); + map.put(new TypedKeyDefault<>("DEVICE", String.class), "second"); + + assertEquals(Collections.singletonList("device"), map.getKeys()); + } + } +}