Skip to content

Commit

Permalink
Fixed tests and added missing changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Speiger committed Jun 29, 2023
1 parent 274d37c commit 640a1a8
Show file tree
Hide file tree
Showing 11 changed files with 620 additions and 32 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/builder/java/speiger/src/builder/modules/MapModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -184,6 +190,7 @@ protected void loadRemappers()
addBiRequirement("MapReplaceTester");
addBiRequirement("MapSizeTester");
addBiRequirement("MapSupplyIfAbsentTester");
addBiRequirement("MapSupplyIfAbsentNonDefaultTester");
addBiRequirement("MapToStringTester");
addBiRequirement("NavigableMapNavigationTester");
addBiRequirement("SortedMapNavigationTester");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -105,6 +113,12 @@ public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder
protected List<Class<? extends AbstractTester>> getTesters() {
List<Class<? extends AbstractTester>> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
Expand All @@ -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
Expand All @@ -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();
}));
Expand All @@ -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();
Expand All @@ -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 {
Expand All @@ -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();
});
Expand All @@ -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();
Expand All @@ -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();
}));
Expand All @@ -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();
}));
Expand Down
Loading

0 comments on commit 640a1a8

Please sign in to comment.