Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Person properties plugin unit tests #6

Merged
merged 15 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public class PersonPropertiesActionSupport {

private PersonPropertiesActionSupport(){}

public static void testConsumer(int initialPopulation, long seed, Consumer<ActorContext> consumer) {
TestPluginData.Builder pluginBuilder = TestPluginData.builder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public <T> T getRandomPropertyValue(final RandomGenerator randomGenerator) {
* Returns the test region property id values associated with property
* definitions that have default values.
*/
public static List<TestRegionPropertyId> getPropertesWithDefaultValues() {
public static List<TestRegionPropertyId> getPropertiesWithDefaultValues() {
List<TestRegionPropertyId> result = new ArrayList<>();
for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.values()) {
if (testRegionPropertyId.propertyDefinition.getDefaultValue().isPresent()) {
Expand All @@ -155,7 +155,7 @@ public static List<TestRegionPropertyId> getPropertesWithDefaultValues() {
* Returns the test region property id values associated with property
* definitions that do not have default values.
*/
public static List<TestRegionPropertyId> getPropertesWithoutDefaultValues() {
public static List<TestRegionPropertyId> getPropertiesWithoutDefaultValues() {
List<TestRegionPropertyId> result = new ArrayList<>();
for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.values()) {
if (testRegionPropertyId.propertyDefinition.getDefaultValue().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Loading