diff --git a/gcm4/src/main/java/plugins/personproperties/testsupport/PersonPropertiesActionSupport.java b/gcm4/src/main/java/plugins/personproperties/testsupport/PersonPropertiesActionSupport.java index 552c8651c..496e98858 100644 --- a/gcm4/src/main/java/plugins/personproperties/testsupport/PersonPropertiesActionSupport.java +++ b/gcm4/src/main/java/plugins/personproperties/testsupport/PersonPropertiesActionSupport.java @@ -30,6 +30,8 @@ public class PersonPropertiesActionSupport { + private PersonPropertiesActionSupport(){} + public static void testConsumer(int initialPopulation, long seed, Consumer consumer) { TestPluginData.Builder pluginBuilder = TestPluginData.builder(); diff --git a/gcm4/src/main/java/plugins/regions/testsupport/TestRegionPropertyId.java b/gcm4/src/main/java/plugins/regions/testsupport/TestRegionPropertyId.java index 19d0a4ee2..f73dfe59d 100644 --- a/gcm4/src/main/java/plugins/regions/testsupport/TestRegionPropertyId.java +++ b/gcm4/src/main/java/plugins/regions/testsupport/TestRegionPropertyId.java @@ -141,7 +141,7 @@ public T getRandomPropertyValue(final RandomGenerator randomGenerator) { * Returns the test region property id values associated with property * definitions that have default values. */ - public static List getPropertesWithDefaultValues() { + public static List getPropertiesWithDefaultValues() { List result = new ArrayList<>(); for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.values()) { if (testRegionPropertyId.propertyDefinition.getDefaultValue().isPresent()) { @@ -155,7 +155,7 @@ public static List getPropertesWithDefaultValues() { * Returns the test region property id values associated with property * definitions that do not have default values. */ - public static List getPropertesWithoutDefaultValues() { + public static List getPropertiesWithoutDefaultValues() { List result = new ArrayList<>(); for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.values()) { if (testRegionPropertyId.propertyDefinition.getDefaultValue().isEmpty()) { diff --git a/gcm4/src/test/java/plugins/personproperties/actors/AT_PersonPropertyInteractionReport.java b/gcm4/src/test/java/plugins/personproperties/actors/AT_PersonPropertyInteractionReport.java new file mode 100644 index 000000000..76c2d8e68 --- /dev/null +++ b/gcm4/src/test/java/plugins/personproperties/actors/AT_PersonPropertyInteractionReport.java @@ -0,0 +1,54 @@ +package plugins.personproperties.actors; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +import nucleus.ActorContext; +import plugins.personproperties.support.PersonPropertyId; +import plugins.personproperties.testsupport.TestPersonPropertyId; +import plugins.reports.support.ReportError; +import plugins.reports.support.ReportId; +import plugins.reports.support.ReportPeriod; +import plugins.reports.support.SimpleReportId; +import tools.annotations.UnitTag; +import tools.annotations.UnitTest; +import tools.annotations.UnitTestConstructor; +import tools.annotations.UnitTestMethod; +import util.errors.ContractException; + +@UnitTest(target = PersonPropertyInteractionReport.class) +public class AT_PersonPropertyInteractionReport { + + @Test + @UnitTestConstructor(args = { ReportId.class, ReportPeriod.class, PersonPropertyId[].class }) + public void testConstructor() { + ReportId reportId = new SimpleReportId(1000); + ReportPeriod reportPeriod = ReportPeriod.DAILY; + PersonPropertyId[] personPropertyIds = { TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK, + TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK }; + + PersonPropertyInteractionReport report = new PersonPropertyInteractionReport(reportId, reportPeriod, + personPropertyIds); + + assertNotNull(report); + + // precondition: report id is null + ContractException contractException = assertThrows(ContractException.class, + () -> new PersonPropertyInteractionReport(null, reportPeriod, personPropertyIds)); + assertEquals(ReportError.NULL_REPORT_ID, contractException.getErrorType()); + + // precondition: report period is null + contractException = assertThrows(ContractException.class, + () -> new PersonPropertyInteractionReport(reportId, null, personPropertyIds)); + assertEquals(ReportError.NULL_REPORT_PERIOD, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(name = "init", args = { ActorContext.class }, tags = { UnitTag.INCOMPLETE }) + public void testInit() { + // TBD + } +} diff --git a/gcm4/src/test/java/plugins/personproperties/actors/AT_PersonPropertyReport.java b/gcm4/src/test/java/plugins/personproperties/actors/AT_PersonPropertyReport.java new file mode 100644 index 000000000..da91dee9b --- /dev/null +++ b/gcm4/src/test/java/plugins/personproperties/actors/AT_PersonPropertyReport.java @@ -0,0 +1,160 @@ +package plugins.personproperties.actors; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +import nucleus.ActorContext; +import plugins.personproperties.support.PersonPropertyId; +import plugins.personproperties.testsupport.TestPersonPropertyId; +import plugins.reports.support.ReportError; +import plugins.reports.support.ReportId; +import plugins.reports.support.ReportPeriod; +import plugins.reports.support.SimpleReportId; +import plugins.util.properties.PropertyError; +import tools.annotations.UnitTag; +import tools.annotations.UnitTest; +import tools.annotations.UnitTestMethod; +import util.errors.ContractException; + +@UnitTest(target = PersonPropertyReport.class) +public class AT_PersonPropertyReport { + + @Test + @UnitTestMethod(name = "builder", args = {}) + public void testBuilder() { + PersonPropertyReport.Builder builder = PersonPropertyReport.builder(); + + assertNotNull(builder); + } + + @Test + @UnitTestMethod(name = "init", args = { ActorContext.class }, tags = { UnitTag.INCOMPLETE }) + public void testInit() { + // TBD + } + + @Test + @UnitTestMethod(target = PersonPropertyReport.Builder.class, name = "build", args = {}) + public void testBuild() { + PersonPropertyReport.Builder builder = PersonPropertyReport.builder(); + + builder.setReportId(new SimpleReportId(1000)); + builder.setReportPeriod(ReportPeriod.DAILY); + + PersonPropertyReport report = builder.build(); + + assertNotNull(report); + + // precondition: null report id + ContractException contractException = assertThrows(ContractException.class, + () -> { + PersonPropertyReport.builder().setReportPeriod(ReportPeriod.DAILY).build(); + }); + assertEquals(ReportError.NULL_REPORT_ID, contractException.getErrorType()); + + // precondition: null report period + contractException = assertThrows(ContractException.class, + () -> { + PersonPropertyReport.builder().setReportId(new SimpleReportId(1000)).build(); + }); + assertEquals(ReportError.NULL_REPORT_PERIOD, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = PersonPropertyReport.Builder.class, name = "setReportId", args = { ReportId.class }) + public void testSetReportId() { + PersonPropertyReport.Builder builder = PersonPropertyReport.builder(); + ReportId reportId = new SimpleReportId(1000); + builder.setReportId(reportId); + builder.setReportPeriod(ReportPeriod.DAILY); + + PersonPropertyReport report = builder.build(); + + assertNotNull(report); + + // precondition: report id is null + ContractException contractException = assertThrows(ContractException.class, + () -> { + PersonPropertyReport.builder().setReportId(null); + }); + assertEquals(ReportError.NULL_REPORT_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = PersonPropertyReport.Builder.class, name = "setReportPeriod", args = { + ReportPeriod.class }) + public void testSetReportPeriod() { + PersonPropertyReport.Builder builder = PersonPropertyReport.builder(); + ReportId reportId = new SimpleReportId(1000); + ReportPeriod reportPeriod = ReportPeriod.DAILY; + builder.setReportId(reportId); + builder.setReportPeriod(reportPeriod); + + PersonPropertyReport report = builder.build(); + + assertNotNull(report); + + // precondition: report period is null + ContractException contractException = assertThrows(ContractException.class, + () -> { + PersonPropertyReport.builder().setReportPeriod(null); + }); + assertEquals(ReportError.NULL_REPORT_PERIOD, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = PersonPropertyReport.Builder.class, name = "setDefaultInclusion", args = { + boolean.class }) + public void testSetDefaultInclusion() { + // nothing to test + } + + @Test + @UnitTestMethod(target = PersonPropertyReport.Builder.class, name = "includePersonProperty", args = { + PersonPropertyId.class }) + public void testIncludePersonProperty() { + PersonPropertyReport.Builder builder = PersonPropertyReport.builder(); + ReportId reportId = new SimpleReportId(1000); + ReportPeriod reportPeriod = ReportPeriod.DAILY; + builder.setReportId(reportId); + builder.setReportPeriod(reportPeriod); + builder.includePersonProperty(TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK); + + PersonPropertyReport report = builder.build(); + + assertNotNull(report); + + // precondition: person property id is null + ContractException contractException = assertThrows(ContractException.class, + () -> { + PersonPropertyReport.builder().includePersonProperty(null); + }); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = PersonPropertyReport.Builder.class, name = "excludePersonProperty", args = { + PersonPropertyId.class }) + public void testExcludePersonProperty() { + PersonPropertyReport.Builder builder = PersonPropertyReport.builder(); + ReportId reportId = new SimpleReportId(1000); + ReportPeriod reportPeriod = ReportPeriod.DAILY; + builder.setReportId(reportId); + builder.setReportPeriod(reportPeriod); + builder.excludePersonProperty(TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK); + + PersonPropertyReport report = builder.build(); + + assertNotNull(report); + + // precondition: person property id is null + ContractException contractException = assertThrows(ContractException.class, + () -> { + PersonPropertyReport.builder().excludePersonProperty(null); + }); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + } +} diff --git a/gcm4/src/test/java/plugins/personproperties/events/AT_PersonPropertyDefinitionEvent.java b/gcm4/src/test/java/plugins/personproperties/events/AT_PersonPropertyDefinitionEvent.java new file mode 100644 index 000000000..4a4ae6e4d --- /dev/null +++ b/gcm4/src/test/java/plugins/personproperties/events/AT_PersonPropertyDefinitionEvent.java @@ -0,0 +1,43 @@ +package plugins.personproperties.events; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +import plugins.personproperties.support.PersonPropertyId; +import plugins.personproperties.testsupport.TestPersonPropertyId; +import plugins.util.properties.PropertyError; +import tools.annotations.UnitTest; +import tools.annotations.UnitTestConstructor; +import tools.annotations.UnitTestMethod; +import util.errors.ContractException; + +@UnitTest(target = PersonPropertyDefinitionEvent.class) +public class AT_PersonPropertyDefinitionEvent { + + @Test + @UnitTestConstructor(args = { PersonPropertyId.class }) + public void testConstructor() { + PersonPropertyDefinitionEvent personPropertyDefinitionEvent = new PersonPropertyDefinitionEvent( + TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK); + + assertNotNull(personPropertyDefinitionEvent); + + // precondition: person property id is null + ContractException contractException = assertThrows(ContractException.class, + () -> new PersonPropertyDefinitionEvent(null)); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(name="getPersonPropertyId", args={}) + public void testGetPersonPropertyId() { + PersonPropertyId personPropertyId = TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK; + PersonPropertyDefinitionEvent personPropertyDefinitionEvent = new PersonPropertyDefinitionEvent(personPropertyId); + + assertNotNull(personPropertyDefinitionEvent); + assertEquals(personPropertyId, personPropertyDefinitionEvent.getPersonPropertyId()); + } +} diff --git a/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyDefinitionInitialization.java b/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyDefinitionInitialization.java new file mode 100644 index 000000000..a7b140a90 --- /dev/null +++ b/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyDefinitionInitialization.java @@ -0,0 +1,254 @@ +package plugins.personproperties.support; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.math3.random.RandomGenerator; +import org.apache.commons.math3.util.Pair; +import org.junit.jupiter.api.Test; + +import plugins.people.support.PersonError; +import plugins.people.support.PersonId; +import plugins.personproperties.testsupport.TestPersonPropertyId; +import plugins.util.properties.PropertyDefinition; +import plugins.util.properties.PropertyError; +import plugins.util.properties.TimeTrackingPolicy; +import tools.annotations.UnitTest; +import tools.annotations.UnitTestMethod; +import util.errors.ContractException; +import util.random.RandomGeneratorProvider; + +@UnitTest(target = PersonPropertyDefinitionInitialization.class) +public class AT_PersonPropertyDefinitionInitialization { + + @Test + @UnitTestMethod(name = "builder", args = {}) + public void testBuilder() { + PersonPropertyDefinitionInitialization.Builder builder = PersonPropertyDefinitionInitialization.builder(); + + assertNotNull(builder); + } + + @Test + @UnitTestMethod(name = "getPropertyDefinition", args = {}) + public void testGetPropertyDefinition() { + PersonPropertyDefinitionInitialization.Builder builder = PersonPropertyDefinitionInitialization.builder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder() + .setType(Integer.class) + .setDefaultValue(100) + .setPropertyValueMutability(true) + .setTimeTrackingPolicy(TimeTrackingPolicy.DO_NOT_TRACK_TIME) + .build(); + + builder.setPropertyDefinition(propertyDefinition); + builder.setPersonPropertyId(TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK); + + PersonPropertyDefinitionInitialization propertyDefinitionInitialization = builder.build(); + + assertNotNull(propertyDefinitionInitialization); + assertEquals(propertyDefinition, propertyDefinitionInitialization.getPropertyDefinition()); + } + + @Test + @UnitTestMethod(name = "getPropertyValues", args = {}) + public void testGetPropertyValues() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2754843240208076356L); + + PersonPropertyDefinitionInitialization.Builder builder = PersonPropertyDefinitionInitialization.builder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder() + .setType(Integer.class) + .setDefaultValue(100) + .setPropertyValueMutability(true) + .setTimeTrackingPolicy(TimeTrackingPolicy.DO_NOT_TRACK_TIME) + .build(); + + builder.setPropertyDefinition(propertyDefinition); + builder.setPersonPropertyId(TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK); + + List> expectedValues = new ArrayList<>(); + + for (int i = 0; i < 20; i++) { + int value = randomGenerator.nextInt(100); + PersonId personId = new PersonId(i * 2); + builder.addPropertyValue(personId, value); + expectedValues.add(new Pair<>(personId, value)); + } + + PersonPropertyDefinitionInitialization propertyDefinitionInitialization = builder.build(); + + assertNotNull(propertyDefinitionInitialization); + + List> actualValues = propertyDefinitionInitialization.getPropertyValues(); + assertNotNull(actualValues); + assertFalse(actualValues.isEmpty()); + assertEquals(expectedValues, actualValues); + } + + @Test + @UnitTestMethod(name = "getPersonPropertyId", args = {}) + public void testGetPersonPropertyId() { + PersonPropertyDefinitionInitialization.Builder builder = PersonPropertyDefinitionInitialization.builder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder() + .setType(Integer.class) + .setDefaultValue(100) + .setPropertyValueMutability(true) + .setTimeTrackingPolicy(TimeTrackingPolicy.DO_NOT_TRACK_TIME) + .build(); + PersonPropertyId personPropertyId = TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK; + builder.setPropertyDefinition(propertyDefinition); + builder.setPersonPropertyId(personPropertyId); + PersonPropertyDefinitionInitialization propertyDefinitionInitialization = builder.build(); + + assertNotNull(propertyDefinitionInitialization); + assertEquals(personPropertyId, propertyDefinitionInitialization.getPersonPropertyId()); + } + + @Test + @UnitTestMethod(target = PersonPropertyDefinitionInitialization.Builder.class, name = "build", args = {}) + public void testBuild() { + PersonPropertyDefinitionInitialization.Builder builder = PersonPropertyDefinitionInitialization.builder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder() + .setType(Integer.class) + .setDefaultValue(100) + .setPropertyValueMutability(true) + .setTimeTrackingPolicy(TimeTrackingPolicy.DO_NOT_TRACK_TIME) + .build(); + PersonPropertyId personPropertyId = TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK; + builder.setPropertyDefinition(propertyDefinition); + builder.setPersonPropertyId(personPropertyId); + PersonPropertyDefinitionInitialization propertyDefinitionInitialization = builder.build(); + + assertNotNull(propertyDefinitionInitialization); + + // precondition: null propertyDefinition + ContractException contractException = assertThrows(ContractException.class, () -> { + PersonPropertyDefinitionInitialization.builder() + .setPersonPropertyId(personPropertyId) + .build(); + }); + assertEquals(PropertyError.NULL_PROPERTY_DEFINITION, contractException.getErrorType()); + + // precondition: person property id is null + contractException = assertThrows(ContractException.class, () -> { + PersonPropertyDefinitionInitialization.builder() + .setPropertyDefinition(propertyDefinition) + .build(); + }); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + // precondition: incomaptible value + contractException = assertThrows(ContractException.class, () -> { + PersonPropertyDefinitionInitialization.builder() + .setPropertyDefinition(propertyDefinition) + .setPersonPropertyId(personPropertyId) + .addPropertyValue(new PersonId(1000), "100") + .build(); + }); + assertEquals(PropertyError.INCOMPATIBLE_VALUE, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = PersonPropertyDefinitionInitialization.Builder.class, name = "setPropertyDefinition", args = { + PropertyDefinition.class }) + public void testSetPropertyDefinition() { + PersonPropertyDefinitionInitialization.Builder builder = PersonPropertyDefinitionInitialization.builder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder() + .setType(Double.class) + .setDefaultValue(100.0) + .setPropertyValueMutability(true) + .setTimeTrackingPolicy(TimeTrackingPolicy.DO_NOT_TRACK_TIME) + .build(); + PersonPropertyId personPropertyId = TestPersonPropertyId.PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK; + builder.setPropertyDefinition(propertyDefinition); + builder.setPersonPropertyId(personPropertyId); + PersonPropertyDefinitionInitialization propertyDefinitionInitialization = builder.build(); + + assertNotNull(propertyDefinitionInitialization); + assertEquals(personPropertyId, propertyDefinitionInitialization.getPersonPropertyId()); + + // precondition: property definition is null + ContractException contractException = assertThrows(ContractException.class, () -> { + PersonPropertyDefinitionInitialization.builder() + .setPropertyDefinition(null); + }); + assertEquals(PropertyError.NULL_PROPERTY_DEFINITION, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = PersonPropertyDefinitionInitialization.Builder.class, name = "addPropertyValue", args = { + PersonId.class, Object.class }) + public void testAddPropertyValue() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2816191091329528844L); + + PersonPropertyDefinitionInitialization.Builder builder = PersonPropertyDefinitionInitialization.builder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder() + .setType(Double.class) + .setDefaultValue(100.0) + .setPropertyValueMutability(true) + .setTimeTrackingPolicy(TimeTrackingPolicy.DO_NOT_TRACK_TIME) + .build(); + + builder.setPropertyDefinition(propertyDefinition); + builder.setPersonPropertyId(TestPersonPropertyId.PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK); + + List> expectedValues = new ArrayList<>(); + for (int i = 0; i < 20; i++) { + double value = randomGenerator.nextDouble() * 100; + PersonId personId = new PersonId(i * 2); + builder.addPropertyValue(personId, value); + expectedValues.add(new Pair<>(personId, value)); + } + + PersonPropertyDefinitionInitialization propertyDefinitionInitialization = builder.build(); + List> actualValues = propertyDefinitionInitialization.getPropertyValues(); + assertNotNull(actualValues); + assertFalse(actualValues.isEmpty()); + assertEquals(expectedValues, actualValues); + + // precondition: null person id + ContractException contractException = assertThrows(ContractException.class, () -> { + PersonPropertyDefinitionInitialization.builder() + .addPropertyValue(null, 100.0); + }); + assertEquals(PersonError.NULL_PERSON_ID, contractException.getErrorType()); + + // precondition: value is null + contractException = assertThrows(ContractException.class, () -> { + PersonPropertyDefinitionInitialization.builder() + .addPropertyValue(new PersonId(1000), null); + }); + assertEquals(PropertyError.NULL_PROPERTY_VALUE, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = PersonPropertyDefinitionInitialization.Builder.class, name = "setPersonPropertyId", args = { + PersonPropertyId.class }) + public void testSetPersonPropertyId() { + PersonPropertyDefinitionInitialization.Builder builder = PersonPropertyDefinitionInitialization.builder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder() + .setType(Double.class) + .setDefaultValue(100.0) + .setPropertyValueMutability(true) + .setTimeTrackingPolicy(TimeTrackingPolicy.DO_NOT_TRACK_TIME) + .build(); + PersonPropertyId personPropertyId = TestPersonPropertyId.PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK; + builder.setPropertyDefinition(propertyDefinition); + builder.setPersonPropertyId(personPropertyId); + PersonPropertyDefinitionInitialization propertyDefinitionInitialization = builder.build(); + + assertNotNull(propertyDefinitionInitialization); + assertEquals(personPropertyId, propertyDefinitionInitialization.getPersonPropertyId()); + + // precondition: property id is null + ContractException contractException = assertThrows(ContractException.class, () -> { + PersonPropertyDefinitionInitialization.builder() + .setPersonPropertyId(null); + }); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + } +} diff --git a/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyInitialization.java b/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyInitialization.java index deaf10cb2..84391d6f3 100644 --- a/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyInitialization.java +++ b/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyInitialization.java @@ -1,6 +1,7 @@ package plugins.personproperties.support; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import org.junit.jupiter.api.Test; @@ -23,7 +24,8 @@ public void testConstructor() { public void testGetPersonPropertyId() { PersonPropertyId personPropertyId = TestPersonPropertyId.PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK; Double value = 2.7; - PersonPropertyInitialization personPropertyInitialization = new PersonPropertyInitialization(personPropertyId, value); + PersonPropertyInitialization personPropertyInitialization = new PersonPropertyInitialization(personPropertyId, + value); assertEquals(personPropertyId, personPropertyInitialization.getPersonPropertyId()); } @@ -32,8 +34,150 @@ public void testGetPersonPropertyId() { public void testGetValue() { PersonPropertyId personPropertyId = TestPersonPropertyId.PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK; Double value = 2.7; - PersonPropertyInitialization personPropertyInitialization = new PersonPropertyInitialization(personPropertyId, value); + PersonPropertyInitialization personPropertyInitialization = new PersonPropertyInitialization(personPropertyId, + value); assertEquals(value, personPropertyInitialization.getValue()); } + @Test + @UnitTestMethod(name = "equals", args = { Object.class }) + public void testEquals() { + PersonPropertyInitialization personProp1 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK, + 2.7); + PersonPropertyInitialization personProp2 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK, + false); + PersonPropertyInitialization personProp3 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK, + true); + PersonPropertyInitialization personProp4 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK, + 20); + PersonPropertyInitialization personProp5 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK, + 2.7); + PersonPropertyInitialization personProp6 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK, + 20); + + // reflexive + assertEquals(personProp1, personProp1); + assertEquals(personProp2, personProp2); + assertEquals(personProp3, personProp3); + assertEquals(personProp4, personProp4); + assertEquals(personProp5, personProp5); + assertEquals(personProp6, personProp6); + + // symmetric + assertEquals(personProp1, personProp5); + assertEquals(personProp5, personProp1); + assertEquals(personProp4, personProp6); + assertEquals(personProp6, personProp4); + + assertNotEquals(personProp1, personProp2); + assertNotEquals(personProp1, personProp3); + assertNotEquals(personProp1, personProp4); + assertNotEquals(personProp1, personProp6); + + assertNotEquals(personProp2, personProp1); + assertNotEquals(personProp2, personProp3); + assertNotEquals(personProp2, personProp4); + assertNotEquals(personProp2, personProp5); + assertNotEquals(personProp2, personProp6); + + assertNotEquals(personProp3, personProp1); + assertNotEquals(personProp3, personProp2); + assertNotEquals(personProp3, personProp4); + assertNotEquals(personProp3, personProp5); + assertNotEquals(personProp3, personProp6); + + assertNotEquals(personProp4, personProp1); + assertNotEquals(personProp4, personProp2); + assertNotEquals(personProp4, personProp3); + assertNotEquals(personProp4, personProp5); + + assertNotEquals(personProp5, personProp2); + assertNotEquals(personProp5, personProp3); + assertNotEquals(personProp5, personProp4); + assertNotEquals(personProp5, personProp6); + + assertNotEquals(personProp6, personProp1); + assertNotEquals(personProp6, personProp2); + assertNotEquals(personProp6, personProp3); + assertNotEquals(personProp6, personProp5); + + assertNotEquals(personProp1, null); + assertNotEquals(personProp2, null); + assertNotEquals(personProp3, null); + assertNotEquals(personProp4, null); + assertNotEquals(personProp5, null); + assertNotEquals(personProp6, null); + } + + @Test + @UnitTestMethod(name = "toString", args = {}) + public void testToString() { + PersonPropertyId personPropertyId = TestPersonPropertyId.PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK; + Double value = 2.7; + PersonPropertyInitialization personPropertyInitialization = new PersonPropertyInitialization(personPropertyId, + value); + String expectedString = "PersonPropertyAssignment [personPropertyId=PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK, value=2.7]"; + + assertEquals(expectedString, personPropertyInitialization.toString()); + } + + @Test + @UnitTestMethod(name = "hashCode", args = {}) + public void testHashCode() { + PersonPropertyInitialization personProp1 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK, + 2.7); + PersonPropertyInitialization personProp2 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK, + false); + PersonPropertyInitialization personProp3 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK, + 20); + PersonPropertyInitialization personProp4 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_3_DOUBLE_MUTABLE_NO_TRACK, + 2.7); + PersonPropertyInitialization personProp5 = new PersonPropertyInitialization( + TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK, + 20); + + // reflexive + assertEquals(personProp1.hashCode(), personProp1.hashCode()); + assertEquals(personProp2.hashCode(), personProp2.hashCode()); + assertEquals(personProp3.hashCode(), personProp3.hashCode()); + assertEquals(personProp4.hashCode(), personProp4.hashCode()); + assertEquals(personProp5.hashCode(), personProp5.hashCode()); + + // symmetric + assertEquals(personProp1.hashCode(), personProp4.hashCode()); + assertEquals(personProp4.hashCode(), personProp1.hashCode()); + assertEquals(personProp3.hashCode(), personProp5.hashCode()); + assertEquals(personProp5.hashCode(), personProp3.hashCode()); + + assertNotEquals(personProp1.hashCode(), personProp2.hashCode()); + assertNotEquals(personProp1.hashCode(), personProp3.hashCode()); + assertNotEquals(personProp1.hashCode(), personProp5.hashCode()); + + assertNotEquals(personProp2.hashCode(), personProp1.hashCode()); + assertNotEquals(personProp2.hashCode(), personProp3.hashCode()); + assertNotEquals(personProp2.hashCode(), personProp4.hashCode()); + assertNotEquals(personProp2.hashCode(), personProp5.hashCode()); + + assertNotEquals(personProp3.hashCode(), personProp1.hashCode()); + assertNotEquals(personProp3.hashCode(), personProp2.hashCode()); + assertNotEquals(personProp3.hashCode(), personProp4.hashCode()); + + assertNotEquals(personProp4.hashCode(), personProp2.hashCode()); + assertNotEquals(personProp4.hashCode(), personProp3.hashCode()); + assertNotEquals(personProp4.hashCode(), personProp5.hashCode()); + + assertNotEquals(personProp5.hashCode(), personProp1.hashCode()); + assertNotEquals(personProp5.hashCode(), personProp2.hashCode()); + assertNotEquals(personProp5.hashCode(), personProp4.hashCode()); + } } diff --git a/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyLabeler.java b/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyLabeler.java index a3cb9bd6d..dabad4f02 100644 --- a/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyLabeler.java +++ b/gcm4/src/test/java/plugins/personproperties/support/AT_PersonPropertyLabeler.java @@ -13,6 +13,7 @@ import org.apache.commons.math3.random.RandomGenerator; import org.junit.jupiter.api.Test; +import nucleus.Event; import nucleus.SimulationContext; import plugins.partitions.support.LabelerSensitivity; import plugins.people.datamanagers.PeopleDataManager; @@ -65,7 +66,8 @@ public void testGetLabelerSensitivities() { * person property id. */ PersonId personId = new PersonId(56); - PersonPropertyUpdateEvent personPropertyUpdateEvent = new PersonPropertyUpdateEvent(personId, personPropertyId, false, true); + PersonPropertyUpdateEvent personPropertyUpdateEvent = new PersonPropertyUpdateEvent(personId, personPropertyId, + false, true); Optional optional = labelerSensitivity.getPersonId(personPropertyUpdateEvent); assertTrue(optional.isPresent()); assertEquals(personId, optional.get()); @@ -83,8 +85,6 @@ public void testGetLabelerSensitivities() { } - - @Test @UnitTestMethod(name = "getLabel", args = { SimulationContext.class, PersonId.class }) public void testGetLabel() { @@ -96,7 +96,8 @@ public void testGetLabel() { PersonPropertiesActionSupport.testConsumer(10, 6445109933336671672L, (c) -> { // establish data views PeopleDataManager peopleDataManager = c.getDataManager(PeopleDataManager.class); - PersonPropertiesDataManager personPropertiesDataManager = c.getDataManager(PersonPropertiesDataManager.class); + PersonPropertiesDataManager personPropertiesDataManager = c + .getDataManager(PersonPropertiesDataManager.class); StochasticsDataManager stochasticsDataManager = c.getDataManager(StochasticsDataManager.class); RandomGenerator randomGenerator = stochasticsDataManager.getRandomGenerator(); @@ -109,7 +110,8 @@ public void testGetLabel() { */ List people = peopleDataManager.getPeople(); for (PersonId personId : people) { - personPropertiesDataManager.setPersonPropertyValue(personId, personPropertyId, randomGenerator.nextBoolean()); + personPropertiesDataManager.setPersonPropertyValue(personId, personPropertyId, + randomGenerator.nextBoolean()); } /* @@ -140,14 +142,15 @@ public void testGetLabel() { Object actualLabel = personPropertyLabeler.getLabel(c, personId); // show that the two labels are equal - assertEquals(expectedLabel, actualLabel); + assertEquals(expectedLabel, actualLabel); } // precondition tests // if the person does not exist - ContractException contractException = assertThrows(ContractException.class, () -> personPropertyLabeler.getLabel(c, new PersonId(100000))); + ContractException contractException = assertThrows(ContractException.class, + () -> personPropertyLabeler.getLabel(c, new PersonId(100000))); assertEquals(PersonError.UNKNOWN_PERSON_ID, contractException.getErrorType()); // if the person id is null @@ -160,8 +163,70 @@ public void testGetLabel() { @UnitTestMethod(name = "getDimension", args = {}) public void testGetDimension() { for (TestPersonPropertyId testPersonPropertyId : TestPersonPropertyId.values()) { - assertEquals(testPersonPropertyId, new PersonPropertyLabeler(testPersonPropertyId, (c) -> null).getDimension()); + assertEquals(testPersonPropertyId, + new PersonPropertyLabeler(testPersonPropertyId, (c) -> null).getDimension()); } } + @Test + @UnitTestMethod(name = "getPastLabel", args = { SimulationContext.class, Event.class }) + public void testGetPastLabel() { + PersonPropertiesActionSupport.testConsumer(10, 770141763380713425L, (c) -> { + // establish data views + PeopleDataManager peopleDataManager = c.getDataManager(PeopleDataManager.class); + PersonPropertiesDataManager personPropertiesDataManager = c + .getDataManager(PersonPropertiesDataManager.class); + StochasticsDataManager stochasticsDataManager = c.getDataManager(StochasticsDataManager.class); + RandomGenerator randomGenerator = stochasticsDataManager.getRandomGenerator(); + + // select a property to work with + PersonPropertyId personPropertyId = TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK; + + /* + * Assign random values to the people so that we can get some + * variety in the labels + */ + List people = peopleDataManager.getPeople(); + for (PersonId personId : people) { + personPropertiesDataManager.setPersonPropertyValue(personId, personPropertyId, + randomGenerator.nextInt(100)); + } + + /* + * build a person property labeler with a function that can be + * tested + */ + Function function = (g) -> { + Integer integer = (Integer) g; + return integer; + }; + + PersonPropertyLabeler personPropertyLabeler = new PersonPropertyLabeler(personPropertyId, function); + + /* + * Apply the labeler to each person and compare it to the more + * direct use of the labeler's function + */ + for (PersonId personId : people) { + int newValue = randomGenerator.nextInt(1000); + int oldValue = personPropertiesDataManager.getPersonPropertyValue(personId, personPropertyId); + + if (newValue == oldValue) { + newValue += 1; + } + + personPropertiesDataManager.setPersonPropertyValue(personId, personPropertyId, newValue); + Object expectedLabel = function.apply(oldValue); + + // get the label + Object actualLabel = personPropertyLabeler.getPastLabel(c, + new PersonPropertyUpdateEvent(personId, personPropertyId, oldValue, newValue)); + + // show that the two labels are equal + assertEquals(expectedLabel, actualLabel); + + } + }); + } + } diff --git a/gcm4/src/test/java/plugins/personproperties/support/AT_PropertyFilter.java b/gcm4/src/test/java/plugins/personproperties/support/AT_PropertyFilter.java index 3b964f2b5..b3de041ec 100644 --- a/gcm4/src/test/java/plugins/personproperties/support/AT_PropertyFilter.java +++ b/gcm4/src/test/java/plugins/personproperties/support/AT_PropertyFilter.java @@ -130,4 +130,14 @@ public void testEvaluate() { assertEquals(PersonError.UNKNOWN_PERSON_ID,contractException.getErrorType()); }); } + + @Test + @UnitTestMethod(name="toString", args={}) + public void testToString() { + Filter filter = new PropertyFilter(TestPersonPropertyId.PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK, Equality.GREATER_THAN, 12); + String expectedString = "PropertyFilter [personPropertyId=PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK, personPropertyValue=12, equality=GREATER_THAN]"; + + assertEquals(expectedString, filter.toString()); + + } } diff --git a/gcm4/src/test/java/plugins/personproperties/testsupport/AT_PersonPropertiesActionSupport.java b/gcm4/src/test/java/plugins/personproperties/testsupport/AT_PersonPropertiesActionSupport.java new file mode 100644 index 000000000..25c0276d9 --- /dev/null +++ b/gcm4/src/test/java/plugins/personproperties/testsupport/AT_PersonPropertiesActionSupport.java @@ -0,0 +1,27 @@ +package plugins.personproperties.testsupport; + +import java.util.function.Consumer; + +import org.junit.jupiter.api.Test; + +import nucleus.Plugin; +import tools.annotations.UnitTag; +import tools.annotations.UnitTest; +import tools.annotations.UnitTestMethod; + +@UnitTest(target = PersonPropertiesActionSupport.class) +public class AT_PersonPropertiesActionSupport { + @Test + @UnitTestMethod(name = "testConsumer", args = { int.class, long.class, Consumer.class }, tags = { + UnitTag.INCOMPLETE }) + public void testTestConsumer() { + // TBD + } + + @Test + @UnitTestMethod(name = "testConsumers", args = { int.class, long.class, Plugin.class }, tags = { + UnitTag.INCOMPLETE }) + public void testTestConsumers() { + // TBD + } +} diff --git a/gcm4/src/test/java/plugins/personproperties/testsupport/AT_TestAuxiliaryPersonPropertyId.java b/gcm4/src/test/java/plugins/personproperties/testsupport/AT_TestAuxiliaryPersonPropertyId.java new file mode 100644 index 000000000..43f971447 --- /dev/null +++ b/gcm4/src/test/java/plugins/personproperties/testsupport/AT_TestAuxiliaryPersonPropertyId.java @@ -0,0 +1,102 @@ +package plugins.personproperties.testsupport; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.EnumSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.math3.random.RandomGenerator; +import org.junit.jupiter.api.Test; + +import plugins.personproperties.support.PersonPropertyId; +import plugins.util.properties.PropertyDefinition; +import tools.annotations.UnitTest; +import tools.annotations.UnitTestMethod; +import util.random.RandomGeneratorProvider; +import util.wrappers.MutableInteger; + +@UnitTest(target = TestAuxiliaryPersonPropertyId.class) +public class AT_TestAuxiliaryPersonPropertyId { + @Test + @UnitTestMethod(name = "getRandomPersonPropertyId", args = { RandomGenerator.class }) + public void testGetRandomPersonPropertyId() { + Map countMap = new LinkedHashMap<>(); + for (TestAuxiliaryPersonPropertyId testPersonPropertyId : TestAuxiliaryPersonPropertyId.values()) { + countMap.put(testPersonPropertyId, new MutableInteger()); + } + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2864629454580072362L); + int sampleCount = 1000; + for (int i = 0; i < sampleCount; i++) { + TestAuxiliaryPersonPropertyId randomPersonPropertyId = TestAuxiliaryPersonPropertyId.getRandomPersonPropertyId(randomGenerator); + assertNotNull(randomPersonPropertyId); + countMap.get(randomPersonPropertyId).increment(); + } + + int minCount = sampleCount / TestAuxiliaryPersonPropertyId.values().length; + minCount *= 4; + minCount /= 5; + for (TestAuxiliaryPersonPropertyId testPersonPropertyId : TestAuxiliaryPersonPropertyId.values()) { + assertTrue(countMap.get(testPersonPropertyId).getValue() > minCount); + } + } + + @Test + @UnitTestMethod(name = "getRandomPropertyValue", args = { RandomGenerator.class }) + public void testGetRandomPropertyValue() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(890505028463718572L); + + /* + * Show that randomly generated values are compatible with the + * associated property definition. Show that the values are reasonably + * unique + */ + for (TestAuxiliaryPersonPropertyId testPersonPropertyId : TestAuxiliaryPersonPropertyId.values()) { + PropertyDefinition propertyDefinition = testPersonPropertyId.getPropertyDefinition(); + Set values = new LinkedHashSet<>(); + for (int i = 0; i < 100; i++) { + Object propertyValue = testPersonPropertyId.getRandomPropertyValue(randomGenerator); + values.add(propertyValue); + assertTrue(propertyDefinition.getType().isAssignableFrom(propertyValue.getClass())); + } + //show that the values are reasonable unique + if (propertyDefinition.getType() != Boolean.class) { + assertTrue(values.size() > 10); + } else { + assertEquals(2, values.size()); + } + } + } + + @Test + @UnitTestMethod(name = "getPropertyDefinition", args = {}) + public void testGetPropertyDefinition() { + for (TestAuxiliaryPersonPropertyId testPersonPropertyId : TestAuxiliaryPersonPropertyId.values()) { + PropertyDefinition propertyDefinition = testPersonPropertyId.getPropertyDefinition(); + assertNotNull(propertyDefinition); + } + } + + @Test + @UnitTestMethod(name = "getUnknownPersonPropertyId", args = {}) + public void testGetUnknownPersonPropertyId() { + /* + * Shows that a generated unknown person property id is unique, not null + * and not a member of the enum + */ + Set testProperties = EnumSet.allOf(TestAuxiliaryPersonPropertyId.class); + Set unknownPersonPropertyIds = new LinkedHashSet<>(); + for (int i = 0; i < 30; i++) { + PersonPropertyId unknownPersonPropertyId = TestAuxiliaryPersonPropertyId.getUnknownPersonPropertyId(); + assertNotNull(unknownPersonPropertyId); + boolean unique = unknownPersonPropertyIds.add(unknownPersonPropertyId); + assertTrue(unique); + assertFalse(testProperties.contains(unknownPersonPropertyId)); + } + } +} diff --git a/gcm4/src/test/java/plugins/personproperties/testsupport/AT_TestPersonPropertyId.java b/gcm4/src/test/java/plugins/personproperties/testsupport/AT_TestPersonPropertyId.java index a4c76dbc1..9cb60e63c 100644 --- a/gcm4/src/test/java/plugins/personproperties/testsupport/AT_TestPersonPropertyId.java +++ b/gcm4/src/test/java/plugins/personproperties/testsupport/AT_TestPersonPropertyId.java @@ -5,9 +5,11 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.ArrayList; import java.util.EnumSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -34,7 +36,8 @@ public void testGetRandomPersonPropertyId() { RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(5471359242434395756L); int sampleCount = 1000; for (int i = 0; i < sampleCount; i++) { - TestPersonPropertyId randomPersonPropertyId = TestPersonPropertyId.getRandomPersonPropertyId(randomGenerator); + TestPersonPropertyId randomPersonPropertyId = TestPersonPropertyId + .getRandomPersonPropertyId(randomGenerator); assertNotNull(randomPersonPropertyId); countMap.get(randomPersonPropertyId).increment(); } @@ -63,9 +66,9 @@ public void testGetRandomPropertyValue() { for (int i = 0; i < 100; i++) { Object propertyValue = testPersonPropertyId.getRandomPropertyValue(randomGenerator); values.add(propertyValue); - assertTrue(propertyDefinition.getType().isAssignableFrom(propertyValue.getClass())); + assertTrue(propertyDefinition.getType().isAssignableFrom(propertyValue.getClass())); } - //show that the values are reasonable unique + // show that the values are reasonable unique if (propertyDefinition.getType() != Boolean.class) { assertTrue(values.size() > 10); } else { @@ -100,4 +103,48 @@ public void testGetUnknownPersonPropertyId() { assertFalse(testProperties.contains(unknownPersonPropertyId)); } } + + @Test + @UnitTestMethod(name = "getPropertiesWithDefaultValues", args = {}) + public void testGetPropertiesWithDefaultValues() { + List expectedValues = new ArrayList<>(); + + for (TestPersonPropertyId id : TestPersonPropertyId.values()) { + if (id.getPropertyDefinition().getDefaultValue().isPresent()) { + expectedValues.add(id); + } + } + + List actualValues = TestPersonPropertyId.getPropertiesWithDefaultValues(); + + assertNotNull(actualValues); + assertEquals(expectedValues.size(), actualValues.size()); + Set setOfExpectedValues = new LinkedHashSet<>(expectedValues); + Set setOfActualValues = new LinkedHashSet<>(actualValues); + assertEquals(setOfExpectedValues, setOfActualValues); + assertEquals(expectedValues.size(), setOfExpectedValues.size()); + assertEquals(actualValues.size(), setOfActualValues.size()); + } + + @Test + @UnitTestMethod(name = "getPropertiesWithoutDefaultValues", args = {}) + public void testGetPropertiesWithoutDefaultValues() { + List expectedValues = new ArrayList<>(); + + for (TestPersonPropertyId id : TestPersonPropertyId.values()) { + if (id.getPropertyDefinition().getDefaultValue().isEmpty()) { + expectedValues.add(id); + } + } + + List actualValues = TestPersonPropertyId.getPropertiesWithoutDefaultValues(); + + assertNotNull(actualValues); + assertEquals(expectedValues.size(), actualValues.size()); + Set setOfExpectedValues = new LinkedHashSet<>(expectedValues); + Set setOfActualValues = new LinkedHashSet<>(actualValues); + assertEquals(setOfExpectedValues, setOfActualValues); + assertEquals(expectedValues.size(), setOfExpectedValues.size()); + assertEquals(actualValues.size(), setOfActualValues.size()); + } } \ No newline at end of file diff --git a/gcm4/src/test/java/plugins/regions/AT_RegionsPluginData.java b/gcm4/src/test/java/plugins/regions/AT_RegionsPluginData.java index 865e34edc..2f2046b99 100644 --- a/gcm4/src/test/java/plugins/regions/AT_RegionsPluginData.java +++ b/gcm4/src/test/java/plugins/regions/AT_RegionsPluginData.java @@ -189,7 +189,7 @@ public void testGetRegionPropertyValues() { * set about half of the properties for each region for those properties * that have a default value */ - for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertesWithDefaultValues()) { + for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertiesWithDefaultValues()) { for (TestRegionId testRegionId : TestRegionId.values()) { if (randomGenerator.nextBoolean()) { Object value = testRegionPropertyId.getRandomPropertyValue(randomGenerator); @@ -203,7 +203,7 @@ public void testGetRegionPropertyValues() { * set all of the properties for each region for those properties that * do not have a default value */ - for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertesWithoutDefaultValues()) { + for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertiesWithoutDefaultValues()) { for (TestRegionId testRegionId : TestRegionId.values()) { Object value = testRegionPropertyId.getRandomPropertyValue(randomGenerator); builder.setRegionPropertyValue(testRegionId, testRegionPropertyId, value); diff --git a/gcm4/src/test/java/plugins/regions/datamanagers/AT_RegionsDataManager.java b/gcm4/src/test/java/plugins/regions/datamanagers/AT_RegionsDataManager.java index b62b88977..d9c3a6f65 100644 --- a/gcm4/src/test/java/plugins/regions/datamanagers/AT_RegionsDataManager.java +++ b/gcm4/src/test/java/plugins/regions/datamanagers/AT_RegionsDataManager.java @@ -1255,7 +1255,7 @@ public void testPluginDataLoaded() { regionPluginBuilder.defineRegionProperty(testRegionPropertyId, testRegionPropertyId.getPropertyDefinition()); } - for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertesWithoutDefaultValues()) { + for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertiesWithoutDefaultValues()) { for (TestRegionId testRegionId : TestRegionId.values()) { Object randomPropertyValue = testRegionPropertyId.getRandomPropertyValue(randomGenerator); regionPluginBuilder.setRegionPropertyValue(testRegionId, testRegionPropertyId, randomPropertyValue); @@ -1588,7 +1588,7 @@ public void testAddRegion() { RegionsDataManager regionsDataManager = c.getDataManager(RegionsDataManager.class); RegionId newRegionId = TestRegionId.getUnknownRegionId(); RegionConstructionData.Builder builder = RegionConstructionData.builder().setRegionId(newRegionId);// - for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertesWithoutDefaultValues()) { + for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertiesWithoutDefaultValues()) { builder.setRegionPropertyValue(testRegionPropertyId, testRegionPropertyId.getRandomPropertyValue(randomGenerator)); } RegionConstructionData regionConstructionData = builder.build(); @@ -1604,7 +1604,7 @@ public void testAddRegion() { RegionId newRegionId = TestRegionId.getUnknownRegionId(); RegionConstructionData.Builder builder = RegionConstructionData.builder().setRegionId(newRegionId);// - for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertesWithoutDefaultValues()) { + for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertiesWithoutDefaultValues()) { builder.setRegionPropertyValue(testRegionPropertyId, testRegionPropertyId.getRandomPropertyValue(randomGenerator)); } RegionConstructionData regionConstructionData = builder.build(); @@ -2335,7 +2335,7 @@ public void testGetEventFilterForRegionAdditionEvent() { RegionsDataManager regionsDataManager = c.getDataManager(RegionsDataManager.class); RegionId newRegionId = TestRegionId.getUnknownRegionId(); RegionConstructionData.Builder builder = RegionConstructionData.builder().setRegionId(newRegionId);// - for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertesWithoutDefaultValues()) { + for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.getPropertiesWithoutDefaultValues()) { builder.setRegionPropertyValue(testRegionPropertyId, testRegionPropertyId.getRandomPropertyValue(randomGenerator)); } RegionConstructionData regionConstructionData = builder.build(); diff --git a/gcm4/src/test/java/plugins/regions/testsupport/AT_TestRegionPropertyId.java b/gcm4/src/test/java/plugins/regions/testsupport/AT_TestRegionPropertyId.java index aad340b8c..83fec02f3 100644 --- a/gcm4/src/test/java/plugins/regions/testsupport/AT_TestRegionPropertyId.java +++ b/gcm4/src/test/java/plugins/regions/testsupport/AT_TestRegionPropertyId.java @@ -5,7 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.Arrays; +import java.util.ArrayList; import java.util.EnumSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -95,16 +95,17 @@ public void testGetRandomPropertyValue() { } @Test - @UnitTestMethod(name = "getPropertesWithDefaultValues", args = {}) + @UnitTestMethod(name = "getPropertiesWithDefaultValues", args = {}) public void testGetPropertesWithDefaultValues() { - List expectedValues = Arrays.asList( - TestRegionPropertyId.REGION_PROPERTY_1_BOOLEAN_MUTABLE, - TestRegionPropertyId.REGION_PROPERTY_3_DOUBLE_MUTABLE, - TestRegionPropertyId.REGION_PROPERTY_4_BOOLEAN_IMMUTABLE, - TestRegionPropertyId.REGION_PROPERTY_5_INTEGER_IMMUTABLE, - TestRegionPropertyId.REGION_PROPERTY_6_DOUBLE_IMMUTABLE); + List expectedValues = new ArrayList<>(); + + for (TestRegionPropertyId id : TestRegionPropertyId.values()) { + if (id.getPropertyDefinition().getDefaultValue().isPresent()) { + expectedValues.add(id); + } + } - List actualValues = TestRegionPropertyId.getPropertesWithDefaultValues(); + List actualValues = TestRegionPropertyId.getPropertiesWithDefaultValues(); assertNotNull(actualValues); assertEquals(expectedValues.size(), actualValues.size()); @@ -116,11 +117,17 @@ public void testGetPropertesWithDefaultValues() { } @Test - @UnitTestMethod(name = "getPropertesWithoutDefaultValues", args = {}) + @UnitTestMethod(name = "getPropertiesWithoutDefaultValues", args = {}) public void testGetPropertesWithoutDefaultValues() { - List expectedValues = Arrays - .asList(TestRegionPropertyId.REGION_PROPERTY_2_INTEGER_MUTABLE); - List actualValues = TestRegionPropertyId.getPropertesWithoutDefaultValues(); + List expectedValues = new ArrayList<>(); + + for (TestRegionPropertyId id : TestRegionPropertyId.values()) { + if (id.getPropertyDefinition().getDefaultValue().isEmpty()) { + expectedValues.add(id); + } + } + + List actualValues = TestRegionPropertyId.getPropertiesWithoutDefaultValues(); assertNotNull(actualValues); assertEquals(expectedValues.size(), actualValues.size()); @@ -156,7 +163,7 @@ public void testGetRandomRegionPropertyId() { Set applicableValues = EnumSet.allOf(TestRegionPropertyId.class); Map valueCounter = new LinkedHashMap<>(); - for(TestRegionPropertyId actualValue : TestRegionPropertyId.values()) { + for (TestRegionPropertyId actualValue : TestRegionPropertyId.values()) { valueCounter.put(actualValue, new MutableInteger()); }