From 640a1a81617a10bae883c732a3d6f79e16daf5f0 Mon Sep 17 00:00:00 2001 From: Speiger Date: Thu, 29 Jun 2023 20:04:45 +0200 Subject: [PATCH] Fixed tests and added missing changelog --- Changelog.md | 1 + .../src/builder/modules/MapModule.java | 7 + .../builder/maps/MapTestSuiteBuilder.template | 14 ++ ...apComputeIfAbsentNonDefaultTester.template | 153 ++++++++++++++++++ .../maps/MapComputeIfAbsentTester.template | 30 ++-- ...pComputeIfPresentNonDefaultTester.template | 104 ++++++++++++ .../maps/MapComputeIfPresentTester.template | 12 +- .../maps/MapComputeNonDefaultTester.template | 148 +++++++++++++++++ .../tests/maps/MapComputeTester.template | 26 ++- ...MapSupplyIfAbsentNonDefaultTester.template | 130 +++++++++++++++ .../maps/MapSupplyIfAbsentTester.template | 27 ++-- 11 files changed, 620 insertions(+), 32 deletions(-) create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentNonDefaultTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentNonDefaultTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeNonDefaultTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentNonDefaultTester.template diff --git a/Changelog.md b/Changelog.md index 9c8f69ff..7a0eb2ca 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ - Added: Iterators/Async Builders now support MapToPrimitiveType function on the object variant. So more processing can be done. (Will be expanded upon later versions) - Fixed: SetValue wasn't working on forEach implementations. - Fixed: Compute functions now perform with primitives more java compliant. Meaning that getDefaultReturnValue function no longer is seen as null. +- Fixed: Supplier was using the wrong dataType in their function name. - Updated: SimpleCodeGenerator 1.3.0 is now being used which allows for iterative code support. ### Version 0.8.0 diff --git a/src/builder/java/speiger/src/builder/modules/MapModule.java b/src/builder/java/speiger/src/builder/modules/MapModule.java index 8ee2f0c9..f8a4f0e7 100644 --- a/src/builder/java/speiger/src/builder/modules/MapModule.java +++ b/src/builder/java/speiger/src/builder/modules/MapModule.java @@ -108,6 +108,9 @@ protected void loadBlockades() addBlockedFiles("TestOrderedMapGenerator"); addBlockedFilter(T -> T.endsWith("Tester") && (T.startsWith("Map") || T.startsWith("OrderedMap") || T.startsWith("SortedMap") || T.startsWith("NavigableMap"))); } + if(valueType == ClassType.OBJECT) { + addBlockedFiles("MapComputeIfAbsentNonDefaultTester", "MapComputeIfPresentNonDefaultTester", "MapComputeNonDefaultTester", "MapSupplyIfAbsentNonDefaultTester"); + } } @Override @@ -158,6 +161,9 @@ protected void loadRemappers() addBiRequirement("MapComputeIfAbsentTester"); addBiRequirement("MapComputeIfPresentTester"); addBiRequirement("MapComputeTester"); + addBiRequirement("MapComputeIfAbsentNonDefaultTester"); + addBiRequirement("MapComputeIfPresentNonDefaultTester"); + addBiRequirement("MapComputeNonDefaultTester"); addBiRequirement("MapCopyTester"); addBiRequirement("MapContainsTester"); addBiRequirement("MapContainsKeyTester"); @@ -184,6 +190,7 @@ protected void loadRemappers() addBiRequirement("MapReplaceTester"); addBiRequirement("MapSizeTester"); addBiRequirement("MapSupplyIfAbsentTester"); + addBiRequirement("MapSupplyIfAbsentNonDefaultTester"); addBiRequirement("MapToStringTester"); addBiRequirement("NavigableMapNavigationTester"); addBiRequirement("SortedMapNavigationTester"); diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/maps/MapTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/maps/MapTestSuiteBuilder.template index 557b92ab..74ea9fb0 100644 --- a/src/builder/resources/speiger/assets/testers/templates/builder/maps/MapTestSuiteBuilder.template +++ b/src/builder/resources/speiger/assets/testers/templates/builder/maps/MapTestSuiteBuilder.template @@ -53,6 +53,11 @@ import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapCl import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester; import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester; import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester; +#if !VALUE_OBJECT +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentNonDefaultTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentNonDefaultTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeNonDefaultTester; +#endif import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapCopyTester; import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester; import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsKeyTester; @@ -78,6 +83,9 @@ import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapRe import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceTester; import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSizeTester; import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester; +#if !VALUE_OBJECT +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentNonDefaultTester; +#endif import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapToStringTester; import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder; import speiger.src.testers.objects.generators.TestObjectSetGenerator; @@ -105,6 +113,12 @@ public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder protected List> getTesters() { List> testers = new ArrayList<>(); testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapClearTester.class); +#if !VALUE_OBJECT + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeNonDefaultTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentNonDefaultTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentNonDefaultTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentNonDefaultTester.class); +#endif testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester.class); testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester.class); testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester.class); diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentNonDefaultTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentNonDefaultTester.template new file mode 100644 index 00000000..ac5f1038 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentNonDefaultTester.template @@ -0,0 +1,153 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore +#if !VALUE_BOOLEAN +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +#endignore +#endif + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import junit.framework.AssertionFailedError; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testComputeIfAbsent_supportedAbsent() { +#if VALUE_BOOLEAN + getMap().setDefaultReturnValue(true); +#endif + assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> { + assertEquals(k3(), k); + return v3(); + })); + expectAdded(e3()); + } + +#if !VALUE_BOOLEAN +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(ONE) +#endignore + public void testComputeIfAbsent_supportedAbsentFirst() { + getMap().setDefaultReturnValue(v0()); + assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> { + assertEquals(k0(), k); + return v3(); + })); + expectContents(entry(k0(), v3())); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(ONE) +#endignore + public void testComputeIfAbsent_supportedAbsentSameResult() { + getMap().setDefaultReturnValue(v0()); + assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> { + assertEquals(k0(), k); + return v0(); + })); + expectUnchanged(); + } + +#endif +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfAbsent_supportedPresent() { + assertEquals("COMPUTE_IF_ABSENT(present, function) should return existing value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> { + throw new AssertionFailedError(); + })); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testComputeIfAbsent_functionReturnsNullNotInserted() { + assertEquals("COMPUTE_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> { + assertEquals(k3(), k); + return INVALID_VALUE; + })); + expectUnchanged(); + } + + static class ExpectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testComputeIfAbsent_functionThrows() { + try { + getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> { + assertEquals(k3(), k); + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testComputeIfAbsent_unsupportedAbsent() { + try { + getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> { + // allowed to be called + assertEquals(k3(), k); + return v3(); + }); + fail("COMPUTE_IF_ABSENT(notPresent, function) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfAbsent_unsupportedPresentExistingValue() { + try { + assertEquals("COMPUTE_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> { + assertEquals(k0(), k); + return v0(); + })); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfAbsent_unsupportedPresentDifferentValue() { + try { + assertEquals("COMPUTE_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> { + assertEquals(k0(), k); + return v3(); + })); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentTester.template index 4e1c9f27..a3bce282 100644 --- a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentTester.template +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentTester.template @@ -26,7 +26,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN @MapFeature.Require(SUPPORTS_PUT) #endignore public void testComputeIfAbsent_supportedAbsent() { - assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> { + assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENT(k3(), k -> { assertEquals(k3(), k); return v3(); })); @@ -40,11 +40,19 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN #endignore public void testComputeIfAbsent_supportedAbsentFirst() { getMap().setDefaultReturnValue(v0()); - assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> { +#if VALUE_OBJECT + assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENT(k0(), k -> { assertEquals(k0(), k); return v3(); })); expectContents(entry(k0(), v3())); +#else + assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> { + assertEquals(k0(), k); + return v3(); + })); + expectUnchanged(); +#endif } #ignore @@ -53,7 +61,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN #endignore public void testComputeIfAbsent_supportedAbsentSameResult() { getMap().setDefaultReturnValue(v0()); - assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> { + assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> { assertEquals(k0(), k); return v0(); })); @@ -66,7 +74,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN @CollectionSize.Require(absent = ZERO) #endignore public void testComputeIfAbsent_supportedPresent() { - assertEquals("COMPUTE_IF_ABSENT(present, function) should return existing value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> { + assertEquals("COMPUTE_IF_ABSENT(present, function) should return existing value", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> { throw new AssertionFailedError(); })); expectUnchanged(); @@ -76,11 +84,15 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN @MapFeature.Require(SUPPORTS_PUT) #endignore public void testComputeIfAbsent_functionReturnsNullNotInserted() { - assertEquals("COMPUTE_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> { + assertEquals("COMPUTE_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_ABSENT(k3(), k -> { assertEquals(k3(), k); return INVALID_VALUE; })); +#if VALUE_OBJECT expectUnchanged(); +#else + expectAdded(entry(k3(), INVALID_VALUE)); +#endif } static class ExpectedException extends RuntimeException { @@ -92,7 +104,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN #endignore public void testComputeIfAbsent_functionThrows() { try { - getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> { + getMap().COMPUTE_IF_ABSENT(k3(), k -> { assertEquals(k3(), k); throw new ExpectedException(); }); @@ -107,7 +119,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN #endignore public void testComputeIfAbsent_unsupportedAbsent() { try { - getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> { + getMap().COMPUTE_IF_ABSENT(k3(), k -> { // allowed to be called assertEquals(k3(), k); return v3(); @@ -124,7 +136,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN #endignore public void testComputeIfAbsent_unsupportedPresentExistingValue() { try { - assertEquals("COMPUTE_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> { + assertEquals("COMPUTE_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> { assertEquals(k0(), k); return v0(); })); @@ -139,7 +151,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN #endignore public void testComputeIfAbsent_unsupportedPresentDifferentValue() { try { - assertEquals("COMPUTE_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> { + assertEquals("COMPUTE_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> { assertEquals(k0(), k); return v3(); })); diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentNonDefaultTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentNonDefaultTester.template new file mode 100644 index 00000000..9d2636d1 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentNonDefaultTester.template @@ -0,0 +1,104 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import junit.framework.AssertionFailedError; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testComputeIfPresent_supportedAbsent() { + assertEquals("COMPUTE_IF_PRESENT(notPresent, function) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> { + throw new AssertionFailedError(); + })); + expectUnchanged(); + } + +#if !VALUE_BOOLEAN +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfPresent_supportedPresent() { + assertEquals("COMPUTE_IF_PRESENT(present, function) should return new value", v3(), getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + return v3(); + })); + expectReplacement(entry(k0(), v3())); + } + +#endif +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfPresent_functionReturnsNull() { + assertEquals("COMPUTE_IF_PRESENT(present, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + return INVALID_VALUE; + })); + expectMissing(e0()); + } + + static class ExpectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfPresent_functionThrows() { + try { + getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testComputeIfPresent_unsupportedAbsent() { + try { + getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> { + throw new AssertionFailedError(); + }); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfPresent_unsupportedPresent() { + try { + getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> v3()); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentTester.template index a37b521d..85e6abfd 100644 --- a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentTester.template +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentTester.template @@ -21,7 +21,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE @MapFeature.Require(SUPPORTS_PUT) #endignore public void testComputeIfPresent_supportedAbsent() { - assertEquals("COMPUTE_IF_PRESENT(notPresent, function) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> { + assertEquals("COMPUTE_IF_PRESENT(notPresent, function) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENT(k3(), (k, v) -> { throw new AssertionFailedError(); })); expectUnchanged(); @@ -32,7 +32,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE @CollectionSize.Require(absent = ZERO) #endignore public void testComputeIfPresent_supportedPresent() { - assertEquals("COMPUTE_IF_PRESENT(present, function) should return new value", v3(), getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> { + assertEquals("COMPUTE_IF_PRESENT(present, function) should return new value", v3(), getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> { assertEquals(k0(), k); assertEquals(v0(), v); return v3(); @@ -45,7 +45,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE @CollectionSize.Require(absent = ZERO) #endignore public void testComputeIfPresent_functionReturnsNull() { - assertEquals("COMPUTE_IF_PRESENT(present, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> { + assertEquals("COMPUTE_IF_PRESENT(present, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> { assertEquals(k0(), k); assertEquals(v0(), v); return INVALID_VALUE; @@ -63,7 +63,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE #endignore public void testComputeIfPresent_functionThrows() { try { - getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> { + getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> { assertEquals(k0(), k); assertEquals(v0(), v); throw new ExpectedException(); @@ -79,7 +79,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE #endignore public void testComputeIfPresent_unsupportedAbsent() { try { - getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> { + getMap().COMPUTE_IF_PRESENT(k3(), (k, v) -> { throw new AssertionFailedError(); }); } catch (UnsupportedOperationException tolerated) { @@ -93,7 +93,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE #endignore public void testComputeIfPresent_unsupportedPresent() { try { - getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> v3()); + getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> v3()); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException expected) { } diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeNonDefaultTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeNonDefaultTester.template new file mode 100644 index 00000000..e0bb40a9 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeNonDefaultTester.template @@ -0,0 +1,148 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#if !VALUE_BOOLEAN +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) +#endignore + public void testCompute_absentToPresent() { + assertEquals("Map.COMPUTE(absent, functionReturningValue) should return value", v3(), getMap().COMPUTENonDefault(k3(), (k, v) -> { + assertEquals(k3(), k); + assertEquals(INVALID_VALUE, v); + return v3(); + })); + expectAdded(e3()); + assertEquals(getNumElements() + 1, getMap().size()); + } +#endif + +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) +#endignore + public void testCompute_absentToAbsent() { + assertEquals("Map.COMPUTE(absent, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k3(), (k, v) -> { + assertEquals(k3(), k); + assertEquals(INVALID_VALUE, v); + return INVALID_VALUE; + })); + expectUnchanged(); + assertEquals(getNumElements(), getMap().size()); + } + +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testCompute_presentToPresent() { +#if VALUE_BOOLEAN + getMap().setDefaultReturnValue(true); +#endif + assertEquals("Map.COMPUTE(present, functionReturningValue) should return new value", v3(), getMap().COMPUTENonDefault(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + return v3(); + })); + expectReplacement(entry(k0(), v3())); + assertEquals(getNumElements(), getMap().size()); + } + +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testCompute_presentToAbsent() { + assertEquals("Map.COMPUTE(present, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + return INVALID_VALUE; + })); + expectMissing(e0()); + expectMissingKeys(k0()); + assertEquals(getNumElements() - 1, getMap().size()); + } + + static class ExpectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testCompute_presentFunctionThrows() { + try { + getMap().COMPUTENonDefault(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) +#endignore + public void testCompute_absentFunctionThrows() { + try { + getMap().COMPUTENonDefault(k3(), (k, v) -> { + assertEquals(k3(), k); + assertEquals(INVALID_VALUE, v); + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testCompute_removeAbsent() { + try { + getMap().COMPUTENonDefault(k3(), (k, v) -> { + assertEquals(k3(), k); + assertEquals(INVALID_VALUE, v); + return INVALID_VALUE; + }); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testCompute_putAbsent() { + try { + getMap().COMPUTENonDefault(k3(), (k, v) -> { + assertEquals(k3(), k); + assertEquals(INVALID_VALUE, v); + return INVALID_VALUE; + }); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeTester.template index c22883ef..53d9f36a 100644 --- a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeTester.template +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeTester.template @@ -21,7 +21,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) #endignore public void testCompute_absentToPresent() { - assertEquals("Map.COMPUTE(absent, functionReturningValue) should return value", v3(), getMap().COMPUTENonDefault(k3(), (k, v) -> { + assertEquals("Map.COMPUTE(absent, functionReturningValue) should return value", v3(), getMap().COMPUTE(k3(), (k, v) -> { assertEquals(k3(), k); assertEquals(INVALID_VALUE, v); return v3(); @@ -34,13 +34,18 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) #endignore public void testCompute_absentToAbsent() { - assertEquals("Map.COMPUTE(absent, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k3(), (k, v) -> { + assertEquals("Map.COMPUTE(absent, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE(k3(), (k, v) -> { assertEquals(k3(), k); assertEquals(INVALID_VALUE, v); return INVALID_VALUE; })); +#if VALUE_OBJECT expectUnchanged(); assertEquals(getNumElements(), getMap().size()); +#else + expectAdded(entry(k3(), INVALID_VALUE)); + assertEquals(getNumElements()+1, getMap().size()); +#endif } #ignore @@ -48,7 +53,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP @CollectionSize.Require(absent = ZERO) #endignore public void testCompute_presentToPresent() { - assertEquals("Map.COMPUTE(present, functionReturningValue) should return new value", v3(), getMap().COMPUTENonDefault(k0(), (k, v) -> { + assertEquals("Map.COMPUTE(present, functionReturningValue) should return new value", v3(), getMap().COMPUTE(k0(), (k, v) -> { assertEquals(k0(), k); assertEquals(v0(), v); return v3(); @@ -62,14 +67,19 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP @CollectionSize.Require(absent = ZERO) #endignore public void testCompute_presentToAbsent() { - assertEquals("Map.COMPUTE(present, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k0(), (k, v) -> { + assertEquals("Map.COMPUTE(present, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE(k0(), (k, v) -> { assertEquals(k0(), k); assertEquals(v0(), v); return INVALID_VALUE; })); +#if VALUE_OBJECT expectMissing(e0()); expectMissingKeys(k0()); assertEquals(getNumElements() - 1, getMap().size()); +#else + expectReplacement(entry(k0(), INVALID_VALUE)); + assertEquals(getNumElements(), getMap().size()); +#endif } static class ExpectedException extends RuntimeException { @@ -82,7 +92,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP #endignore public void testCompute_presentFunctionThrows() { try { - getMap().COMPUTENonDefault(k0(), (k, v) -> { + getMap().COMPUTE(k0(), (k, v) -> { assertEquals(k0(), k); assertEquals(v0(), v); throw new ExpectedException(); @@ -98,7 +108,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP #endignore public void testCompute_absentFunctionThrows() { try { - getMap().COMPUTENonDefault(k3(), (k, v) -> { + getMap().COMPUTE(k3(), (k, v) -> { assertEquals(k3(), k); assertEquals(INVALID_VALUE, v); throw new ExpectedException(); @@ -114,7 +124,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP #endignore public void testCompute_removeAbsent() { try { - getMap().COMPUTENonDefault(k3(), (k, v) -> { + getMap().COMPUTE(k3(), (k, v) -> { assertEquals(k3(), k); assertEquals(INVALID_VALUE, v); return INVALID_VALUE; @@ -130,7 +140,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP #endignore public void testCompute_putAbsent() { try { - getMap().COMPUTENonDefault(k3(), (k, v) -> { + getMap().COMPUTE(k3(), (k, v) -> { assertEquals(k3(), k); assertEquals(INVALID_VALUE, v); return INVALID_VALUE; diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentNonDefaultTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentNonDefaultTester.template new file mode 100644 index 00000000..fed201f6 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentNonDefaultTester.template @@ -0,0 +1,130 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore +#if !VALUE_BOOLEAN +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +#endignore +#endif + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import junit.framework.AssertionFailedError; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testSupplyIfAbsent_supportedAbsent() { +#if VALUE_BOOLEAN + getMap().setDefaultReturnValue(true); +#endif + assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3)); + expectAdded(e3()); + } + +#if !VALUE_BOOLEAN +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(ONE) +#endignore + public void testSupplyIfAbsent_supportedAbsentFirst() { + getMap().setDefaultReturnValue(v0()); + assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3)); + expectContents(entry(k0(), v3())); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(ONE) +#endignore + public void testSupplyIfAbsent_supportedAbsentSameResult() { + getMap().setDefaultReturnValue(v0()); + assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0)); + expectUnchanged(); + } + +#endif +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSupplyIfAbsent_supportedPresent() { + assertEquals("SUPPLY_IF_ABSENT(present, function) should return existing value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), () -> { + throw new AssertionFailedError(); + })); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testSupplyIfAbsent_functionReturnsNullNotInserted() { + assertEquals("SUPPLY_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> INVALID_VALUE)); + expectUnchanged(); + } + + static class ExpectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testSupplyIfAbsent_functionThrows() { + try { + getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> { + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testSupplyIfAbsent_unsupportedAbsent() { + try { + getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3); + fail("SUPPLY_IF_ABSENT(notPresent, function) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSupplyIfAbsent_unsupportedPresentExistingValue() { + try { + assertEquals("SUPPLY_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0)); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSupplyIfAbsent_unsupportedPresentDifferentValue() { + try { + assertEquals("SUPPLY_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3)); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentTester.template index 254960ad..310c1c5d 100644 --- a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentTester.template +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentTester.template @@ -26,7 +26,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE @MapFeature.Require(SUPPORTS_PUT) #endignore public void testSupplyIfAbsent_supportedAbsent() { - assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3)); + assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENT(k3(), this::v3)); expectAdded(e3()); } @@ -37,8 +37,13 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE #endignore public void testSupplyIfAbsent_supportedAbsentFirst() { getMap().setDefaultReturnValue(v0()); - assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3)); +#if VALUE_OBJECT + assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENT(k0(), this::v3)); expectContents(entry(k0(), v3())); +#else + assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v3)); + expectUnchanged(); +#endif } #ignore @@ -47,7 +52,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE #endignore public void testSupplyIfAbsent_supportedAbsentSameResult() { getMap().setDefaultReturnValue(v0()); - assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0)); + assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v0)); expectUnchanged(); } @@ -57,7 +62,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE @CollectionSize.Require(absent = ZERO) #endignore public void testSupplyIfAbsent_supportedPresent() { - assertEquals("SUPPLY_IF_ABSENT(present, function) should return existing value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), () -> { + assertEquals("SUPPLY_IF_ABSENT(present, function) should return existing value", v0(), getMap().SUPPLY_IF_ABSENT(k0(), () -> { throw new AssertionFailedError(); })); expectUnchanged(); @@ -67,8 +72,12 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE @MapFeature.Require(SUPPORTS_PUT) #endignore public void testSupplyIfAbsent_functionReturnsNullNotInserted() { - assertEquals("SUPPLY_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> INVALID_VALUE)); + assertEquals("SUPPLY_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().SUPPLY_IF_ABSENT(k3(), () -> INVALID_VALUE)); +#if VALUE_OBJECT expectUnchanged(); +#else + expectAdded(entry(k3(), INVALID_VALUE)); +#endif } static class ExpectedException extends RuntimeException { @@ -80,7 +89,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE #endignore public void testSupplyIfAbsent_functionThrows() { try { - getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> { + getMap().SUPPLY_IF_ABSENT(k3(), () -> { throw new ExpectedException(); }); fail("Expected ExpectedException"); @@ -94,7 +103,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE #endignore public void testSupplyIfAbsent_unsupportedAbsent() { try { - getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3); + getMap().SUPPLY_IF_ABSENT(k3(), this::v3); fail("SUPPLY_IF_ABSENT(notPresent, function) should throw"); } catch (UnsupportedOperationException expected) { } @@ -107,7 +116,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE #endignore public void testSupplyIfAbsent_unsupportedPresentExistingValue() { try { - assertEquals("SUPPLY_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0)); + assertEquals("SUPPLY_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v0)); } catch (UnsupportedOperationException tolerated) { } expectUnchanged(); @@ -119,7 +128,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE #endignore public void testSupplyIfAbsent_unsupportedPresentDifferentValue() { try { - assertEquals("SUPPLY_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3)); + assertEquals("SUPPLY_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v3)); } catch (UnsupportedOperationException tolerated) { } expectUnchanged();