From 260ec1c934d472aa830485ca51febb564ef5629c Mon Sep 17 00:00:00 2001 From: Shawn Date: Thu, 30 Mar 2023 16:09:34 -0400 Subject: [PATCH] Refactored unit testing for PersonPropertiesPluginData --- .../PersonPropertiesPluginData.java | 2 +- .../AT_PersonPropertyPluginData.java | 43 ++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/gcm4/src/main/java/plugins/personproperties/PersonPropertiesPluginData.java b/gcm4/src/main/java/plugins/personproperties/PersonPropertiesPluginData.java index c1d199b14..ed87406b6 100644 --- a/gcm4/src/main/java/plugins/personproperties/PersonPropertiesPluginData.java +++ b/gcm4/src/main/java/plugins/personproperties/PersonPropertiesPluginData.java @@ -174,7 +174,7 @@ public Builder addPerson(PersonId personId) { * id is null *
  • {@linkplain PropertyError#NULL_PROPERTY_ID} if the * person property id is null
  • - *
  • {@linkplain PropertyError#NULL_PROPERTY_VALUE} if the + *
  • {@linkplain PersonPropertyError#NULL_PROPERTY_VALUE} if the * person property value is null
  • */ public Builder setPersonPropertyValue(final PersonId personId, final PersonPropertyId personPropertyId, final Object personPropertyValue) { diff --git a/gcm4/src/test/java/plugins/personproperties/AT_PersonPropertyPluginData.java b/gcm4/src/test/java/plugins/personproperties/AT_PersonPropertyPluginData.java index b1020246c..1ffbb1a21 100644 --- a/gcm4/src/test/java/plugins/personproperties/AT_PersonPropertyPluginData.java +++ b/gcm4/src/test/java/plugins/personproperties/AT_PersonPropertyPluginData.java @@ -18,6 +18,7 @@ import nucleus.PluginDataBuilder; import plugins.people.support.PersonError; import plugins.people.support.PersonId; +import plugins.personproperties.support.PersonPropertyError; import plugins.personproperties.support.PersonPropertyId; import plugins.personproperties.support.PersonPropertyInitialization; import plugins.personproperties.testsupport.TestPersonPropertyId; @@ -47,8 +48,7 @@ public void testBuild() { */ ContractException contractException = assertThrows(ContractException.class, // () -> PersonPropertiesPluginData.builder()// - .addPerson(new PersonId(0)) - .setPersonPropertyValue(new PersonId(0), TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK, true)// + .addPerson(new PersonId(0)).setPersonPropertyValue(new PersonId(0), TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK, true)// .build());// assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); @@ -62,8 +62,7 @@ public void testBuild() { PropertyDefinition propertyDefinition = testPersonPropertyId.getPropertyDefinition(); PersonPropertiesPluginData .builder()// .definePersonProperty(testPersonPropertyId, propertyDefinition)// - .addPerson(new PersonId(0)) - .setPersonPropertyValue(new PersonId(0), TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK, 45)// + .addPerson(new PersonId(0)).setPersonPropertyValue(new PersonId(0), TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK, 45)// .build();// });// assertEquals(PropertyError.INCOMPATIBLE_VALUE, contractException.getErrorType()); @@ -91,6 +90,38 @@ public void testBuild() { });// assertEquals(PropertyError.INSUFFICIENT_PROPERTY_VALUE_ASSIGNMENT, contractException.getErrorType()); + contractException = assertThrows(ContractException.class, // + () -> {// + + TestPersonPropertyId prop1 = TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK; + PropertyDefinition def1 = prop1.getPropertyDefinition(); + + // this property has no associated default value + TestPersonPropertyId prop2 = TestPersonPropertyId.PERSON_PROPERTY_9_DOUBLE_IMMUTABLE_NO_TRACK; + PropertyDefinition def2 = prop2.getPropertyDefinition(); + + PersonPropertiesPluginData.Builder builder = + + PersonPropertiesPluginData.builder();// + builder .definePersonProperty(prop1, def1)// + .definePersonProperty(prop2, def2);// + + for (int i = 0; i < 10; i++) { + if (i % 2 == 0) { + builder.addPerson(new PersonId(i));// + } + builder.setPersonPropertyValue(new PersonId(i), prop1, false);// + builder.setPersonPropertyValue(new PersonId(i), prop2, 2.556);// + } + builder.build(); + + });// + assertEquals(PersonPropertyError.PROPERTY_ASSIGNMENT_FOR_NON_ADDED_PERSON, contractException.getErrorType()); + + // *
  • {@linkplain + // PropertyError#PROPERTY_ASSIGNMENT_FOR_NON_ADDED_PERSON} + // * if a person who is not explicitly added via addPerson() + // * is assigned property values
  • } @Test @@ -391,12 +422,12 @@ public void testGetMaxPersonIndex() { int personCount = 50; int expectedMaxPersonIndex = -1; for (int i = 0; i < personCount; i++) { - + if (randomGenerator.nextBoolean()) { PersonId personId = new PersonId(i); personPropertyBuilder.addPerson(personId); expectedMaxPersonIndex = FastMath.max(expectedMaxPersonIndex, i); - int propertyCount = randomGenerator.nextInt(5); + int propertyCount = randomGenerator.nextInt(5); for (int j = 0; j < propertyCount; j++) { TestPersonPropertyId testPersonPropertyId = propertiesWithDefaultValues.get(randomGenerator.nextInt(propertiesWithDefaultValues.size())); Object value = testPersonPropertyId.getRandomPropertyValue(randomGenerator);