TSK-1012: Add dynamic list of pojos for pojotesting
(cherry picked from commit a97fdfa4bdb7a99ab65638ee5e282a659c09e77d)
This commit is contained in:
parent
c500599e1c
commit
ad15fedcab
|
@ -11,7 +11,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.LongStream;
|
import java.util.stream.LongStream;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
@ -290,25 +289,6 @@ public final class DaysToWorkingDaysConverter {
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (o == null || getClass() != o.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
DaysToWorkingDaysConverter that = (DaysToWorkingDaysConverter) o;
|
|
||||||
return positiveDaysToWorkingDays.equals(that.positiveDaysToWorkingDays)
|
|
||||||
&& negativeDaysToWorkingDays.equals(that.negativeDaysToWorkingDays)
|
|
||||||
&& dateCreated.equals(that.dateCreated);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(positiveDaysToWorkingDays, negativeDaysToWorkingDays, dateCreated);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumeration of German holidays.
|
* Enumeration of German holidays.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,7 +4,9 @@ import java.util.Collection;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.DynamicTest;
|
import org.junit.jupiter.api.DynamicTest;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestFactory;
|
import org.junit.jupiter.api.TestFactory;
|
||||||
|
|
||||||
import com.openpojo.reflection.impl.PojoClassFactory;
|
import com.openpojo.reflection.impl.PojoClassFactory;
|
||||||
|
@ -17,24 +19,22 @@ import com.openpojo.validation.rule.impl.SetterMustExistRule;
|
||||||
import com.openpojo.validation.test.Tester;
|
import com.openpojo.validation.test.Tester;
|
||||||
import com.openpojo.validation.test.impl.GetterTester;
|
import com.openpojo.validation.test.impl.GetterTester;
|
||||||
import com.openpojo.validation.test.impl.SetterTester;
|
import com.openpojo.validation.test.impl.SetterTester;
|
||||||
|
import com.tngtech.archunit.core.domain.JavaClass;
|
||||||
|
import com.tngtech.archunit.core.importer.ClassFileImporter;
|
||||||
|
|
||||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||||
import nl.jqno.equalsverifier.Warning;
|
import nl.jqno.equalsverifier.Warning;
|
||||||
import pro.taskana.impl.AttachmentImpl;
|
|
||||||
import pro.taskana.impl.AttachmentSummaryImpl;
|
|
||||||
import pro.taskana.impl.ClassificationImpl;
|
|
||||||
import pro.taskana.impl.ClassificationSummaryImpl;
|
|
||||||
import pro.taskana.impl.TaskImpl;
|
|
||||||
import pro.taskana.impl.TaskSummaryImpl;
|
|
||||||
import pro.taskana.impl.WorkbasketAccessItemImpl;
|
|
||||||
import pro.taskana.impl.WorkbasketImpl;
|
|
||||||
import pro.taskana.impl.WorkbasketSummaryImpl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check classes with a custom equals and hashcode implementation for correctness.
|
* check classes with a custom equals and hashcode implementation for correctness.
|
||||||
*/
|
*/
|
||||||
class PojoTest {
|
class PojoTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testsThatPojoClassesAreFound() {
|
||||||
|
Assertions.assertTrue(getPojoClasses().count() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
@TestFactory
|
@TestFactory
|
||||||
Collection<DynamicTest> equalsContract() {
|
Collection<DynamicTest> equalsContract() {
|
||||||
return
|
return
|
||||||
|
@ -46,47 +46,52 @@ class PojoTest {
|
||||||
|
|
||||||
@TestFactory
|
@TestFactory
|
||||||
Collection<DynamicTest> validateGetters() {
|
Collection<DynamicTest> validateGetters() {
|
||||||
return getPojoClasses()
|
return
|
||||||
.map(cl -> DynamicTest.dynamicTest("Check Getter exist for " + cl.getSimpleName(),
|
getPojoClasses()
|
||||||
() -> validateWithRules(cl, new GetterMustExistRule())
|
.map(cl -> DynamicTest.dynamicTest("Check Getter exist for " + cl.getSimpleName(),
|
||||||
))
|
() -> validateWithRules(cl, new GetterMustExistRule())
|
||||||
.collect(Collectors.toList());
|
))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestFactory
|
@TestFactory
|
||||||
Collection<DynamicTest> validateSetters() {
|
Collection<DynamicTest> validateSetters() {
|
||||||
return getPojoClasses()
|
return
|
||||||
.map(cl -> DynamicTest.dynamicTest("Check Setter for " + cl.getSimpleName(),
|
getPojoClasses()
|
||||||
() -> validateWithRules(cl, new SetterMustExistRule())
|
.map(cl -> DynamicTest.dynamicTest("Check Setter for " + cl.getSimpleName(),
|
||||||
))
|
() -> validateWithRules(cl, new SetterMustExistRule())
|
||||||
.collect(Collectors.toList());
|
))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestFactory
|
@TestFactory
|
||||||
Collection<DynamicTest> validateGetAndSet() {
|
Collection<DynamicTest> validateGetAndSet() {
|
||||||
return getPojoClasses()
|
return
|
||||||
.map(cl -> DynamicTest.dynamicTest("Test set & get " + cl.getSimpleName(),
|
getPojoClasses()
|
||||||
() -> validateWithTester(cl, new GetterTester(), new SetterTester())
|
.map(cl -> DynamicTest.dynamicTest("Test set & get " + cl.getSimpleName(),
|
||||||
))
|
() -> validateWithTester(cl, new GetterTester(), new SetterTester())
|
||||||
.collect(Collectors.toList());
|
))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestFactory
|
@TestFactory
|
||||||
Collection<DynamicTest> validateNoStaticExceptFinalFields() {
|
Collection<DynamicTest> validateNoStaticExceptFinalFields() {
|
||||||
return getPojoClasses()
|
return
|
||||||
.map(cl -> DynamicTest.dynamicTest("Check static fields for " + cl.getSimpleName(),
|
getPojoClasses()
|
||||||
() -> validateWithRules(cl, new NoStaticExceptFinalRule())
|
.map(cl -> DynamicTest.dynamicTest("Check static fields for " + cl.getSimpleName(),
|
||||||
))
|
() -> validateWithRules(cl, new NoStaticExceptFinalRule())
|
||||||
.collect(Collectors.toList());
|
))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestFactory
|
@TestFactory
|
||||||
Collection<DynamicTest> validateNoPublicFields() {
|
Collection<DynamicTest> validateNoPublicFields() {
|
||||||
return getPojoClasses()
|
return
|
||||||
.map(cl -> DynamicTest.dynamicTest("Check public fields for " + cl.getSimpleName(),
|
getPojoClasses()
|
||||||
() -> validateWithRules(cl, new NoPublicFieldsRule())
|
.map(cl -> DynamicTest.dynamicTest("Check public fields for " + cl.getSimpleName(),
|
||||||
))
|
() -> validateWithRules(cl, new NoPublicFieldsRule())
|
||||||
.collect(Collectors.toList());
|
))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateWithRules(Class<?> cl, Rule... rules) {
|
private void validateWithRules(Class<?> cl, Rule... rules) {
|
||||||
|
@ -110,21 +115,12 @@ class PojoTest {
|
||||||
.verify();
|
.verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO find a way to dynamically create a list with custom implemented equals or hash methods.
|
|
||||||
private Stream<Class<?>> getPojoClasses() {
|
private Stream<Class<?>> getPojoClasses() {
|
||||||
return Stream.of(
|
//TODO how to identify pojos? Is overwritten equals method enough?
|
||||||
KeyDomain.class,
|
return new ClassFileImporter().importPackages("pro.taskana")
|
||||||
ObjectReference.class,
|
.stream()
|
||||||
TimeInterval.class,
|
.filter(javaClass -> javaClass.tryGetMethod("equals", Object.class).isPresent())
|
||||||
AttachmentImpl.class,
|
.map(JavaClass::reflect);
|
||||||
AttachmentSummaryImpl.class,
|
|
||||||
ClassificationImpl.class,
|
|
||||||
ClassificationSummaryImpl.class,
|
|
||||||
TaskImpl.class,
|
|
||||||
TaskSummaryImpl.class,
|
|
||||||
WorkbasketAccessItemImpl.class,
|
|
||||||
WorkbasketImpl.class,
|
|
||||||
WorkbasketSummaryImpl.class
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,19 +30,6 @@ class DaysToWorkingDaysConverterTest {
|
||||||
DaysToWorkingDaysConverter.setCustomHolidays(Arrays.asList(dayOfReformation, allSaintsDays));
|
DaysToWorkingDaysConverter.setCustomHolidays(Arrays.asList(dayOfReformation, allSaintsDays));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testInitializeForDifferentReportLineItemDefinitions() throws InvalidArgumentException {
|
|
||||||
DaysToWorkingDaysConverter instance1 = DaysToWorkingDaysConverter
|
|
||||||
.initialize(getShortListOfColumnHeaders(), Instant.parse("2018-02-03T00:00:00.000Z"));
|
|
||||||
DaysToWorkingDaysConverter instance2 = DaysToWorkingDaysConverter
|
|
||||||
.initialize(getShortListOfColumnHeaders(), Instant.parse("2018-02-03T00:00:00.000Z"));
|
|
||||||
DaysToWorkingDaysConverter instance3 = DaysToWorkingDaysConverter
|
|
||||||
.initialize(getLargeListOfColumnHeaders(), Instant.parse("2018-02-03T00:00:00.000Z"));
|
|
||||||
|
|
||||||
assertEquals(instance1, instance2);
|
|
||||||
assertNotEquals(instance1, instance3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testConvertWorkingDaysToDaysForTasks() throws InvalidArgumentException {
|
void testConvertWorkingDaysToDaysForTasks() throws InvalidArgumentException {
|
||||||
List<TimeIntervalColumnHeader> reportItems = singletonList(new TimeIntervalColumnHeader(0));
|
List<TimeIntervalColumnHeader> reportItems = singletonList(new TimeIntervalColumnHeader(0));
|
||||||
|
|
Loading…
Reference in New Issue