├── .gitignore ├── .idea └── codeStyleSettings.xml ├── Jenkinsfile ├── LICENSE.MD ├── README.MD ├── build.gradle ├── codecov.yml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── book ├── .gitignore ├── CNAME ├── LICENSE.md ├── README.md ├── SUMMARY.md ├── book.json ├── comparison │ ├── README.md │ ├── coverage-comparison.png │ └── pojo-the-winner.png ├── contributors │ └── README.md ├── release-notes │ └── README.md ├── why-use │ ├── README.md │ ├── coverage-with-pojo-tester.png │ └── coverage-without-pojo.png └── writing-tests │ ├── README.md │ └── log4jproperties.png ├── integrationTest ├── java │ └── pl │ │ └── pojo │ │ └── tester │ │ ├── issue153 │ │ ├── Message.java │ │ ├── NullOrEmptyCollectionsTest.java │ │ ├── Person.java │ │ └── PersonType.java │ │ ├── issue157 │ │ ├── AbstractClass.java │ │ └── AbstractClassWithoutDefaultConstructorTest.java │ │ ├── issue187 │ │ ├── EntityClass.java │ │ └── EntityClassPojoTest.java │ │ ├── issue192 │ │ ├── ConstructorWithZonedDateTime.java │ │ └── ConstructorWithZonedDateTimeTest.java │ │ ├── issue212 │ │ ├── BBB.java │ │ ├── DefensiveCopy.java │ │ └── DefensiveCopyTest.java │ │ ├── issue215 │ │ ├── AbstractProduct.java │ │ ├── ClassAsConstructorParameterTest.java │ │ ├── IProduct.java │ │ ├── Nourriture.java │ │ ├── ProductConfig.java │ │ └── Taxable.java │ │ └── usecase │ │ ├── logs │ │ ├── A.java │ │ ├── B.java │ │ ├── C.java │ │ └── LogsTest.java │ │ ├── statics │ │ ├── ClassWithStaticField.java │ │ └── StaticFieldTest.java │ │ └── types │ │ ├── AllTypesTest.java │ │ ├── Collections_Collection_Types.java │ │ ├── Collections_Iterators_Types.java │ │ ├── Collections_Map_Types.java │ │ ├── Collections_Other_Types.java │ │ ├── Collections_Types.java │ │ ├── Math_Types.java │ │ ├── Other_Types.java │ │ ├── Primitive_Types.java │ │ └── Primitive_Wrapped_Types.java └── resources │ └── log4j.properties ├── main ├── java │ └── pl │ │ └── pojo │ │ └── tester │ │ ├── api │ │ ├── ClassAndFieldPredicatePair.java │ │ ├── ConstructorParameters.java │ │ ├── DefaultPackageFilter.java │ │ ├── FieldPredicate.java │ │ ├── NamedPredicate.java │ │ ├── PackageFilter.java │ │ ├── PackageFilterException.java │ │ └── assertion │ │ │ ├── AbstractAssertion.java │ │ │ ├── Assertions.java │ │ │ ├── Method.java │ │ │ ├── MultiClassAssertion.java │ │ │ ├── SingleClassAssertion.java │ │ │ └── TesterInstantiationException.java │ │ └── internal │ │ ├── GetOrSetValueException.java │ │ ├── assertion │ │ ├── AbstractAssertionError.java │ │ ├── TestAssertions.java │ │ ├── constructor │ │ ├── equals │ │ │ ├── AbstractEqualsAssertionError.java │ │ │ ├── ConsistentEqualsAssertionError.java │ │ │ ├── EqualAssertions.java │ │ │ ├── EqualEqualsAssertionError.java │ │ │ ├── NotEqualEqualsAssertionError.java │ │ │ ├── NullEqualsAssertionError.java │ │ │ ├── OtherTypeEqualsAssertionError.java │ │ │ ├── ReflexiveEqualsAssertionError.java │ │ │ ├── SymmetricEqualsAssertionError.java │ │ │ └── TransitiveEqualsAssertionError.java │ │ ├── getter │ │ │ ├── GetterAssertionError.java │ │ │ └── GetterAssertions.java │ │ ├── hashcode │ │ │ ├── AbstractHashCodeAssertionError.java │ │ │ ├── ConsistentHashCodeAssertionError.java │ │ │ ├── EqualHashCodeAssertionError.java │ │ │ ├── HashCodeAssertions.java │ │ │ └── NotEqualHashCodeAssertionError.java │ │ ├── setter │ │ │ ├── SetterAssertionError.java │ │ │ └── SetterAssertions.java │ │ └── tostring │ │ │ ├── AbstractToStringAssertionError.java │ │ │ ├── ContainsToStringAssertionError.java │ │ │ ├── NotContainToStringAssertionError.java │ │ │ └── ToStringAssertions.java │ │ ├── field │ │ ├── AbstractFieldValueChanger.java │ │ ├── DefaultFieldValueChanger.java │ │ ├── EnumValueChanger.java │ │ ├── ImpossibleEnumValueChangeException.java │ │ ├── StringValueChanger.java │ │ ├── UUIDValueChanger.java │ │ ├── collections │ │ │ ├── ArrayValueChanger.java │ │ │ ├── CollectionsFieldValueChanger.java │ │ │ ├── StreamValueChanger.java │ │ │ ├── collection │ │ │ │ ├── AbstractCollectionFieldValueChanger.java │ │ │ │ ├── ArrayListValueChanger.java │ │ │ │ ├── DequeValueChanger.java │ │ │ │ ├── HashSetValueChanger.java │ │ │ │ ├── LinkedHashSetValueChanger.java │ │ │ │ ├── LinkedListValueChanger.java │ │ │ │ ├── ListValueChanger.java │ │ │ │ ├── QueueValueChanger.java │ │ │ │ ├── SetValueChanger.java │ │ │ │ ├── SortedSetValueChanger.java │ │ │ │ ├── StackValueChanger.java │ │ │ │ ├── TreeSetValueChanger.java │ │ │ │ └── VectorValueChanger.java │ │ │ ├── iterators │ │ │ │ ├── AbstractIteratorsFieldValueChanger.java │ │ │ │ ├── IterableValueChanger.java │ │ │ │ └── IteratorValueChanger.java │ │ │ └── map │ │ │ │ ├── AbstractMapFieldValueChanger.java │ │ │ │ ├── HashMapValueChanger.java │ │ │ │ ├── HashtableValueChanger.java │ │ │ │ ├── LinkedHashMapValueChanger.java │ │ │ │ ├── MapValueChanger.java │ │ │ │ ├── SortedMapValueChanger.java │ │ │ │ └── TreeMapValueChanger.java │ │ ├── date │ │ │ ├── DateFieldValueChanger.java │ │ │ ├── DefaultDateAndTimeFieldValueChanger.java │ │ │ ├── InstantFieldValueChanger.java │ │ │ ├── LocalDateFieldValueChanger.java │ │ │ ├── LocalDateTimeFieldValueChanger.java │ │ │ ├── LocalTimeFieldValueChanger.java │ │ │ ├── SqlDateFieldValueChanger.java │ │ │ └── ZonedDateTimeFieldValueChanger.java │ │ ├── math │ │ │ ├── BigDecimalValueChanger.java │ │ │ └── BigIntegerValueChanger.java │ │ └── primitive │ │ │ ├── AbstractPrimitiveValueChanger.java │ │ │ ├── BooleanValueChanger.java │ │ │ ├── ByteValueChanger.java │ │ │ ├── CharacterValueChanger.java │ │ │ ├── DoubleValueChanger.java │ │ │ ├── FloatValueChanger.java │ │ │ ├── IntegerValueChanger.java │ │ │ ├── LongValueChanger.java │ │ │ └── ShortValueChanger.java │ │ ├── instantiator │ │ ├── AbstractMultiConstructorInstantiator.java │ │ ├── AbstractObjectInstantiator.java │ │ ├── ArrayInstantiator.java │ │ ├── BestConstructorInstantiator.java │ │ ├── CollectionInstantiator.java │ │ ├── DefaultConstructorInstantiator.java │ │ ├── EnumInstantiator.java │ │ ├── Instantiable.java │ │ ├── JavaTypeInstantiator.java │ │ ├── ObjectGenerator.java │ │ ├── ObjectInstantiationException.java │ │ ├── ProxyInstantiator.java │ │ └── UserDefinedConstructorInstantiator.java │ │ ├── preconditions │ │ ├── BlankParameterException.java │ │ ├── NullParameterException.java │ │ └── ParameterPreconditions.java │ │ ├── tester │ │ ├── AbstractTester.java │ │ ├── ConstructorTester.java │ │ ├── EqualsTester.java │ │ ├── GetterTester.java │ │ ├── HashCodeTester.java │ │ ├── SetterTester.java │ │ └── ToStringTester.java │ │ └── utils │ │ ├── ClassLoader.java │ │ ├── ClassLoadingException.java │ │ ├── CollectionUtils.java │ │ ├── FieldUtils.java │ │ ├── GetterNotFoundException.java │ │ ├── MethodUtils.java │ │ ├── Permutator.java │ │ ├── ReflectionUtils.java │ │ ├── SetterNotFoundException.java │ │ ├── SublistFieldPermutator.java │ │ ├── Sublists.java │ │ └── ThoroughFieldPermutator.java └── resources │ └── log4j.properties └── test └── java ├── classesForTest ├── Abstract.java ├── Abstract_PrivateConstructor.java ├── Annotation.java ├── ClassContainingPrivateEnum.java ├── ClassContainingStaticClasses.java ├── ClassContainingUnpublicClasses.java ├── ClassWithSyntheticConstructor.java ├── Constructor_Field.java ├── Constructor_Stream.java ├── Constructor_Thread.java ├── Constructors_First_Throws_Exception.java ├── EmptyEnum.java ├── Interface.java ├── ObjectContainingArray.java ├── ObjectContainingIterable.java ├── ObjectContainingIterator.java ├── ObjectContainingList.java ├── ObjectContainingStream.java ├── PackageConstructor.java ├── Person.java ├── PrivateConstructor.java ├── ProtectedConstructor.java ├── UnpublicClass.java ├── fields │ ├── AllFiledTypes.java │ ├── AllFiledTypes_Wrapped.java │ ├── ClassContainingArrays.java │ ├── ClassContainingStream.java │ ├── ClassWithAllAvailableFieldModifiers.java │ ├── EnumFields.java │ ├── EnumWithoutConstants.java │ ├── Permutation1.java │ ├── Permutation2.java │ ├── SingleEnum.java │ ├── TestEnum1.java │ └── collections │ │ ├── collection │ │ └── Collections.java │ │ ├── iterators │ │ └── Iterators.java │ │ └── map │ │ └── Maps.java ├── packageFilter │ ├── A.java │ ├── B.java │ ├── C.java │ └── next │ │ ├── D.java │ │ ├── E.java │ │ └── notAClass ├── permutator │ └── A.java └── reflectionUtils │ ├── base │ ├── AExtendsBase.java │ ├── BExtendsBase.java │ ├── Base.java │ └── CNotExtendsBase.java │ └── next │ ├── D.java │ ├── E.java │ └── notAClass ├── helpers ├── ClassAndFieldPredicatePairArgumentMatcher.java ├── ClassNameAndFieldPredicatePairArgumentMatcher.java ├── MapMatcher.java ├── MultiValuedMapMatcher.java ├── RecursivelyEqualArgumentMatcher.java ├── StringPredicateArgumentMatcher.java └── TestHelper.java └── pl └── pojo └── tester ├── api ├── ClassAndFieldPredicatePairTest.java ├── ConstructorParametersTest.java ├── DefaultPackageFilterTest.java ├── FastTestingTest.java ├── FieldPredicateTest.java ├── NamedPredicateTest.java └── assertion │ ├── AbstractAssertionTest.java │ ├── AssertionsTest.java │ ├── MethodTest.java │ ├── MultiClassAssertionTest.java │ └── SingleClassAssetionTest.java └── internal ├── GetOrSetValueExceptionTest.java ├── assertion ├── AbstractAssertionErrorTest.java ├── TestAssertionsTest.java ├── constructor ├── equals │ ├── ConsistentEqualsAssertionErrorTest.java │ ├── EqualAssertionsTest.java │ ├── EqualEqualsAssertionErrorTest.java │ ├── EqualsAssertionErrorTest.java │ ├── NotEqualEqualsAssertionErrorTest.java │ ├── NullEqualsAssertionErrorTest.java │ ├── OtherTypeEqualsAssertionErrorTest.java │ ├── ReflexiveEqualsAssertionErrorTest.java │ ├── SymmetricEqualsAssertionErrorTest.java │ └── TransitiveEqualsAssertionErrorTest.java ├── getter │ ├── GetterAssertionErrorTest.java │ └── GetterAssertionsTest.java ├── hashcode │ ├── AbstractHashCodeAssertionErrorTest.java │ ├── ConsistentHashCodeAssertionErrorTest.java │ ├── EqualHashCodeAssertionErrorTest.java │ ├── HashCodeAssertionsTest.java │ └── NotEqualHashCodeAssertionErrorTest.java ├── setter │ ├── SetterAssertionErrorTest.java │ └── SetterAssertionsTest.java └── tostring │ ├── AbstractToStringAssertionErrorTest.java │ ├── ContainsToStringAssertionErrorTest.java │ ├── NotContainToStringAssertionErrorTest.java │ └── ToStringAssertionsTest.java ├── field ├── AbstractFieldValueChangerTest.java ├── DefaultFieldValueChangerTest.java ├── EnumValueChangerTest.java ├── StringValueChangerTest.java ├── UUIDValueChangerTest.java ├── collections │ ├── ArrayValueChangerTest.java │ ├── StreamValueChangerTest.java │ ├── collection │ │ ├── AbstractCollectionFieldValueChangerTest.java │ │ ├── ArrayListValueChangerTest.java │ │ ├── DequeValueChangerTest.java │ │ ├── HashSetValueChangerTest.java │ │ ├── LinkedHashSetValueChangerTest.java │ │ ├── LinkedListValueChangerTest.java │ │ ├── ListValueChangerTest.java │ │ ├── QueueChangerTest.java │ │ ├── SetChangerTest.java │ │ ├── SortedSetChangerTest.java │ │ ├── StackChangerTest.java │ │ ├── TreeSetChangerTest.java │ │ └── VectorChangerTest.java │ ├── iterators │ │ ├── AbstractIteratorsFieldValueChangerTest.java │ │ ├── IterableValueChangerTest.java │ │ └── IteratorValueChangerTest.java │ └── map │ │ ├── AbstractMapFieldValueChangerTest.java │ │ ├── HashMapValueChangerTest.java │ │ ├── HashtableValueChangerTest.java │ │ ├── LinkedHashMapValueChangerTest.java │ │ ├── MapValueChangerTest.java │ │ ├── SortedMapValueChangerTest.java │ │ └── TreeMapValueChangerTest.java ├── date │ ├── DateFieldValueChangerTest.java │ ├── InstantFieldValueChangerTest.java │ ├── LocalDateFieldValueChangerTest.java │ ├── LocalDateTimeFieldValueChangerTest.java │ ├── LocalTimeFieldValueChangerTest.java │ ├── SqlDateFieldValueChangerTest.java │ └── ZonedDateTimeFieldValueChangerTest.java ├── math │ ├── BigDecimalValueChangerTest.java │ └── BigIntegerValueChangerTest.java └── primitive │ ├── AbstractPrimitiveValueChangerTest.java │ ├── BooleanValueChangerTest.java │ ├── ByteValueChangerTest.java │ ├── CharacterValueChangerTest.java │ ├── DoubleValueChangerTest.java │ ├── FloatValueChangerTest.java │ ├── IntegerValueChangerTest.java │ ├── LongValueChangerTest.java │ └── ShortValueChangerTest.java ├── instantiator ├── AbstractMultiConstructorInstantiatorTest.java ├── ArrayInstantiatorTest.java ├── BestConstructorInstantiatorTest.java ├── CollectionInstantiatorTest.java ├── DefaultConstructorInstantiatorTest.java ├── EnumInstantiatorTest.java ├── InstantiableTest.java ├── JavaTypeInstantiatorTest.java ├── ObjectGeneratorFastTest.java ├── ObjectGeneratorTest.java ├── ProxyInstantiatorTest.java └── UserDefinedConstructorInstantiatorTest.java ├── preconditions └── ParameterPreconditionsTest.java ├── tester ├── AbstractTesterTest.java ├── ConstructorTesterTest.java ├── EqualsFastTesterTest.java ├── EqualsTesterTest.java ├── GetterTesterTest.java ├── HashCodeTesterTest.java ├── SetterTesterTest.java └── ToStringTesterTest.java └── utils ├── ClassLoaderTest.java ├── CollectionUtilsTest.java ├── FieldUtilsTest.java ├── MethodUtilsTest.java ├── ReflectionUtilsTest.java ├── SublistFieldPermutatorTest.java └── ThoroughFieldPermutatorTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | /build 3 | /classes 4 | .gradle 5 | 6 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 7 | !gradle-wrapper.jar 8 | 9 | # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 10 | gradle/wrapper/gradle-wrapper.properties 11 | docs/gitbook/gitbook-plugin-livereload/ 12 | src/book/javadoc 13 | 14 | !.idea/codeStyleSettings.xml 15 | out -------------------------------------------------------------------------------- /.idea/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 19 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # `POJO-TESTER` - Java framework for pojo-testing 2 | 3 | # PROJECT IS ON HOLD 4 | ## I have no time to invest more in this project. See https://github.com/sta-szek/pojo-tester/issues/247 5 | ## Thank you for using pojo-tester! It has 131 019 (05.06.2020) downloads total! I was not expecting such popularity :rocket: 6 | 7 | 8 | ---- 9 | `POJO-TESTER` is a java testing library, which makes your `pojo-tests` much easier. You can test your `pojo` against `equals`, `hashCode`, `toString`, `getters`, `setters` and `constructors`. 10 | 11 | Get more information at [pojo-tester documentation site](http://pojo.pl) 12 | 13 | If you have any questions, we can chat on [![Rocket.Chat](https://demo.rocket.chat/images/join-chat.svg)](http://chat.pojo.pl/channel/pojo-tester) 14 | 15 | Build status is provided by 16 | 17 | Current coverage is [![codecov](https://codecov.io/gh/sta-szek/pojo-tester/branch/master/graph/badge.svg)](https://codecov.io/gh/sta-szek/pojo-tester) 18 | 19 | Project quality [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f20e4ae366964fe4864179d26ed392c4)](https://www.codacy.com/app/sta-szek/pojo-tester?utm_source=github.com&utm_medium=referral&utm_content=sta-szek/pojo-tester&utm_campaign=Badge_Grade) 20 | 21 | Download latest version [![Download](https://api.bintray.com/packages/sta-szek/maven/pojo-tester/images/download.svg) ](https://bintray.com/sta-szek/maven/pojo-tester/_latestVersion) 22 | 23 | Get automatic notifications about new `POJO-TESTER` versions 24 | 25 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: 2 | layout: "header, diff, tree, changes, sunburst" 3 | 4 | coverage: 5 | precision: 3 6 | round: down 7 | range: "80...100" 8 | 9 | status: 10 | project: 11 | default: 12 | target: 95% 13 | threshold: 1% 14 | base: auto 15 | set_pending: yes 16 | if_no_uploads: error 17 | if_not_found: success 18 | if_ci_failed: error 19 | 20 | patch: 21 | default: 22 | target: 95% 23 | set_pending: yes 24 | base: auto 25 | if_no_uploads: success 26 | if_not_found: success 27 | if_ci_failed: error 28 | 29 | changes: 30 | default: 31 | base: auto 32 | set_pending: yes 33 | if_no_uploads: error 34 | if_not_found: success 35 | if_ci_failed: error 36 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | group=pl.pojo 2 | artifact=pojo-tester 3 | version=0.8.0-SNAPSHOT 4 | sourceCompatibility=1.8 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sta-szek/pojo-tester/0860ba76af2e675e1143f6060fe3192c05d69be5/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Dec 17 10:43:20 CET 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'pojo-tester' 2 | -------------------------------------------------------------------------------- /src/book/.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules/ 3 | build 4 | _book/ 5 | -------------------------------------------------------------------------------- /src/book/CNAME: -------------------------------------------------------------------------------- 1 | www.pojo.pl 2 | -------------------------------------------------------------------------------- /src/book/book.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "POJO-TESTER User Guide", 3 | "description": "POJO-TESTER is java testing library, which makes your pojo methods tests much easier and more bulletproof!", 4 | "plugins": [ 5 | "anchors", 6 | "toggle-chapters", 7 | "sharing", 8 | "editlink", 9 | "share", 10 | "sitemap", 11 | "disqus", 12 | "nocache", 13 | "back-to-top-button", 14 | "advanced-emoji", 15 | "prettify-html", 16 | "ga", 17 | "github", 18 | "githubcontributors" 19 | ], 20 | "pluginsConfig": { 21 | "ga": { 22 | "token": "UA-84695813-1" 23 | }, 24 | "sitemap": { 25 | "hostname": "http://pojo.pl/" 26 | }, 27 | "github": { 28 | "url": "https://github.com/sta-szek/pojo-tester" 29 | }, 30 | "editlink": { 31 | "base": "https://github.com/sta-szek/pojo-tester/edit/master/src/book", 32 | "label": "Edit This Page", 33 | "multilingual": false 34 | }, 35 | "disqus": { 36 | "shortName": "pojo" 37 | }, 38 | "githubcontributors": { 39 | "githubOwner": "sta-szek", 40 | "githubRepository": "pojo-tester", 41 | "contributorWidth": "370px" 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/book/comparison/coverage-comparison.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sta-szek/pojo-tester/0860ba76af2e675e1143f6060fe3192c05d69be5/src/book/comparison/coverage-comparison.png -------------------------------------------------------------------------------- /src/book/comparison/pojo-the-winner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sta-szek/pojo-tester/0860ba76af2e675e1143f6060fe3192c05d69be5/src/book/comparison/pojo-the-winner.png -------------------------------------------------------------------------------- /src/book/contributors/README.md: -------------------------------------------------------------------------------- 1 | # Contributors 2 | 3 | 4 | {% GitHubContributors %} 5 | {% endGitHubContributors %} 6 | -------------------------------------------------------------------------------- /src/book/why-use/coverage-with-pojo-tester.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sta-szek/pojo-tester/0860ba76af2e675e1143f6060fe3192c05d69be5/src/book/why-use/coverage-with-pojo-tester.png -------------------------------------------------------------------------------- /src/book/why-use/coverage-without-pojo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sta-szek/pojo-tester/0860ba76af2e675e1143f6060fe3192c05d69be5/src/book/why-use/coverage-without-pojo.png -------------------------------------------------------------------------------- /src/book/writing-tests/log4jproperties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sta-szek/pojo-tester/0860ba76af2e675e1143f6060fe3192c05d69be5/src/book/writing-tests/log4jproperties.png -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue153/Message.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue153; 2 | 3 | import org.apache.commons.lang3.builder.EqualsBuilder; 4 | import org.apache.commons.lang3.builder.HashCodeBuilder; 5 | import org.apache.commons.lang3.builder.ToStringBuilder; 6 | 7 | import java.util.LinkedHashSet; 8 | import java.util.Set; 9 | import java.util.UUID; 10 | 11 | class Message { 12 | 13 | private final UUID id; 14 | private final Set readers; 15 | 16 | public Message() { 17 | this.id = UUID.randomUUID(); 18 | this.readers = new LinkedHashSet<>(); 19 | } 20 | 21 | @Override 22 | public boolean equals(final Object obj) { 23 | if (this == obj) { 24 | return true; 25 | } 26 | 27 | if (obj == null || getClass() != obj.getClass()) { 28 | return false; 29 | } 30 | 31 | final Message that = (Message) obj; 32 | 33 | return new EqualsBuilder().append(id, that.id) 34 | .append(readers, that.readers) 35 | .isEquals(); 36 | } 37 | 38 | @Override 39 | public int hashCode() { 40 | return new HashCodeBuilder().append(id) 41 | .append(readers) 42 | .toHashCode(); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return new ToStringBuilder(this).append("id", id) 48 | .append("readers", readers) 49 | .toString(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue153/NullOrEmptyCollectionsTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue153; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; 6 | import static pl.pojo.tester.api.assertion.Method.*; 7 | 8 | class NullOrEmptyCollectionsTest { 9 | 10 | @Test 11 | void shouldPojoBeWellImplemented() { 12 | assertPojoMethodsFor(Message.class).testing(TO_STRING, EQUALS, CONSTRUCTOR, HASH_CODE) 13 | .areWellImplemented(); 14 | } 15 | } -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue153/Person.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue153; 2 | 3 | 4 | import org.apache.commons.lang3.builder.EqualsBuilder; 5 | import org.apache.commons.lang3.builder.HashCodeBuilder; 6 | import org.apache.commons.lang3.builder.ToStringBuilder; 7 | 8 | class Person { 9 | 10 | private final String id; 11 | private final PersonType type; 12 | 13 | public Person(final String id, final PersonType type) { 14 | this.id = id; 15 | this.type = type; 16 | } 17 | 18 | @Override 19 | public boolean equals(final Object obj) { 20 | if (this == obj) { 21 | return true; 22 | } 23 | 24 | if (obj == null || getClass() != obj.getClass()) { 25 | return false; 26 | } 27 | 28 | final Person that = (Person) obj; 29 | 30 | return new EqualsBuilder().append(id, that.id) 31 | .append(type, that.type) 32 | .isEquals(); 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | return new HashCodeBuilder().append(id) 38 | .append(type) 39 | .toHashCode(); 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return new ToStringBuilder(this).append("id", id) 45 | .append("type", type) 46 | .toString(); 47 | } 48 | } -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue153/PersonType.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue153; 2 | 3 | public enum PersonType { 4 | U, A, C, S 5 | } 6 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue157/AbstractClass.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue157; 2 | 3 | 4 | import lombok.EqualsAndHashCode; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | import lombok.ToString; 8 | 9 | @EqualsAndHashCode 10 | @Getter 11 | @ToString 12 | @Setter 13 | public abstract class AbstractClass { 14 | 15 | private String a; 16 | private String b; 17 | private String c; 18 | private int d; 19 | 20 | public AbstractClass(final String a) { 21 | this.a = a; 22 | } 23 | 24 | public void setA(final String a) { 25 | this.a = a; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue157/AbstractClassWithoutDefaultConstructorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue157; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; 6 | 7 | class AbstractClassWithoutDefaultConstructorTest { 8 | 9 | @Test 10 | void shouldPojoBeWellImplemented() { 11 | assertPojoMethodsFor(AbstractClass.class).areWellImplemented(); 12 | } 13 | } -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue187/EntityClass.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue187; 2 | 3 | import lombok.*; 4 | 5 | import java.time.LocalDate; 6 | import java.time.LocalDateTime; 7 | import java.time.LocalTime; 8 | import java.time.ZonedDateTime; 9 | import java.util.Date; 10 | 11 | @Getter 12 | @ToString 13 | @EqualsAndHashCode 14 | @AllArgsConstructor 15 | @NoArgsConstructor(access = AccessLevel.PACKAGE) 16 | public class EntityClass { 17 | 18 | private String f1; 19 | private String f2; 20 | private int f3; 21 | private Date f4; 22 | private LocalDate f5; 23 | private LocalDateTime f6; 24 | private LocalTime f7; 25 | private java.sql.Date f8; 26 | private ZonedDateTime f9; 27 | } 28 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue187/EntityClassPojoTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue187; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | import pl.pojo.tester.api.ConstructorParameters; 6 | 7 | import java.time.LocalDateTime; 8 | import java.time.ZoneId; 9 | import java.time.ZoneOffset; 10 | import java.time.ZonedDateTime; 11 | 12 | import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; 13 | import static pl.pojo.tester.api.assertion.Method.CONSTRUCTOR; 14 | import static pl.pojo.tester.api.assertion.Method.EQUALS; 15 | import static pl.pojo.tester.api.assertion.Method.GETTER; 16 | import static pl.pojo.tester.api.assertion.Method.HASH_CODE; 17 | import static pl.pojo.tester.api.assertion.Method.TO_STRING; 18 | 19 | class EntityClassPojoTest { 20 | 21 | @Test 22 | void Should_Test_Entity_Class() { 23 | final ConstructorParameters constructorParameters = new ConstructorParameters( 24 | new Object[]{ LocalDateTime.now(), ZoneOffset.MAX, ZoneId.systemDefault() }, 25 | new Class[]{ LocalDateTime.class, ZoneOffset.class, ZoneId.class }); 26 | 27 | for (int i = 0; i < 100; i++) { 28 | assertPojoMethodsFor(EntityClass.class).testing(GETTER, TO_STRING, CONSTRUCTOR, EQUALS, HASH_CODE) 29 | .create(ZonedDateTime.class, constructorParameters) 30 | .areWellImplemented(); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue192/ConstructorWithZonedDateTime.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue192; 2 | 3 | 4 | import lombok.EqualsAndHashCode; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | import lombok.ToString; 8 | 9 | import java.time.ZonedDateTime; 10 | 11 | @ToString 12 | @EqualsAndHashCode 13 | @Setter 14 | @Getter 15 | class ConstructorWithZonedDateTime { 16 | 17 | private ZonedDateTime zonedDateTime; 18 | 19 | ConstructorWithZonedDateTime(final ZonedDateTime zonedDateTime) { 20 | this.zonedDateTime = zonedDateTime; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue192/ConstructorWithZonedDateTimeTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue192; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; 7 | 8 | class ConstructorWithZonedDateTimeTest { 9 | 10 | @Test 11 | void Should_Create_Instance_That_Have_Zoned_Date_Time_As_Constructor_Parameter() { 12 | assertPojoMethodsFor(ConstructorWithZonedDateTime.class).areWellImplemented(); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue212/BBB.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue212; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | class BBB { 7 | } -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue212/DefensiveCopy.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue212; 2 | 3 | 4 | import lombok.Data; 5 | 6 | import java.util.Arrays; 7 | 8 | @Data 9 | public class DefensiveCopy { 10 | private BBB[] bbb = new BBB[]{new BBB(), new BBB()}; 11 | 12 | public BBB[] getBbb() { 13 | return bbb == null ? null : Arrays.copyOf(bbb, bbb.length); 14 | } 15 | 16 | public void setBbb(final BBB[] bbb) { 17 | this.bbb = (bbb == null) ? null : Arrays.copyOf(bbb, bbb.length); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue212/DefensiveCopyTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue212; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | import pl.pojo.tester.api.assertion.Method; 6 | 7 | import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; 8 | 9 | class DefensiveCopyTest { 10 | 11 | @Test 12 | void Should_Test_Getters_And_Setters_In_Defensive_Copy_Class() { 13 | assertPojoMethodsFor(DefensiveCopy.class) 14 | .testing(Method.GETTER) 15 | .testing(Method.SETTER) 16 | .areWellImplemented(); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue215/AbstractProduct.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue215; 2 | 3 | import lombok.Getter; 4 | import lombok.NonNull; 5 | import lombok.RequiredArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @RequiredArgsConstructor 9 | @Getter 10 | public abstract class AbstractProduct implements Taxable { 11 | @NonNull 12 | private String name; 13 | 14 | @NonNull 15 | private double prixHT; 16 | 17 | @NonNull 18 | private boolean imported; 19 | 20 | @Setter 21 | private double prixTTC; 22 | 23 | @Setter 24 | private double taxe; 25 | 26 | @Override 27 | public boolean isExemptedTaxe() { 28 | return false; 29 | } 30 | } -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue215/ClassAsConstructorParameterTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue215; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import pl.pojo.tester.api.ConstructorParameters; 5 | 6 | import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; 7 | import static pl.pojo.tester.api.assertion.Method.*; 8 | 9 | class ClassAsConstructorParameterTest { 10 | 11 | @Test 12 | void Should_Test_Class_With_Class_As_Constructor_Parameter() { 13 | // given 14 | final Class classUnderTest = ProductConfig.class; 15 | final Object[] parameters = {Nourriture.class, "Legume", 1d, false}; 16 | final Class[] parameterTypes = {Class.class, String.class, double.class, boolean.class}; 17 | final ConstructorParameters constructorParameters = new ConstructorParameters(parameters, parameterTypes); 18 | 19 | // when 20 | 21 | // then 22 | assertPojoMethodsFor(classUnderTest).create(classUnderTest, constructorParameters) 23 | .testing(GETTER) 24 | .testing(TO_STRING) 25 | .testing(EQUALS, HASH_CODE) 26 | .testing(CONSTRUCTOR) 27 | .areWellImplemented(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue215/IProduct.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue215; 2 | 3 | /** 4 | * PatternBox: "IProduct" implementation. 5 | * 8 | * 9 | * @author Dirk Ehms, www.patternbox.com 10 | * @author mnarouman 11 | */ 12 | public interface IProduct { 13 | String getName(); 14 | 15 | double getPrixHT(); 16 | 17 | double getPrixTTC(); 18 | 19 | void setPrixTTC(double prixHT); 20 | 21 | boolean isExemptedTaxe(); 22 | 23 | boolean isImported(); 24 | 25 | } -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue215/Nourriture.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue215; 2 | 3 | import lombok.Builder; 4 | 5 | public class Nourriture extends AbstractProduct { 6 | @Builder 7 | private Nourriture(final String name, final double prixHT, final boolean imported) { 8 | super(name, prixHT, imported); 9 | } 10 | 11 | @Override 12 | public void applyTaxe() { 13 | setPrixTTC(getPrixHT()); 14 | } 15 | 16 | @Override 17 | public boolean isExemptedTaxe() { 18 | return true; 19 | } 20 | } -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue215/ProductConfig.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue215; 2 | 3 | import lombok.Builder; 4 | import lombok.EqualsAndHashCode; 5 | import lombok.ToString; 6 | import lombok.Value; 7 | 8 | @Builder 9 | @Value 10 | @EqualsAndHashCode 11 | @ToString 12 | public class ProductConfig { 13 | private Class productType; 14 | private String productName; 15 | private double prixHT; 16 | private boolean imported; 17 | } -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/issue215/Taxable.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.issue215; 2 | 3 | /** 4 | * A taxe decorator interface 5 | * 6 | * @author michel 7 | */ 8 | public interface Taxable extends IProduct { 9 | double getTaxe(); 10 | 11 | void setTaxe(double taxe); 12 | 13 | /** 14 | * Compute prixTTC and the product taxe 15 | */ 16 | void applyTaxe(); 17 | } 18 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/logs/A.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.logs; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class A { 7 | 8 | private int a; 9 | private B b; 10 | } 11 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/logs/B.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.logs; 2 | 3 | 4 | import lombok.Data; 5 | 6 | @Data 7 | public class B { 8 | private int b; 9 | private C c; 10 | } 11 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/logs/C.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.logs; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class C { 7 | private int c; 8 | private C d; 9 | } 10 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/logs/LogsTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.logs; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsForAll; 7 | 8 | class LogsTest { 9 | 10 | @Test 11 | void Should_Test_Class_With_Static_Fields() { 12 | // given 13 | 14 | // when 15 | 16 | // then 17 | assertPojoMethodsForAll(A.class, B.class, C.class).areWellImplemented(); 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/statics/ClassWithStaticField.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.statics; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | class ClassWithStaticField { 7 | 8 | private static final String STATIC_FINAL = "test"; 9 | private int a; 10 | private int b; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/statics/StaticFieldTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.statics; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static pl.pojo.tester.api.FieldPredicate.exclude; 7 | import static pl.pojo.tester.api.FieldPredicate.include; 8 | import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; 9 | 10 | class StaticFieldTest { 11 | 12 | @Test 13 | void Should_Test_Class_With_Static_Fields() { 14 | // given 15 | 16 | // when 17 | 18 | // then 19 | assertPojoMethodsFor(ClassWithStaticField.class).areWellImplemented(); 20 | } 21 | 22 | @Test 23 | void Should_Test_Class_With_Excluded_Static_Fields() { 24 | // given 25 | 26 | // when 27 | 28 | // then 29 | assertPojoMethodsFor(ClassWithStaticField.class, exclude("STATIC_FINAL")).areWellImplemented(); 30 | } 31 | 32 | @Test 33 | void Should_Test_Class_With_Included_Non_Static_Fields() { 34 | // given 35 | 36 | // when 37 | 38 | // then 39 | assertPojoMethodsFor(ClassWithStaticField.class, include("a", "b")).areWellImplemented(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/types/Collections_Collection_Types.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.types; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.*; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class Collections_Collection_Types { 13 | 14 | private ArrayList arrayList; 15 | private Deque deque; 16 | private HashSet hashSet; 17 | private LinkedHashSet linkedHashSet; 18 | private LinkedList linkedList; 19 | private List list; 20 | private Queue queue; 21 | private Set set; 22 | private SortedMap sortedMap; 23 | private Stack stack; 24 | private TreeSet treeSet; 25 | private Vector vector; 26 | } 27 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/types/Collections_Iterators_Types.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.types; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.Iterator; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class Collections_Iterators_Types { 13 | 14 | private Iterator iterator; 15 | private Iterable iterable; 16 | } 17 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/types/Collections_Map_Types.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.types; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.*; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class Collections_Map_Types { 13 | 14 | private HashMap hashMap; 15 | private Hashtable hashtable; 16 | private LinkedHashMap linkedHashMap; 17 | private Map map; 18 | private SortedSet sortedSet; 19 | private TreeMap treeMap; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/types/Collections_Other_Types.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.types; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.stream.Stream; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class Collections_Other_Types { 13 | 14 | private boolean[] boolean_; 15 | private byte[] byte_; 16 | private char[] character_; 17 | private double[] double_; 18 | private int[] integer_; 19 | private long[] long_; 20 | private short[] short_; 21 | private float[] float_; 22 | private Stream stream; 23 | } 24 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/types/Collections_Types.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.types; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.stream.Stream; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class Collections_Types { 13 | 14 | private int[] array; 15 | private Stream stream; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/types/Math_Types.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.types; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.math.BigDecimal; 8 | import java.math.BigInteger; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | public class Math_Types { 14 | 15 | private BigInteger bigInteger; 16 | private BigDecimal bigDecimal; 17 | } 18 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/types/Other_Types.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.types; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.UUID; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class Other_Types { 13 | 14 | private UUID uuid; 15 | private Enum enum_; 16 | private String string; 17 | } 18 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/types/Primitive_Types.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.types; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class Primitive_Types { 11 | 12 | private boolean boolean_; 13 | private byte byte_; 14 | private char character_; 15 | private double double_; 16 | private int integer_; 17 | private long long_; 18 | private short short_; 19 | private float float_; 20 | } 21 | -------------------------------------------------------------------------------- /src/integrationTest/java/pl/pojo/tester/usecase/types/Primitive_Wrapped_Types.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.usecase.types; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class Primitive_Wrapped_Types { 11 | 12 | private Boolean boolean_; 13 | private Byte byte_; 14 | private Character character_; 15 | private Double double_; 16 | private Integer integer_; 17 | private Long long_; 18 | private Short short_; 19 | private Float float_; 20 | } 21 | -------------------------------------------------------------------------------- /src/integrationTest/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, stdout 3 | # Direct log messages to stdout 4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.Target=System.out 6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/api/DefaultPackageFilter.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.api; 2 | 3 | 4 | import pl.pojo.tester.internal.utils.ReflectionUtils; 5 | 6 | import java.io.IOException; 7 | 8 | import static pl.pojo.tester.internal.preconditions.ParameterPreconditions.checkNotBlank; 9 | 10 | /** 11 | * Default package filter filters classes from package name recursively. 12 | * 13 | * @author Piotr Joński 14 | * @since 0.5.0 15 | */ 16 | public final class DefaultPackageFilter implements PackageFilter { 17 | 18 | private final String packageName; 19 | 20 | private DefaultPackageFilter(final String packageName) { 21 | checkNotBlank("packageName", packageName); 22 | this.packageName = packageName; 23 | } 24 | 25 | /** 26 | * Creates filter for package name. 27 | * 28 | * @param packageName name of package 29 | * @return filter for package name 30 | */ 31 | public static DefaultPackageFilter forPackage(final String packageName) { 32 | return new DefaultPackageFilter(packageName); 33 | } 34 | 35 | /** 36 | * Creates filter for package of given class. 37 | * 38 | * @param clazz class 39 | * @return filter for class package 40 | */ 41 | public static DefaultPackageFilter forClass(final Class clazz) { 42 | return new DefaultPackageFilter(clazz.getPackage() 43 | .getName()); 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | * 49 | * @return filtered classes 50 | */ 51 | @Override 52 | public Class[] getClasses() { 53 | try { 54 | return ReflectionUtils.getClassesFromPackage(packageName); 55 | } catch (final IOException e) { 56 | throw new PackageFilterException(packageName, e); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/api/PackageFilter.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.api; 2 | 3 | /** 4 | * Interface for package filtering. 5 | * 6 | * @author Piotr Joński 7 | * @since 0.5.0 8 | */ 9 | @FunctionalInterface 10 | public interface PackageFilter { 11 | 12 | /** 13 | * Returns classes filtered by filter. 14 | * 15 | * @return classes 16 | */ 17 | Class[] getClasses(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/api/PackageFilterException.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.api; 2 | 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * Exception is thrown when package or converted to filename package does not exist in file system. 8 | * 9 | * @author Piotr Joński 10 | * @since 0.5.0 11 | */ 12 | public class PackageFilterException extends RuntimeException { 13 | 14 | /** 15 | * Instantiates exception. 16 | * 17 | * @param packageName package name or file of package 18 | * @param cause cause, which raised this exception 19 | */ 20 | public PackageFilterException(final String packageName, final IOException cause) { 21 | super(createMessage(packageName), cause); 22 | } 23 | 24 | private static String createMessage(final String packageName) { 25 | return String.format("Package '%s' does not exist.", packageName); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/api/assertion/Method.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.api.assertion; 2 | 3 | 4 | import pl.pojo.tester.internal.tester.AbstractTester; 5 | import pl.pojo.tester.internal.tester.ConstructorTester; 6 | import pl.pojo.tester.internal.tester.EqualsTester; 7 | import pl.pojo.tester.internal.tester.GetterTester; 8 | import pl.pojo.tester.internal.tester.HashCodeTester; 9 | import pl.pojo.tester.internal.tester.SetterTester; 10 | import pl.pojo.tester.internal.tester.ToStringTester; 11 | 12 | /** 13 | * Declares methods that can be tested using POJO-TESTER. 14 | *

15 | * For more documentation, please refer POJO-TESTER User Guide documentation 16 | * 17 | * @author Piotr Joński 18 | * @since 0.1.0 19 | */ 20 | public enum Method { 21 | EQUALS(EqualsTester.class), 22 | HASH_CODE(HashCodeTester.class), 23 | SETTER(SetterTester.class), 24 | GETTER(GetterTester.class), 25 | TO_STRING(ToStringTester.class), 26 | CONSTRUCTOR(ConstructorTester.class); 27 | 28 | private final Class testerClass; 29 | 30 | Method(final Class tester) { 31 | this.testerClass = tester; 32 | } 33 | 34 | public AbstractTester getTester() { 35 | try { 36 | return testerClass.newInstance(); 37 | } catch (InstantiationException | IllegalAccessException e) { 38 | throw new TesterInstantiationException(e); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/api/assertion/MultiClassAssertion.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.api.assertion; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import pl.pojo.tester.api.ClassAndFieldPredicatePair; 6 | 7 | import java.util.List; 8 | 9 | 10 | class MultiClassAssertion extends AbstractAssertion { 11 | 12 | private static final Logger LOGGER = LoggerFactory.getLogger(MultiClassAssertion.class); 13 | 14 | private final List classAndFieldPredicatePairs; 15 | 16 | MultiClassAssertion(final List classAndFieldPredicatePairs) { 17 | super(); 18 | this.classAndFieldPredicatePairs = classAndFieldPredicatePairs; 19 | } 20 | 21 | @Override 22 | protected void runAssertions() { 23 | final ClassAndFieldPredicatePair[] classes = classAndFieldPredicatePairs.toArray( 24 | new ClassAndFieldPredicatePair[classAndFieldPredicatePairs.size()]); 25 | logTestersAndClasses(LOGGER, classes); 26 | testers.forEach(tester -> tester.testAll(classes)); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/api/assertion/TesterInstantiationException.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.api.assertion; 2 | 3 | class TesterInstantiationException extends RuntimeException { 4 | TesterInstantiationException(final Throwable cause) { 5 | super(cause); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/GetOrSetValueException.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal; 2 | 3 | 4 | public class GetOrSetValueException extends RuntimeException { 5 | 6 | public GetOrSetValueException(final String fieldName, final Class clazz, final Exception cause) { 7 | super(createMessage(fieldName, clazz, cause.getMessage()), cause); 8 | } 9 | 10 | private static String createMessage(final String fieldName, final Class clazz, final String causeMessage) { 11 | return "Unable to get or set value for field '" + fieldName + "' in class '" + clazz + "'." 12 | + "\n Cause message: " + causeMessage; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/AbstractAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion; 2 | 3 | 4 | public abstract class AbstractAssertionError extends RuntimeException { 5 | 6 | protected final Class testedCass; 7 | 8 | public AbstractAssertionError(final Class testedCass) { 9 | super(); 10 | this.testedCass = testedCass; 11 | setStackTrace(new StackTraceElement[]{}); 12 | } 13 | 14 | @Override 15 | public String getMessage() { 16 | return "\n\n\n" + getErrorPrefix() + "\n" + getDetailedMessage(); 17 | } 18 | 19 | protected abstract String getErrorPrefix(); 20 | 21 | protected abstract String getDetailedMessage(); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/TestAssertions.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion; 2 | 3 | 4 | import pl.pojo.tester.internal.assertion.constructor.ConstructorAssertions; 5 | import pl.pojo.tester.internal.assertion.equals.EqualAssertions; 6 | import pl.pojo.tester.internal.assertion.getter.GetterAssertions; 7 | import pl.pojo.tester.internal.assertion.hashcode.HashCodeAssertions; 8 | import pl.pojo.tester.internal.assertion.setter.SetterAssertions; 9 | import pl.pojo.tester.internal.assertion.tostring.ToStringAssertions; 10 | 11 | import java.lang.reflect.Constructor; 12 | 13 | public class TestAssertions { 14 | 15 | public EqualAssertions assertThatEqualsMethodFor(final Object objectUnderAssert) { 16 | return new EqualAssertions(objectUnderAssert); 17 | } 18 | 19 | public HashCodeAssertions assertThatHashCodeMethodFor(final Object objectUnderAssert) { 20 | return new HashCodeAssertions(objectUnderAssert); 21 | } 22 | 23 | public ToStringAssertions assertThatToStringMethodFor(final Object objectUnderAssert) { 24 | return new ToStringAssertions(objectUnderAssert); 25 | } 26 | 27 | public SetterAssertions assertThatSetMethodFor(final Object objectUnderAssert) { 28 | return new SetterAssertions(objectUnderAssert); 29 | } 30 | 31 | public GetterAssertions assertThatGetMethodFor(final Object objectUnderAssert) { 32 | return new GetterAssertions(objectUnderAssert); 33 | } 34 | 35 | public ConstructorAssertions assertThatConstructor(final Constructor constructorUnderAssert) { 36 | return new ConstructorAssertions(constructorUnderAssert); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/constructor/ConstructorAssertions.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.constructor; 2 | 3 | 4 | import java.lang.reflect.Constructor; 5 | import java.lang.reflect.InvocationTargetException; 6 | 7 | public class ConstructorAssertions { 8 | 9 | private final Constructor constructorUnderAssert; 10 | private final Class classUnderTest; 11 | 12 | public ConstructorAssertions(final Constructor constructorUnderAssert) { 13 | this.constructorUnderAssert = constructorUnderAssert; 14 | this.classUnderTest = constructorUnderAssert.getDeclaringClass(); 15 | } 16 | 17 | public void willInstantiateClassUsing(final Object... constructorParameters) { 18 | constructorUnderAssert.setAccessible(true); 19 | try { 20 | constructorUnderAssert.newInstance(constructorParameters); 21 | } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { 22 | throw new ConstructorAssertionError(classUnderTest, constructorUnderAssert, constructorParameters, e); 23 | } 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/equals/AbstractEqualsAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | import pl.pojo.tester.internal.assertion.AbstractAssertionError; 5 | 6 | public abstract class AbstractEqualsAssertionError extends AbstractAssertionError { 7 | 8 | 9 | AbstractEqualsAssertionError(final Class testedCass) { 10 | super(testedCass); 11 | } 12 | 13 | @Override 14 | protected String getErrorPrefix() { 15 | return String.format("Class %s has bad 'equals' method implementation.", testedCass.getCanonicalName()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/equals/ConsistentEqualsAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | class ConsistentEqualsAssertionError extends AbstractEqualsAssertionError { 5 | 6 | private static final String CONSTRAINT_CONSISTENT = "The equals method should be consistent when comparing same objects multiple " 7 | + "times.\n" 8 | + "Current implementation returns different results.\n" 9 | + "When comparing object:\n" 10 | + "%s\n" 11 | + "to itself, first result was '%s' and second time was '%s'."; 12 | private final Object testedObject; 13 | private final boolean firstResult; 14 | private final boolean secondResult; 15 | 16 | 17 | ConsistentEqualsAssertionError(final Class testedCass, 18 | final Object testedObject, 19 | final boolean firstResult, 20 | final boolean secondResult) { 21 | super(testedCass); 22 | this.testedObject = testedObject; 23 | this.firstResult = firstResult; 24 | this.secondResult = secondResult; 25 | } 26 | 27 | @Override 28 | protected String getDetailedMessage() { 29 | return String.format(CONSTRAINT_CONSISTENT, testedObject, firstResult, secondResult); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/equals/EqualEqualsAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | class EqualEqualsAssertionError extends AbstractEqualsAssertionError { 5 | 6 | private static final String CONSTRAINT_NOT_EQUAL = 7 | "The equals method should return true if objects should be equal.\n" 8 | + "Current implementation returns false.\n" 9 | + "Object:\n" 10 | + "%s\n" 11 | + "should be equal to:\n" 12 | + "%s"; 13 | private final Object testedObject; 14 | private final Object otherObject; 15 | 16 | EqualEqualsAssertionError(final Class testedCass, final Object testedObject, final Object otherObject) { 17 | super(testedCass); 18 | this.testedObject = testedObject; 19 | this.otherObject = otherObject; 20 | } 21 | 22 | @Override 23 | protected String getDetailedMessage() { 24 | return String.format(CONSTRAINT_NOT_EQUAL, testedObject, otherObject); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/equals/NotEqualEqualsAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | class NotEqualEqualsAssertionError extends AbstractEqualsAssertionError { 5 | 6 | private static final String CONSTRAINT_NOT_EQUAL = "The equals method should return false if objects should not be equal.\n" 7 | + "Current implementation returns true.\n" 8 | + "Object:\n" 9 | + "%s\n" 10 | + "should not be equal to:\n" 11 | + "%s"; 12 | private final Object testedObject; 13 | private final Object otherObject; 14 | 15 | NotEqualEqualsAssertionError(final Class testedCass, final Object testedObject, final Object otherObject) { 16 | super(testedCass); 17 | this.testedObject = testedObject; 18 | this.otherObject = otherObject; 19 | } 20 | 21 | @Override 22 | protected String getDetailedMessage() { 23 | return String.format(CONSTRAINT_NOT_EQUAL, testedObject, otherObject); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/equals/NullEqualsAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | class NullEqualsAssertionError extends AbstractEqualsAssertionError { 5 | 6 | private static final String CONSTRAINT_NULL = "The equals method should return false if object is comparing to null.\n" 7 | + "Current implementation returns true."; 8 | 9 | NullEqualsAssertionError(final Class testedCass) { 10 | super(testedCass); 11 | } 12 | 13 | @Override 14 | protected String getDetailedMessage() { 15 | return CONSTRAINT_NULL; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/equals/OtherTypeEqualsAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | class OtherTypeEqualsAssertionError extends AbstractEqualsAssertionError { 5 | 6 | private static final String CONSTRAINT_OTHER_TYPE = "The equals method should return false if object is comparing to object with " 7 | + "different type.\n" 8 | + "Current implementation returns true.\n" 9 | + "Object:\n" 10 | + "%s\n" 11 | + "should not be equal to:\n" 12 | + "%s"; 13 | private final Object testedObject; 14 | private final Object otherObject; 15 | 16 | OtherTypeEqualsAssertionError(final Class testedCass, final Object testedObject, final Object otherObject) { 17 | super(testedCass); 18 | this.testedObject = testedObject; 19 | this.otherObject = otherObject; 20 | } 21 | 22 | @Override 23 | protected String getDetailedMessage() { 24 | return String.format(CONSTRAINT_OTHER_TYPE, testedObject, otherObject); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/equals/ReflexiveEqualsAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | class ReflexiveEqualsAssertionError extends AbstractEqualsAssertionError { 5 | 6 | private static final String CONSTRAINT_REFLEXIVE = "The equals method should return true if object is comparing to itself.\n" 7 | + "Current implementation returns false.\n" 8 | + "Object:\n" 9 | + "%s\n" 10 | + "should be equal to:\n" 11 | + "%s"; 12 | private final Object testedObject; 13 | 14 | ReflexiveEqualsAssertionError(final Class testedCass, final Object testedObject) { 15 | super(testedCass); 16 | this.testedObject = testedObject; 17 | } 18 | 19 | @Override 20 | protected String getDetailedMessage() { 21 | return String.format(CONSTRAINT_REFLEXIVE, testedObject, testedObject); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/equals/SymmetricEqualsAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | class SymmetricEqualsAssertionError extends AbstractEqualsAssertionError { 5 | 6 | private static final String CONSTRAINT_SYMMETRIC = "The equals method should return true for both a.equals(b) and b.equals(a).\n" 7 | + "Current implementation returns:\n" 8 | + "%s for a.equals(b),\n" 9 | + "%s for b.equals(a),\n" 10 | + "where 'a' is:\n" 11 | + "%s\n" 12 | + "and 'b' is:\n" 13 | + "%s"; 14 | private final Object testedObject; 15 | private final Object otherObject; 16 | private final boolean firstResult; 17 | private final boolean secondResult; 18 | 19 | 20 | SymmetricEqualsAssertionError(final Class testedCass, 21 | final Object testedObject, 22 | final Object otherObject, 23 | final boolean firstResult, 24 | final boolean secondResult) { 25 | super(testedCass); 26 | this.testedObject = testedObject; 27 | this.otherObject = otherObject; 28 | this.firstResult = firstResult; 29 | this.secondResult = secondResult; 30 | } 31 | 32 | @Override 33 | protected String getDetailedMessage() { 34 | return String.format(CONSTRAINT_SYMMETRIC, firstResult, secondResult, testedObject, otherObject); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/getter/GetterAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.getter; 2 | 3 | import java.lang.reflect.Field; 4 | import pl.pojo.tester.internal.assertion.AbstractAssertionError; 5 | 6 | class GetterAssertionError extends AbstractAssertionError { 7 | 8 | private static final String CONSTRAINT_GETTER = "The getter method for field '%s' should return field value.\n" 9 | + "Current implementation returns different value.\n" 10 | + "Expected value:\n" 11 | + "%s\n" 12 | + "but was:\n" 13 | + "%s"; 14 | 15 | private final Field field; 16 | private final Object expectedValue; 17 | private final Object currentValue; 18 | 19 | GetterAssertionError(final Class testedCass, final Field field, final Object expectedValue, final Object currentValue) { 20 | super(testedCass); 21 | this.field = field; 22 | this.expectedValue = expectedValue; 23 | this.currentValue = currentValue; 24 | } 25 | 26 | @Override 27 | protected String getDetailedMessage() { 28 | return String.format(CONSTRAINT_GETTER, field, expectedValue, currentValue); 29 | } 30 | 31 | @Override 32 | protected String getErrorPrefix() { 33 | return String.format("Class %s has bad 'getter' method implementation.", testedCass.getCanonicalName()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/getter/GetterAssertions.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.getter; 2 | 3 | 4 | import pl.pojo.tester.internal.GetOrSetValueException; 5 | import pl.pojo.tester.internal.utils.FieldUtils; 6 | 7 | import java.lang.reflect.Field; 8 | import java.lang.reflect.InvocationTargetException; 9 | import java.lang.reflect.Method; 10 | import java.util.Objects; 11 | 12 | public class GetterAssertions { 13 | 14 | private final Object objectUnderAssert; 15 | private final Class classUnderTest; 16 | 17 | public GetterAssertions(final Object objectUnderAssert) { 18 | this.objectUnderAssert = objectUnderAssert; 19 | this.classUnderTest = objectUnderAssert.getClass(); 20 | } 21 | 22 | public void willGetValueFromField(final Method getter, final Field field) { 23 | try { 24 | getter.setAccessible(true); 25 | final Object valueFromGetter; 26 | valueFromGetter = getter.invoke(objectUnderAssert); 27 | final Object value = FieldUtils.getValue(objectUnderAssert, field); 28 | final boolean result = Objects.deepEquals(value, valueFromGetter); 29 | 30 | checkResult(result, new GetterAssertionError(classUnderTest, field, valueFromGetter, value)); 31 | } catch (IllegalAccessException | InvocationTargetException e) { 32 | throw new GetOrSetValueException(field.getName(), classUnderTest, e); 33 | } 34 | } 35 | 36 | 37 | private void checkResult(final boolean pass, final GetterAssertionError errorToThrow) { 38 | if (!pass) { 39 | throw errorToThrow; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/hashcode/AbstractHashCodeAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.hashcode; 2 | 3 | 4 | import pl.pojo.tester.internal.assertion.AbstractAssertionError; 5 | 6 | public abstract class AbstractHashCodeAssertionError extends AbstractAssertionError { 7 | 8 | 9 | AbstractHashCodeAssertionError(final Class testedCass) { 10 | super(testedCass); 11 | } 12 | 13 | @Override 14 | protected String getErrorPrefix() { 15 | return String.format("Class %s has bad 'hashCode' method implementation.", testedCass.getCanonicalName()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/hashcode/ConsistentHashCodeAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.hashcode; 2 | 3 | 4 | class ConsistentHashCodeAssertionError extends AbstractHashCodeAssertionError { 5 | 6 | private static final String CONSTRAINT_CONSISTENT = "The hashCode method should return same hash code for same object.\n" 7 | + "Current implementation returns different values.\n" 8 | + "Object:\n" 9 | + "%s\n" 10 | + "has two different hash codes:\n" 11 | + "%s\n" 12 | + "and" 13 | + "\n%s"; 14 | private final Object testedObject; 15 | private final int firstHashCode; 16 | private final int secondHashCode; 17 | 18 | ConsistentHashCodeAssertionError(final Class testedCass, 19 | final Object testedObject, 20 | final int firstHashCode, 21 | final int secondHashCode) { 22 | super(testedCass); 23 | this.testedObject = testedObject; 24 | this.firstHashCode = firstHashCode; 25 | this.secondHashCode = secondHashCode; 26 | } 27 | 28 | @Override 29 | protected String getDetailedMessage() { 30 | return String.format(CONSTRAINT_CONSISTENT, testedObject, firstHashCode, secondHashCode); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/hashcode/EqualHashCodeAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.hashcode; 2 | 3 | 4 | class EqualHashCodeAssertionError extends AbstractHashCodeAssertionError { 5 | 6 | private static final String CONSTRAINT_EQUAL = "The hashCode method should return same hash code for equal objects.\n" 7 | + "Current implementation returns different values.\n" 8 | + "Object:\n" 9 | + "%s\n" 10 | + "and\n" 11 | + "%s\n" 12 | + "have two different hash codes:\n" 13 | + "%s\n" 14 | + "and\n" 15 | + "%s"; 16 | private final Object testedObject; 17 | private final Object secondObject; 18 | private final int firstHashCode; 19 | private final int secondHashCode; 20 | 21 | EqualHashCodeAssertionError(final Class testedCass, 22 | final Object testedObject, 23 | final Object secondObject, 24 | final int firstHashCode, 25 | final int secondHashCode) { 26 | super(testedCass); 27 | this.testedObject = testedObject; 28 | this.secondObject = secondObject; 29 | this.firstHashCode = firstHashCode; 30 | this.secondHashCode = secondHashCode; 31 | } 32 | 33 | @Override 34 | protected String getDetailedMessage() { 35 | return String.format(CONSTRAINT_EQUAL, testedObject, secondObject, firstHashCode, secondHashCode); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/hashcode/NotEqualHashCodeAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.hashcode; 2 | 3 | 4 | public class NotEqualHashCodeAssertionError extends AbstractHashCodeAssertionError { 5 | 6 | private static final String CONSTRAINT_NOT_EQUAL = "The hashCode method should return different hash codes for non equal objects.\n" 7 | + "Current implementation returns same hash codes.\n" 8 | + "Object:\n" 9 | + "%s\n" 10 | + "and\n" 11 | + "%s\n" 12 | + "should have different hash codes:\n" 13 | + "%s\n" 14 | + "and\n" 15 | + "%s"; 16 | private final Object testedObject; 17 | private final Object secondObject; 18 | private final int firstHashCode; 19 | private final int secondHashCode; 20 | 21 | NotEqualHashCodeAssertionError(final Class testedCass, 22 | final Object testedObject, 23 | final Object secondObject, 24 | final int firstHashCode, 25 | final int secondHashCode) { 26 | super(testedCass); 27 | this.testedObject = testedObject; 28 | this.secondObject = secondObject; 29 | this.firstHashCode = firstHashCode; 30 | this.secondHashCode = secondHashCode; 31 | } 32 | 33 | @Override 34 | protected String getDetailedMessage() { 35 | return String.format(CONSTRAINT_NOT_EQUAL, testedObject, secondObject, firstHashCode, secondHashCode); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/setter/SetterAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.setter; 2 | 3 | 4 | import java.lang.reflect.Field; 5 | import pl.pojo.tester.internal.assertion.AbstractAssertionError; 6 | 7 | class SetterAssertionError extends AbstractAssertionError { 8 | 9 | private static final String CONSTRAINT_SETTER = "The setter method for field '%s' should set field value.\n" 10 | + "Current implementation does not set the value.\n" 11 | + "Expected value:\n" 12 | + "%s\n" 13 | + "but was:\n" 14 | + "%s"; 15 | 16 | private final Field field; 17 | private final Object expectedValue; 18 | private final Object currentValue; 19 | 20 | SetterAssertionError(final Class testedCass, final Field field, final Object expectedValue, final Object currentValue) { 21 | super(testedCass); 22 | this.field = field; 23 | this.expectedValue = expectedValue; 24 | this.currentValue = currentValue; 25 | } 26 | 27 | @Override 28 | protected String getDetailedMessage() { 29 | return String.format(CONSTRAINT_SETTER, field, expectedValue, currentValue); 30 | } 31 | 32 | @Override 33 | protected String getErrorPrefix() { 34 | return String.format("Class %s has bad 'setter' method implementation.", testedCass.getCanonicalName()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/setter/SetterAssertions.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.setter; 2 | 3 | 4 | import pl.pojo.tester.internal.GetOrSetValueException; 5 | import pl.pojo.tester.internal.utils.FieldUtils; 6 | 7 | import java.lang.reflect.Field; 8 | import java.lang.reflect.InvocationTargetException; 9 | import java.lang.reflect.Method; 10 | import java.util.Objects; 11 | 12 | public class SetterAssertions { 13 | 14 | private final Object objectUnderAssert; 15 | private final Class classUnderTest; 16 | 17 | public SetterAssertions(final Object objectUnderAssert) { 18 | this.objectUnderAssert = objectUnderAssert; 19 | this.classUnderTest = objectUnderAssert.getClass(); 20 | } 21 | 22 | public void willSetValueOnField(final Method setter, final Field field, final Object expectedValue) { 23 | try { 24 | setter.setAccessible(true); 25 | setter.invoke(objectUnderAssert, expectedValue); 26 | final Object value = FieldUtils.getValue(objectUnderAssert, field); 27 | final boolean result = Objects.deepEquals(value, expectedValue); 28 | 29 | checkResult(result, new SetterAssertionError(classUnderTest, field, expectedValue, value)); 30 | } catch (IllegalAccessException | InvocationTargetException e) { 31 | throw new GetOrSetValueException(field.getName(), classUnderTest, e); 32 | } 33 | } 34 | 35 | 36 | private void checkResult(final boolean pass, final SetterAssertionError errorToThrow) { 37 | if (!pass) { 38 | throw errorToThrow; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/tostring/AbstractToStringAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.tostring; 2 | 3 | 4 | import pl.pojo.tester.internal.assertion.AbstractAssertionError; 5 | 6 | abstract class AbstractToStringAssertionError extends AbstractAssertionError { 7 | 8 | AbstractToStringAssertionError(final Class testedCass) { 9 | super(testedCass); 10 | } 11 | 12 | @Override 13 | protected String getErrorPrefix() { 14 | return String.format("Class %s has bad 'toString' method implementation.", testedCass.getCanonicalName()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/tostring/ContainsToStringAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.tostring; 2 | 3 | 4 | class ContainsToStringAssertionError extends AbstractToStringAssertionError { 5 | 6 | private static final String CONSTRAINT_CONTAINS = "The toString method should contain:\n" 7 | + "%s\n" 8 | + "But does not.\n" 9 | + "Result of toString:\n" 10 | + "%s"; 11 | private final String value; 12 | private final String toString; 13 | 14 | ContainsToStringAssertionError(final Class testedCass, 15 | final String value, 16 | final String toString) { 17 | super(testedCass); 18 | this.value = value; 19 | this.toString = toString; 20 | } 21 | 22 | @Override 23 | protected String getDetailedMessage() { 24 | return String.format(CONSTRAINT_CONTAINS, value, toString); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/tostring/NotContainToStringAssertionError.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.tostring; 2 | 3 | 4 | class NotContainToStringAssertionError extends AbstractToStringAssertionError { 5 | 6 | private static final String CONSTRAINT_NOT_CONTAIN = "The toString method should not contain:\n" 7 | + "%s\n" 8 | + "but does.\n" 9 | + "Result of toString:\n" 10 | + "%s"; 11 | private final String value; 12 | private final String toString; 13 | 14 | NotContainToStringAssertionError(final Class testedCass, 15 | final String value, 16 | final String toString) { 17 | super(testedCass); 18 | this.value = value; 19 | this.toString = toString; 20 | } 21 | 22 | @Override 23 | protected String getDetailedMessage() { 24 | return String.format(CONSTRAINT_NOT_CONTAIN, value, toString); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/assertion/tostring/ToStringAssertions.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.tostring; 2 | 3 | 4 | import org.apache.commons.lang3.ObjectUtils; 5 | 6 | public class ToStringAssertions { 7 | 8 | private final Object objectUnderAssert; 9 | private final Class classUnderTest; 10 | 11 | public ToStringAssertions(final Object objectUnderAssert) { 12 | this.objectUnderAssert = objectUnderAssert; 13 | this.classUnderTest = objectUnderAssert.getClass(); 14 | } 15 | 16 | 17 | public void contains(final String fieldName, final Object value) { 18 | final String stringValue = fieldName + "=" + getStringOf(value); 19 | final String toString = objectUnderAssert.toString(); 20 | final boolean result = toString.contains(stringValue); 21 | checkResult(result, new ContainsToStringAssertionError(classUnderTest, stringValue, toString)); 22 | 23 | } 24 | 25 | public void doestNotContain(final String fieldName, final Object value) { 26 | final String stringValue = fieldName + "=" + getStringOf(value); 27 | final String toString = objectUnderAssert.toString(); 28 | final boolean result = toString.contains(stringValue); 29 | checkResult(!result, new NotContainToStringAssertionError(classUnderTest, stringValue, toString)); 30 | 31 | } 32 | 33 | private String getStringOf(final Object value) { 34 | final Object notNullObject = ObjectUtils.defaultIfNull(value, ""); 35 | return notNullObject.toString(); 36 | } 37 | 38 | 39 | private void checkResult(final boolean pass, final AbstractToStringAssertionError errorToThrow) { 40 | if (!pass) { 41 | throw errorToThrow; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/DefaultFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field; 2 | 3 | 4 | import pl.pojo.tester.internal.field.collections.CollectionsFieldValueChanger; 5 | import pl.pojo.tester.internal.field.date.DefaultDateAndTimeFieldValueChanger; 6 | import pl.pojo.tester.internal.field.math.BigDecimalValueChanger; 7 | import pl.pojo.tester.internal.field.math.BigIntegerValueChanger; 8 | import pl.pojo.tester.internal.field.primitive.AbstractPrimitiveValueChanger; 9 | 10 | 11 | public final class DefaultFieldValueChanger { 12 | 13 | public static final AbstractFieldValueChanger INSTANCE = new EnumValueChanger() 14 | .attachNext(AbstractPrimitiveValueChanger.INSTANCE) 15 | .attachNext(CollectionsFieldValueChanger.INSTANCE) 16 | .attachNext(DefaultDateAndTimeFieldValueChanger.INSTANCE) 17 | .attachNext(new StringValueChanger()) 18 | .attachNext(new UUIDValueChanger()) 19 | .attachNext(new BigDecimalValueChanger()) 20 | .attachNext(new BigIntegerValueChanger()); 21 | 22 | private DefaultFieldValueChanger() { 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/EnumValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field; 2 | 3 | 4 | class EnumValueChanger extends AbstractFieldValueChanger { 5 | 6 | @Override 7 | protected boolean canChange(final Class type) { 8 | return type.isEnum(); 9 | } 10 | 11 | @Override 12 | protected Enum increaseValue(final Enum value, final Class type) { 13 | if (value == null) { 14 | return firstValue(type); 15 | } else { 16 | return findDifferentValue(value, type); 17 | } 18 | } 19 | 20 | private Enum findDifferentValue(final Enum value, final Class type) { 21 | final Enum[] enumConstants = (Enum[]) type.getEnumConstants(); 22 | for (final Enum enumConstant : enumConstants) { 23 | if (areDifferentValues(value, enumConstant)) { 24 | return enumConstant; 25 | } 26 | } 27 | return null; 28 | } 29 | 30 | private Enum firstValue(final Class type) { 31 | final Object[] enumConstants = type.getEnumConstants(); 32 | if (enumConstants.length == 0) { 33 | throw new ImpossibleEnumValueChangeException(type); 34 | } 35 | return (Enum) enumConstants[0]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/ImpossibleEnumValueChangeException.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field; 2 | 3 | class ImpossibleEnumValueChangeException extends RuntimeException { 4 | 5 | ImpossibleEnumValueChangeException(final Class type) { 6 | super("Enum with type '" + type.getName() + "' has no enum constants. The only value of field with this type is null."); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/StringValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field; 2 | 3 | class StringValueChanger extends AbstractFieldValueChanger { 4 | 5 | @Override 6 | protected boolean canChange(final Class type) { 7 | return type.equals(String.class); 8 | } 9 | 10 | @Override 11 | protected String increaseValue(final String value, final Class type) { 12 | return value + "++increased"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/UUIDValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field; 2 | 3 | import java.util.UUID; 4 | 5 | class UUIDValueChanger extends AbstractFieldValueChanger { 6 | 7 | @Override 8 | protected boolean canChange(final Class type) { 9 | return type.equals(UUID.class); 10 | } 11 | 12 | @Override 13 | protected UUID increaseValue(final UUID value, final Class type) { 14 | UUID random; 15 | do { 16 | random = UUID.randomUUID(); 17 | } while (!areDifferentValues(value, random)); 18 | return random; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/ArrayValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.lang.reflect.Array; 6 | import java.util.Arrays; 7 | 8 | class ArrayValueChanger extends AbstractFieldValueChanger { 9 | 10 | @Override 11 | public boolean areDifferentValues(final Object sourceValue, final Object targetValue) { 12 | return !Arrays.deepEquals(new Object[]{ sourceValue }, new Object[]{ targetValue }); 13 | } 14 | 15 | @Override 16 | protected boolean canChange(final Class type) { 17 | return type.isArray(); 18 | } 19 | 20 | @Override 21 | protected Object increaseValue(final Object value, final Class type) { 22 | return value == null 23 | ? Array.newInstance(type.getComponentType(), 0) 24 | : null; 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/CollectionsFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections; 2 | 3 | 4 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 5 | import pl.pojo.tester.internal.field.collections.collection.AbstractCollectionFieldValueChanger; 6 | import pl.pojo.tester.internal.field.collections.iterators.AbstractIteratorsFieldValueChanger; 7 | import pl.pojo.tester.internal.field.collections.map.AbstractMapFieldValueChanger; 8 | 9 | public final class CollectionsFieldValueChanger { 10 | 11 | public static final AbstractFieldValueChanger INSTANCE = new ArrayValueChanger() 12 | .attachNext(new StreamValueChanger()) 13 | .attachNext(AbstractCollectionFieldValueChanger.INSTANCE) 14 | .attachNext(AbstractMapFieldValueChanger.INSTANCE) 15 | .attachNext(AbstractIteratorsFieldValueChanger.INSTANCE); 16 | 17 | private CollectionsFieldValueChanger() {} 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/StreamValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.util.Arrays; 6 | import java.util.stream.Stream; 7 | 8 | class StreamValueChanger extends AbstractFieldValueChanger> { 9 | 10 | @Override 11 | public boolean areDifferentValues(final Stream sourceValue, final Stream targetValue) { 12 | if (sourceValue == targetValue) { 13 | return false; 14 | } 15 | if (sourceValue == null || targetValue == null) { 16 | return true; 17 | } else { 18 | final Object[] sourceValuesArray = sourceValue.toArray(); 19 | final Object[] targetValuesArray = targetValue.toArray(); 20 | return !Arrays.deepEquals(sourceValuesArray, targetValuesArray); 21 | } 22 | } 23 | 24 | @Override 25 | protected boolean canChange(final Class type) { 26 | return type.isAssignableFrom(getGenericTypeClass()); 27 | } 28 | 29 | @Override 30 | protected Stream increaseValue(final Stream value, final Class type) { 31 | return value == null 32 | ? Stream.empty() 33 | : null; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/ArrayListValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.ArrayList; 6 | 7 | class ArrayListValueChanger extends AbstractCollectionFieldValueChanger> { 8 | 9 | @Override 10 | protected ArrayList increaseValue(final ArrayList value, final Class type) { 11 | return CollectionUtils.isNotEmpty(value) 12 | ? null 13 | : CollectionUtils.asList(new Object()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/DequeValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.Deque; 6 | import java.util.LinkedList; 7 | 8 | class DequeValueChanger extends AbstractCollectionFieldValueChanger> { 9 | 10 | @Override 11 | protected Deque increaseValue(final Deque value, final Class type) { 12 | return CollectionUtils.isNotEmpty(value) 13 | ? null 14 | : new LinkedList<>(CollectionUtils.asList(new Object())); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/HashSetValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.HashSet; 6 | 7 | class HashSetValueChanger extends AbstractCollectionFieldValueChanger> { 8 | 9 | 10 | @Override 11 | protected HashSet increaseValue(final HashSet value, final Class type) { 12 | return CollectionUtils.isNotEmpty(value) 13 | ? null 14 | : new HashSet<>(CollectionUtils.asList(new Object())); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/LinkedHashSetValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.LinkedHashSet; 6 | 7 | class LinkedHashSetValueChanger extends AbstractCollectionFieldValueChanger> { 8 | 9 | 10 | @Override 11 | protected LinkedHashSet increaseValue(final LinkedHashSet value, final Class type) { 12 | return CollectionUtils.isNotEmpty(value) 13 | ? null 14 | : new LinkedHashSet<>(CollectionUtils.asList(new Object())); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/LinkedListValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.LinkedList; 6 | 7 | 8 | class LinkedListValueChanger extends AbstractCollectionFieldValueChanger> { 9 | 10 | 11 | @Override 12 | protected LinkedList increaseValue(final LinkedList value, final Class type) { 13 | return CollectionUtils.isNotEmpty(value) 14 | ? null 15 | : new LinkedList<>(CollectionUtils.asList(new Object())); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/ListValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.List; 6 | 7 | class ListValueChanger extends AbstractCollectionFieldValueChanger> { 8 | 9 | @Override 10 | protected List increaseValue(final List value, final Class type) { 11 | return CollectionUtils.isNotEmpty(value) 12 | ? null 13 | : CollectionUtils.asList(new Object()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/QueueValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.LinkedList; 6 | import java.util.Queue; 7 | 8 | class QueueValueChanger extends AbstractCollectionFieldValueChanger> { 9 | 10 | @Override 11 | protected Queue increaseValue(final Queue value, final Class type) { 12 | return CollectionUtils.isNotEmpty(value) 13 | ? null 14 | : new LinkedList<>(CollectionUtils.asList(new Object())); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/SetValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | class SetValueChanger extends AbstractCollectionFieldValueChanger> { 9 | 10 | @Override 11 | protected Set increaseValue(final Set value, final Class type) { 12 | return CollectionUtils.isNotEmpty(value) 13 | ? null 14 | : new HashSet<>(CollectionUtils.asList(new Object())); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/SortedSetValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.SortedSet; 6 | import java.util.TreeSet; 7 | 8 | class SortedSetValueChanger extends AbstractCollectionFieldValueChanger> { 9 | 10 | @Override 11 | protected SortedSet increaseValue(final SortedSet value, final Class type) { 12 | return CollectionUtils.isNotEmpty(value) 13 | ? null 14 | : createTreeSet(); 15 | } 16 | 17 | private TreeSet createTreeSet() { 18 | final TreeSet objects = new TreeSet<>(); 19 | objects.add((Comparable) o -> 0); 20 | return objects; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/StackValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.Stack; 6 | 7 | class StackValueChanger extends AbstractCollectionFieldValueChanger> { 8 | 9 | @Override 10 | protected Stack increaseValue(final Stack value, final Class type) { 11 | return CollectionUtils.isNotEmpty(value) 12 | ? null 13 | : createStackWithOneElement(); 14 | } 15 | 16 | private Stack createStackWithOneElement() { 17 | final Stack objects = new Stack<>(); 18 | objects.add(new Object()); 19 | return objects; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/TreeSetValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.TreeSet; 6 | 7 | class TreeSetValueChanger extends AbstractCollectionFieldValueChanger> { 8 | 9 | @Override 10 | protected TreeSet increaseValue(final TreeSet value, final Class type) { 11 | return CollectionUtils.isNotEmpty(value) 12 | ? null 13 | : createTreeSet(); 14 | } 15 | 16 | private TreeSet createTreeSet() { 17 | final TreeSet objects = new TreeSet<>(); 18 | objects.add((Comparable) o -> 0); 19 | return objects; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/collection/VectorValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | import pl.pojo.tester.internal.utils.CollectionUtils; 4 | 5 | import java.util.Vector; 6 | 7 | class VectorValueChanger extends AbstractCollectionFieldValueChanger> { 8 | 9 | @Override 10 | protected Vector increaseValue(final Vector value, final Class type) { 11 | return CollectionUtils.isNotEmpty(value) 12 | ? null 13 | : new Vector<>(CollectionUtils.asList(new Object())); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/iterators/AbstractIteratorsFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.iterators; 2 | 3 | 4 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 5 | 6 | public abstract class AbstractIteratorsFieldValueChanger extends AbstractFieldValueChanger { 7 | 8 | public static final AbstractFieldValueChanger INSTANCE = new IteratorValueChanger().attachNext(new IterableValueChanger()); 9 | 10 | 11 | @Override 12 | protected boolean canChange(final Class type) { 13 | return type.isAssignableFrom(getGenericTypeClass()); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/iterators/IterableValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.iterators; 2 | 3 | 4 | import org.apache.commons.collections4.IteratorUtils; 5 | 6 | import java.util.Arrays; 7 | import java.util.Collections; 8 | 9 | class IterableValueChanger extends AbstractIteratorsFieldValueChanger> { 10 | 11 | @Override 12 | public boolean areDifferentValues(final Iterable sourceValue, final Iterable targetValue) { 13 | if (sourceValue == targetValue) { 14 | return false; 15 | } 16 | if (sourceValue == null || targetValue == null) { 17 | return true; 18 | } else { 19 | final Object[] sourceValuesArray = IteratorUtils.toArray(sourceValue.iterator()); 20 | final Object[] targetValuesArray = IteratorUtils.toArray(targetValue.iterator()); 21 | return !Arrays.deepEquals(sourceValuesArray, targetValuesArray); 22 | } 23 | } 24 | 25 | @Override 26 | protected Iterable increaseValue(final Iterable value, final Class type) { 27 | return value == null 28 | ? Collections.emptyList() 29 | : null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/iterators/IteratorValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.iterators; 2 | 3 | 4 | import org.apache.commons.collections4.IteratorUtils; 5 | 6 | import java.util.Arrays; 7 | import java.util.Collections; 8 | import java.util.Iterator; 9 | 10 | class IteratorValueChanger extends AbstractIteratorsFieldValueChanger> { 11 | 12 | 13 | @Override 14 | public boolean areDifferentValues(final Iterator sourceValue, final Iterator targetValue) { 15 | if (sourceValue == targetValue) { 16 | return false; 17 | } 18 | if (sourceValue == null || targetValue == null) { 19 | return true; 20 | } else { 21 | final Object[] sourceValuesArray = IteratorUtils.toArray(sourceValue); 22 | final Object[] targetValuesArray = IteratorUtils.toArray(targetValue); 23 | return !Arrays.deepEquals(sourceValuesArray, targetValuesArray); 24 | } 25 | } 26 | 27 | @Override 28 | protected Iterator increaseValue(final Iterator value, final Class type) { 29 | return value == null 30 | ? Collections.emptyList().iterator() 31 | : null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/map/AbstractMapFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | 4 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 5 | 6 | import java.util.Map; 7 | 8 | public abstract class AbstractMapFieldValueChanger extends AbstractFieldValueChanger { 9 | 10 | public static final AbstractFieldValueChanger INSTANCE = new HashMapValueChanger().attachNext(new HashtableValueChanger()) 11 | .attachNext(new LinkedHashMapValueChanger()) 12 | .attachNext(new MapValueChanger()) 13 | .attachNext(new SortedMapValueChanger()) 14 | .attachNext(new TreeMapValueChanger()); 15 | 16 | @Override 17 | protected boolean canChange(final Class type) { 18 | return type.isAssignableFrom(getGenericTypeClass()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/map/HashMapValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import java.util.HashMap; 4 | 5 | 6 | class HashMapValueChanger extends AbstractMapFieldValueChanger> { 7 | 8 | @Override 9 | protected HashMap increaseValue(final HashMap value, final Class type) { 10 | return value == null 11 | ? new HashMap<>() 12 | : null; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/map/HashtableValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import java.util.Hashtable; 4 | 5 | 6 | class HashtableValueChanger extends AbstractMapFieldValueChanger> { 7 | 8 | @Override 9 | protected Hashtable increaseValue(final Hashtable value, final Class type) { 10 | return value == null 11 | ? new Hashtable<>() 12 | : null; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/map/LinkedHashMapValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import java.util.LinkedHashMap; 4 | 5 | 6 | class LinkedHashMapValueChanger extends AbstractMapFieldValueChanger> { 7 | 8 | @Override 9 | protected LinkedHashMap increaseValue(final LinkedHashMap value, final Class type) { 10 | return value == null 11 | ? new LinkedHashMap<>() 12 | : null; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/map/MapValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import java.util.Collections; 4 | import java.util.Map; 5 | 6 | class MapValueChanger extends AbstractMapFieldValueChanger> { 7 | 8 | @Override 9 | protected Map increaseValue(final Map value, final Class type) { 10 | return value == null 11 | ? Collections.emptyMap() 12 | : null; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/map/SortedMapValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import java.util.SortedMap; 4 | import java.util.TreeMap; 5 | 6 | 7 | class SortedMapValueChanger extends AbstractMapFieldValueChanger> { 8 | 9 | @Override 10 | protected SortedMap increaseValue(final SortedMap value, final Class type) { 11 | return value == null 12 | ? new TreeMap<>() 13 | : null; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/collections/map/TreeMapValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import java.util.TreeMap; 4 | 5 | 6 | class TreeMapValueChanger extends AbstractMapFieldValueChanger> { 7 | 8 | @Override 9 | protected TreeMap increaseValue(final TreeMap value, final Class type) { 10 | return value == null 11 | ? new TreeMap<>() 12 | : null; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/date/DateFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.date; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.util.Date; 6 | 7 | class DateFieldValueChanger extends AbstractFieldValueChanger { 8 | 9 | @Override 10 | protected Date increaseValue(final Date value, final Class type) { 11 | return Date.from(value.toInstant().plusSeconds(100)); 12 | } 13 | 14 | @Override 15 | protected boolean canChange(final Class type) { 16 | return type.equals(Date.class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/date/DefaultDateAndTimeFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.date; 2 | 3 | 4 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 5 | 6 | public final class DefaultDateAndTimeFieldValueChanger { 7 | public static final AbstractFieldValueChanger INSTANCE = new ZonedDateTimeFieldValueChanger().attachNext(new DateFieldValueChanger()) 8 | .attachNext(new LocalDateFieldValueChanger()) 9 | .attachNext(new LocalDateTimeFieldValueChanger()) 10 | .attachNext(new LocalTimeFieldValueChanger()) 11 | .attachNext(new SqlDateFieldValueChanger()) 12 | .attachNext(new InstantFieldValueChanger()); 13 | 14 | private DefaultDateAndTimeFieldValueChanger() { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/date/InstantFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.date; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.time.Instant; 6 | 7 | class InstantFieldValueChanger extends AbstractFieldValueChanger { 8 | 9 | @Override 10 | protected Instant increaseValue(final Instant value, final Class type) { 11 | return value.plusSeconds(3600); 12 | } 13 | 14 | @Override 15 | protected boolean canChange(final Class type) { 16 | return type.equals(Instant.class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/date/LocalDateFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.date; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.time.LocalDate; 6 | 7 | class LocalDateFieldValueChanger extends AbstractFieldValueChanger { 8 | 9 | @Override 10 | protected LocalDate increaseValue(final LocalDate value, final Class type) { 11 | return value.plusDays(1); 12 | } 13 | 14 | @Override 15 | protected boolean canChange(final Class type) { 16 | return type.equals(LocalDate.class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/date/LocalDateTimeFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.date; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.time.LocalDateTime; 6 | 7 | class LocalDateTimeFieldValueChanger extends AbstractFieldValueChanger { 8 | 9 | @Override 10 | protected LocalDateTime increaseValue(final LocalDateTime value, final Class type) { 11 | return value.plusDays(1); 12 | } 13 | 14 | @Override 15 | protected boolean canChange(final Class type) { 16 | return type.equals(LocalDateTime.class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/date/LocalTimeFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.date; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.time.LocalTime; 6 | 7 | class LocalTimeFieldValueChanger extends AbstractFieldValueChanger { 8 | 9 | @Override 10 | protected LocalTime increaseValue(final LocalTime value, final Class type) { 11 | return value.plusHours(1); 12 | } 13 | 14 | @Override 15 | protected boolean canChange(final Class type) { 16 | return type.equals(LocalTime.class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/date/SqlDateFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.date; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.sql.Date; 6 | 7 | class SqlDateFieldValueChanger extends AbstractFieldValueChanger { 8 | 9 | @Override 10 | protected Date increaseValue(final Date value, final Class type) { 11 | return new Date(value.getTime() + 1000); 12 | } 13 | 14 | @Override 15 | protected boolean canChange(final Class type) { 16 | return type.equals(Date.class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/date/ZonedDateTimeFieldValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.date; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.time.ZonedDateTime; 6 | 7 | class ZonedDateTimeFieldValueChanger extends AbstractFieldValueChanger { 8 | 9 | @Override 10 | protected ZonedDateTime increaseValue(final ZonedDateTime value, final Class type) { 11 | return value.plusDays(1); 12 | } 13 | 14 | @Override 15 | protected boolean canChange(final Class type) { 16 | return type.equals(ZonedDateTime.class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/math/BigDecimalValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.math; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.math.BigDecimal; 6 | 7 | 8 | public class BigDecimalValueChanger extends AbstractFieldValueChanger { 9 | 10 | @Override 11 | protected BigDecimal increaseValue(final BigDecimal value, final Class type) { 12 | return value.add(BigDecimal.ONE); 13 | } 14 | 15 | @Override 16 | protected boolean canChange(final Class type) { 17 | return type.equals(BigDecimal.class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/math/BigIntegerValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.math; 2 | 3 | import pl.pojo.tester.internal.field.AbstractFieldValueChanger; 4 | 5 | import java.math.BigInteger; 6 | 7 | 8 | public class BigIntegerValueChanger extends AbstractFieldValueChanger { 9 | 10 | @Override 11 | protected BigInteger increaseValue(final BigInteger value, final Class type) { 12 | return value.add(BigInteger.ONE); 13 | } 14 | 15 | @Override 16 | protected boolean canChange(final Class type) { 17 | return type.equals(BigInteger.class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/primitive/BooleanValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.primitive; 2 | 3 | class BooleanValueChanger extends AbstractPrimitiveValueChanger { 4 | 5 | @Override 6 | protected Boolean increase(final Boolean value) { 7 | return !value; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/primitive/ByteValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.primitive; 2 | 3 | 4 | class ByteValueChanger extends AbstractPrimitiveValueChanger { 5 | 6 | @Override 7 | protected Byte increase(final Byte value) { 8 | return (byte) (value + 1); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/primitive/CharacterValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.primitive; 2 | 3 | class CharacterValueChanger extends AbstractPrimitiveValueChanger { 4 | 5 | @Override 6 | protected Character increase(final Character value) { 7 | return (char) (value + 1); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/primitive/DoubleValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.primitive; 2 | 3 | 4 | class DoubleValueChanger extends AbstractPrimitiveValueChanger { 5 | 6 | @Override 7 | protected Double increase(final Double value) { 8 | return 2 * (value + 1); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/primitive/FloatValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.primitive; 2 | 3 | 4 | class FloatValueChanger extends AbstractPrimitiveValueChanger { 5 | 6 | @Override 7 | protected Float increase(final Float value) { 8 | return 2 * (value + 1); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/primitive/IntegerValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.primitive; 2 | 3 | class IntegerValueChanger extends AbstractPrimitiveValueChanger { 4 | 5 | @Override 6 | protected Integer increase(final Integer value) { 7 | return value + 1; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/primitive/LongValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.primitive; 2 | 3 | 4 | class LongValueChanger extends AbstractPrimitiveValueChanger { 5 | 6 | @Override 7 | protected Long increase(final Long value) { 8 | return value + 1; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/field/primitive/ShortValueChanger.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.primitive; 2 | 3 | 4 | class ShortValueChanger extends AbstractPrimitiveValueChanger { 5 | 6 | @Override 7 | protected Short increase(final Short value) { 8 | return (short) (value + 1); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/instantiator/AbstractObjectInstantiator.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.instantiator; 2 | 3 | import org.apache.commons.collections4.MultiValuedMap; 4 | import pl.pojo.tester.api.ConstructorParameters; 5 | 6 | abstract class AbstractObjectInstantiator { 7 | 8 | protected final Class clazz; 9 | protected final MultiValuedMap, ConstructorParameters> constructorParameters; 10 | 11 | AbstractObjectInstantiator(final Class clazz, 12 | final MultiValuedMap, ConstructorParameters> constructorParameters) { 13 | this.clazz = clazz; 14 | this.constructorParameters = constructorParameters; 15 | } 16 | 17 | public abstract Object instantiate(); 18 | 19 | public abstract boolean canInstantiate(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/instantiator/ArrayInstantiator.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.instantiator; 2 | 3 | import org.apache.commons.collections4.MultiValuedMap; 4 | import pl.pojo.tester.api.ConstructorParameters; 5 | 6 | import java.lang.reflect.Array; 7 | 8 | class ArrayInstantiator extends AbstractObjectInstantiator { 9 | 10 | private static final int DEFAULT_ARRAY_LENGTH = 0; 11 | 12 | ArrayInstantiator(final Class clazz, 13 | final MultiValuedMap, ConstructorParameters> constructorParameters) { 14 | super(clazz, constructorParameters); 15 | } 16 | 17 | @Override 18 | public Object instantiate() { 19 | return Array.newInstance(clazz.getComponentType(), DEFAULT_ARRAY_LENGTH); 20 | } 21 | 22 | @Override 23 | public boolean canInstantiate() { 24 | return clazz.isArray(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/instantiator/EnumInstantiator.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.instantiator; 2 | 3 | 4 | import org.apache.commons.collections4.MultiValuedMap; 5 | import pl.pojo.tester.api.ConstructorParameters; 6 | 7 | import java.util.Random; 8 | 9 | class EnumInstantiator extends AbstractObjectInstantiator { 10 | 11 | EnumInstantiator(final Class clazz, 12 | final MultiValuedMap, ConstructorParameters> constructorParameters) { 13 | super(clazz, constructorParameters); 14 | } 15 | 16 | @Override 17 | public Object instantiate() { 18 | final Object[] enumConstants = clazz.getEnumConstants(); 19 | final int length = enumConstants.length; 20 | 21 | if (length != 0) { 22 | final int random = new Random().nextInt(length); 23 | return enumConstants[random]; 24 | } 25 | return null; 26 | } 27 | 28 | @Override 29 | public boolean canInstantiate() { 30 | return clazz.isEnum(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/instantiator/ObjectInstantiationException.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.instantiator; 2 | 3 | 4 | import java.util.Arrays; 5 | 6 | class ObjectInstantiationException extends RuntimeException { 7 | 8 | ObjectInstantiationException(final Class clazz, final String message, final Throwable cause) { 9 | super(createMessage(clazz) + " " + message, cause); 10 | } 11 | 12 | ObjectInstantiationException(final Class clazz, final String message) { 13 | this(clazz, message, null); 14 | } 15 | 16 | public ObjectInstantiationException(final Class clazz, 17 | final String message, 18 | final Class[] parameterTypes, 19 | final Object[] parameters, 20 | final Throwable cause) { 21 | this(clazz, message + " " + createMessage(parameterTypes, parameters), cause); 22 | } 23 | 24 | private static String createMessage(final Class clazz) { 25 | return "Unable to create object for class: " + clazz; 26 | } 27 | 28 | private static String createMessage(final Class[] parameterTypes, final Object[] parameters) { 29 | return "Parameter types are " 30 | + Arrays.toString(parameterTypes) 31 | + " and parameters are " 32 | + Arrays.toString(parameters); 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/preconditions/BlankParameterException.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.preconditions; 2 | 3 | public class BlankParameterException extends RuntimeException { 4 | public BlankParameterException(final String parameterName, final String parameterValue) { 5 | super(createMessage(parameterName, parameterValue)); 6 | } 7 | 8 | private static String createMessage(final String parameterName, final String parameterValue) { 9 | return String.format("Parameter '%s' is blank. It's value is '%s'", parameterName, parameterValue); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/preconditions/NullParameterException.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.preconditions; 2 | 3 | public class NullParameterException extends RuntimeException { 4 | 5 | public NullParameterException(final String parameterName) { 6 | super(createMessage(parameterName)); 7 | } 8 | 9 | private static String createMessage(final String parameterName) { 10 | return String.format("Parameter '%s' has null value.", parameterName); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/preconditions/ParameterPreconditions.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.preconditions; 2 | 3 | import java.util.Arrays; 4 | 5 | public final class ParameterPreconditions { 6 | 7 | private ParameterPreconditions() {} 8 | 9 | public static void checkNotBlank(final String parameterName, final String parameterValue) { 10 | checkNotNull(parameterName, parameterValue); 11 | if (hasZeroLength(parameterValue)) { 12 | throw new BlankParameterException(parameterName, parameterValue); 13 | } 14 | } 15 | 16 | public static void checkNotBlank(final String parameterName, final String[] parameterValue) { 17 | Arrays.stream(parameterValue) 18 | .forEach(each -> checkNotBlank(parameterName, each)); 19 | } 20 | 21 | public static void checkNotNull(final String parameterName, final Object parameterValue) { 22 | if (parameterValue == null) { 23 | throw new NullParameterException(parameterName); 24 | } 25 | } 26 | 27 | public static void checkNotNull(final String parameterName, final Object[] parameterValue) { 28 | Arrays.stream(parameterValue) 29 | .forEach(each -> checkNotNull(parameterName, each)); 30 | } 31 | 32 | private static boolean hasZeroLength(final String parameterValue) { 33 | return parameterValue.trim() 34 | .length() == 0; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/utils/ClassLoader.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | public final class ClassLoader { 4 | 5 | private ClassLoader() { 6 | } 7 | 8 | public static Class loadClass(final String qualifiedClassName) { 9 | try { 10 | return Class.forName(qualifiedClassName); 11 | } catch (final ClassNotFoundException e) { 12 | throw new ClassLoadingException(qualifiedClassName, e); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/utils/ClassLoadingException.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | class ClassLoadingException extends RuntimeException { 4 | 5 | ClassLoadingException(final String qualifiedClassName, final ClassNotFoundException cause) { 6 | super(createMessage(qualifiedClassName), cause); 7 | } 8 | 9 | private static String createMessage(final String qualifiedClassName) { 10 | return String.format("Unable to load class %s", qualifiedClassName); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/utils/CollectionUtils.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | 4 | import java.util.*; 5 | 6 | public class CollectionUtils { 7 | 8 | private CollectionUtils() { 9 | } 10 | 11 | public static boolean isNotEmpty(final Collection collection) { 12 | return !isEmpty(collection); 13 | } 14 | 15 | static boolean isEmpty(final Collection collection) { 16 | return collection == null || collection.isEmpty(); 17 | } 18 | 19 | public static ArrayList asList(final T... elements) { 20 | final ArrayList list = new ArrayList<>(elements.length); 21 | Collections.addAll(list, elements); 22 | return list; 23 | } 24 | 25 | public static Set asSet(final T... elements) { 26 | final HashSet list = new HashSet<>(elements.length); 27 | Collections.addAll(list, elements); 28 | return list; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/utils/GetterNotFoundException.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | 6 | public class GetterNotFoundException extends RuntimeException { 7 | 8 | GetterNotFoundException(final Class clazz, final Field field) { 9 | super(String.format("Class %s has no getter for field %s", clazz.getCanonicalName(), field)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/utils/Permutator.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.List; 5 | 6 | public interface Permutator { 7 | 8 | List> permute(final List elements); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/utils/SetterNotFoundException.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | public class SetterNotFoundException extends RuntimeException { 6 | 7 | SetterNotFoundException(final Class clazz, final Field field) { 8 | super(String.format("Class %s has no setter for field %s", clazz.getCanonicalName(), field)); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/utils/SublistFieldPermutator.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.List; 5 | 6 | public class SublistFieldPermutator implements Permutator { 7 | 8 | @Override 9 | public List> permute(final List elements) { 10 | return Sublists.subsequences(elements); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/utils/Sublists.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public final class Sublists { 8 | 9 | private Sublists() { 10 | } 11 | 12 | /** 13 | * Given a list of objects, return a list of sublists, i-th sublist includes i-th element of 14 | * the original list and all elements that follow it in the original list. 15 | * All returned lists are read-only and backed by a copy of the original list, so later changes 16 | * in the original list will not affect the returned sublists. 17 | * 18 | * @param list list of objects 19 | * @param the type of list element 20 | * @return sublists of list 21 | */ 22 | public static List> subsequences(final List list) { 23 | final List copyOfList = new ArrayList<>(list); 24 | final List> result = new ArrayList<>(); 25 | for (int i = 0; i < copyOfList.size(); i++) { 26 | result.add(Collections.unmodifiableList(copyOfList.subList(i, copyOfList.size()))); 27 | } 28 | return Collections.unmodifiableList(result); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/pl/pojo/tester/internal/utils/ThoroughFieldPermutator.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.List; 5 | 6 | public class ThoroughFieldPermutator implements Permutator { 7 | 8 | @Override 9 | public List> permute(final List elements) { 10 | return FieldUtils.permutations(elements); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, stdout 3 | # Direct log messages to stdout 4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.Target=System.out 6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n -------------------------------------------------------------------------------- /src/test/java/classesForTest/Abstract.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | public abstract class Abstract { 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/Abstract_PrivateConstructor.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | public abstract class Abstract_PrivateConstructor { 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/Annotation.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | public @interface Annotation { 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/ClassContainingStaticClasses.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | public class ClassContainingStaticClasses { 5 | 6 | public static class NestedStaticClass_PublicConstructor { 7 | public NestedStaticClass_PublicConstructor() { 8 | } 9 | } 10 | 11 | public static class NestedStaticClass_PackageConstructor { 12 | NestedStaticClass_PackageConstructor() { 13 | } 14 | } 15 | 16 | public static class NestedStaticClass_ProtectedConstructor { 17 | protected NestedStaticClass_ProtectedConstructor() { 18 | } 19 | } 20 | 21 | public static class NestedStaticClass_PrivateConstructor { 22 | private NestedStaticClass_PrivateConstructor() { 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/ClassContainingUnpublicClasses.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | class ClassContainingUnpublicClasses { 5 | 6 | private class Package_PublicConstructor { 7 | public Package_PublicConstructor() { 8 | } 9 | } 10 | 11 | private class Package_PackageConstructor { 12 | Package_PackageConstructor() { 13 | } 14 | } 15 | 16 | private class Package_ProtectedConstructor { 17 | protected Package_ProtectedConstructor() { 18 | } 19 | } 20 | 21 | private class Package_PrivateConstructor { 22 | private Package_PrivateConstructor() { 23 | } 24 | } 25 | 26 | private class Protected_PublicConstructor { 27 | public Protected_PublicConstructor() { 28 | } 29 | } 30 | 31 | private class Protected_PackageConstructor { 32 | Protected_PackageConstructor() { 33 | } 34 | } 35 | 36 | private class Protected_ProtectedConstructor { 37 | protected Protected_ProtectedConstructor() { 38 | } 39 | } 40 | 41 | private class Protected_PrivateConstructor { 42 | private Protected_PrivateConstructor() { 43 | } 44 | } 45 | 46 | private class Private_PublicConstructor { 47 | public Private_PublicConstructor() { 48 | } 49 | } 50 | 51 | private class Private_PackageConstructor { 52 | Private_PackageConstructor() { 53 | } 54 | } 55 | 56 | private class Private_ProtectedConstructor { 57 | protected Private_ProtectedConstructor() { 58 | } 59 | } 60 | 61 | private class Private_PrivateConstructor { 62 | private Private_PrivateConstructor() { 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/ClassWithSyntheticConstructor.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | public class ClassWithSyntheticConstructor { 5 | 6 | private ClassWithSyntheticConstructor(final String parameter) { 7 | } 8 | 9 | private static class Builder { 10 | 11 | public ClassWithSyntheticConstructor build() { 12 | return new ClassWithSyntheticConstructor("test"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/Constructor_Field.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | import java.lang.reflect.Field; 5 | 6 | public class Constructor_Field { 7 | 8 | private final Field field; 9 | 10 | public Constructor_Field(final Field field) { 11 | this.field = field; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/Constructor_Stream.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | import java.util.stream.Stream; 5 | 6 | public class Constructor_Stream { 7 | 8 | private final Stream stream; 9 | 10 | public Constructor_Stream(final Stream stream) { 11 | this.stream = stream; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/Constructor_Thread.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | public class Constructor_Thread { 4 | 5 | private final Thread thread; 6 | 7 | public Constructor_Thread(final Thread thread) { 8 | this.thread = thread; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/Constructors_First_Throws_Exception.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | public class Constructors_First_Throws_Exception { 4 | private Constructors_First_Throws_Exception() { 5 | throw new NullPointerException("test"); 6 | } 7 | 8 | private Constructors_First_Throws_Exception(final Object o) { } 9 | } -------------------------------------------------------------------------------- /src/test/java/classesForTest/EmptyEnum.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | public enum EmptyEnum { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/Interface.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | public interface Interface { 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/ObjectContainingArray.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | import org.apache.commons.lang3.builder.EqualsBuilder; 4 | import org.apache.commons.lang3.builder.HashCodeBuilder; 5 | import org.apache.commons.lang3.builder.ToStringBuilder; 6 | 7 | public class ObjectContainingArray { 8 | 9 | private int[] array; 10 | 11 | @Override 12 | public boolean equals(final Object o) { 13 | if (this == o) { 14 | return true; 15 | } 16 | 17 | if (o == null || getClass() != o.getClass()) { 18 | return false; 19 | } 20 | 21 | final ObjectContainingArray that = (ObjectContainingArray) o; 22 | 23 | return new EqualsBuilder().append(array, that.array) 24 | .isEquals(); 25 | } 26 | 27 | @Override 28 | public int hashCode() { 29 | return new HashCodeBuilder().append(array) 30 | .toHashCode(); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return new ToStringBuilder(this) 36 | .append("array", array) 37 | .toString(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/ObjectContainingIterable.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | import org.apache.commons.lang3.builder.EqualsBuilder; 4 | import org.apache.commons.lang3.builder.HashCodeBuilder; 5 | import org.apache.commons.lang3.builder.ToStringBuilder; 6 | 7 | public class ObjectContainingIterable { 8 | 9 | private Iterable iterable; 10 | 11 | @Override 12 | public boolean equals(final Object o) { 13 | if (this == o) { 14 | return true; 15 | } 16 | 17 | if (o == null || getClass() != o.getClass()) { 18 | return false; 19 | } 20 | 21 | final ObjectContainingIterable that = (ObjectContainingIterable) o; 22 | 23 | return new EqualsBuilder().append(iterable, that.iterable) 24 | .isEquals(); 25 | } 26 | 27 | @Override 28 | public int hashCode() { 29 | return new HashCodeBuilder().append(iterable) 30 | .toHashCode(); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return new ToStringBuilder(this) 36 | .append("iterable", iterable) 37 | .toString(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/ObjectContainingIterator.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | import java.util.Iterator; 4 | import org.apache.commons.lang3.builder.EqualsBuilder; 5 | import org.apache.commons.lang3.builder.HashCodeBuilder; 6 | import org.apache.commons.lang3.builder.ToStringBuilder; 7 | 8 | 9 | public class ObjectContainingIterator { 10 | 11 | private Iterator iterator; 12 | 13 | @Override 14 | public boolean equals(final Object o) { 15 | if (this == o) { 16 | return true; 17 | } 18 | 19 | if (o == null || getClass() != o.getClass()) { 20 | return false; 21 | } 22 | 23 | final ObjectContainingIterator that = (ObjectContainingIterator) o; 24 | 25 | return new EqualsBuilder().append(iterator, that.iterator) 26 | .isEquals(); 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | return new HashCodeBuilder().append(iterator) 32 | .toHashCode(); 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return new ToStringBuilder(this) 38 | .append("iterator", iterator) 39 | .toString(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/ObjectContainingList.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | import org.apache.commons.lang3.builder.EqualsBuilder; 4 | import org.apache.commons.lang3.builder.HashCodeBuilder; 5 | import org.apache.commons.lang3.builder.ToStringBuilder; 6 | 7 | import java.util.List; 8 | 9 | 10 | class ObjectContainingList { 11 | 12 | private List list; 13 | 14 | @Override 15 | public boolean equals(final Object o) { 16 | if (this == o) { 17 | return true; 18 | } 19 | 20 | if (o == null || getClass() != o.getClass()) { 21 | return false; 22 | } 23 | 24 | final ObjectContainingList that = (ObjectContainingList) o; 25 | 26 | return new EqualsBuilder().append(list, that.list) 27 | .isEquals(); 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | return new HashCodeBuilder().append(list) 33 | .toHashCode(); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return new ToStringBuilder(this) 39 | .append("list", list) 40 | .toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/ObjectContainingStream.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | import java.util.stream.Stream; 4 | import org.apache.commons.lang3.builder.EqualsBuilder; 5 | import org.apache.commons.lang3.builder.HashCodeBuilder; 6 | import org.apache.commons.lang3.builder.ToStringBuilder; 7 | 8 | 9 | public class ObjectContainingStream { 10 | 11 | private Stream stream; 12 | 13 | @Override 14 | public boolean equals(final Object o) { 15 | if (this == o) { 16 | return true; 17 | } 18 | 19 | if (o == null || getClass() != o.getClass()) { 20 | return false; 21 | } 22 | 23 | final ObjectContainingStream that = (ObjectContainingStream) o; 24 | 25 | return new EqualsBuilder().append(stream, that.stream) 26 | .isEquals(); 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | return new HashCodeBuilder().append(stream) 32 | .toHashCode(); 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return new ToStringBuilder(this) 38 | .append("stream", stream) 39 | .toString(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/PackageConstructor.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | public class PackageConstructor { 5 | 6 | private int a; 7 | private int b; 8 | private int c; 9 | private Object object; 10 | 11 | PackageConstructor() { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/Person.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | import java.util.UUID; 4 | import org.apache.commons.lang3.builder.EqualsBuilder; 5 | import org.apache.commons.lang3.builder.HashCodeBuilder; 6 | 7 | public class Person { 8 | 9 | private final UUID id; 10 | private final String name; 11 | 12 | private Person(final String name) { 13 | this.id = UUID.randomUUID(); 14 | this.name = name; 15 | } 16 | 17 | @Override 18 | public boolean equals(final Object obj) { 19 | if (this == obj) { 20 | return true; 21 | } 22 | 23 | if (obj == null || getClass() != obj.getClass()) { 24 | return false; 25 | } 26 | 27 | final Person person = (Person) obj; 28 | 29 | return new EqualsBuilder().append(id, person.id) 30 | .isEquals(); 31 | } 32 | 33 | @Override 34 | public int hashCode() { 35 | return new HashCodeBuilder().append(id) 36 | .toHashCode(); 37 | } 38 | 39 | public static class PersonBuilder { 40 | 41 | private String name; 42 | 43 | public PersonBuilder setName(final String name) { 44 | this.name = name; 45 | return this; 46 | } 47 | 48 | public Person build() { 49 | return new Person(name); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/PrivateConstructor.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | public class PrivateConstructor { 5 | 6 | private int a; 7 | private int b; 8 | private int c; 9 | private Object object; 10 | 11 | private PrivateConstructor() { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/ProtectedConstructor.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | 4 | public class ProtectedConstructor { 5 | 6 | private int a; 7 | private int b; 8 | private int c; 9 | private Object object; 10 | 11 | private ProtectedConstructor() { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/UnpublicClass.java: -------------------------------------------------------------------------------- 1 | package classesForTest; 2 | 3 | class UnpublicClass { 4 | final static private class PrivateStaticFinalNestedClass { 5 | final static private class PrivateStaticFinalNestedClass2 { 6 | } 7 | } 8 | 9 | private final static class ProtectedStaticFinalNestedClass { 10 | } 11 | 12 | private final static class PackageStaticFinalNestedClass { 13 | } 14 | 15 | private final static class PublicStaticFinalNestedClass { 16 | } 17 | 18 | static private class PrivateStaticNestedClass { 19 | } 20 | 21 | private static class ProtectedStaticNestedClass { 22 | } 23 | 24 | private static class PackageStaticNestedClass { 25 | } 26 | 27 | private static class PublicStaticNestedClass { 28 | } 29 | 30 | final private class PrivateFinalNestedClass { 31 | } 32 | 33 | private final class ProtectedFinalNestedClass { 34 | } 35 | 36 | private final class PackageFinalNestedClass { 37 | } 38 | 39 | private final class PublicFinalNestedClass { 40 | } 41 | 42 | private class PrivateNestedClass { 43 | } 44 | 45 | private class ProtectedNestedClass { 46 | } 47 | 48 | private class PackageNestedClass { 49 | } 50 | 51 | private class PublicNestedClass { 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/AllFiledTypes_Wrapped.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields; 2 | 3 | 4 | public class AllFiledTypes_Wrapped { 5 | private final Integer finalIntType = 0; 6 | private Byte byteType; 7 | private Short shortType; 8 | private Integer intType; 9 | private Long longType; 10 | private Double doubleType; 11 | private Boolean booleanType; 12 | private Character characterType; 13 | private Float floatType; 14 | 15 | public AllFiledTypes_Wrapped(final Byte byteType) { 16 | this.byteType = byteType; 17 | } 18 | 19 | public AllFiledTypes_Wrapped(final Float floatType) { 20 | this.floatType = floatType; 21 | } 22 | 23 | public AllFiledTypes_Wrapped(final Character characterType) { 24 | this.characterType = characterType; 25 | } 26 | 27 | public AllFiledTypes_Wrapped(final Boolean booleanType) { 28 | this.booleanType = booleanType; 29 | } 30 | 31 | public AllFiledTypes_Wrapped(final Double doubleType) { 32 | this.doubleType = doubleType; 33 | } 34 | 35 | public AllFiledTypes_Wrapped(final Long longType) { 36 | this.longType = longType; 37 | } 38 | 39 | public AllFiledTypes_Wrapped(final Integer intType) { 40 | this.intType = intType; 41 | } 42 | 43 | public AllFiledTypes_Wrapped(final Short shortType) { 44 | this.shortType = shortType; 45 | } 46 | 47 | public AllFiledTypes_Wrapped() { 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/ClassContainingArrays.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields; 2 | 3 | 4 | public class ClassContainingArrays { 5 | 6 | private final Object[] a_object = new Object[1]; 7 | private int[] a_int; 8 | private char[] a_char; 9 | private float[] a_float; 10 | private double[] a_double; 11 | private boolean[] a_boolean; 12 | private byte[] a_byte; 13 | private short[] a_short; 14 | private long[] a_long; 15 | private Integer[] a_Int; 16 | private Character[] a_Char; 17 | private Float[] a_Float; 18 | private Double[] a_Double; 19 | private Boolean[] a_Boolean; 20 | private Byte[] a_Byte; 21 | private Short[] a_Short; 22 | private Long[] a_Long; 23 | private Object[] a_object_null; 24 | private A a; 25 | private A[] a_a; 26 | 27 | private class A {} 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/ClassContainingStream.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields; 2 | 3 | 4 | import java.util.stream.Stream; 5 | 6 | public class ClassContainingStream { 7 | 8 | private final Stream stream_Integer = Stream.of(1); 9 | private Stream stream_String; 10 | private Stream stream_Object; 11 | private Stream stream_A; 12 | private Stream stream; 13 | private A a; 14 | 15 | private class A {} 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/ClassWithAllAvailableFieldModifiers.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields; 2 | 3 | 4 | public class ClassWithAllAvailableFieldModifiers { 5 | 6 | final static public int m = 1; 7 | final static protected int n = 1; 8 | final static int o = 1; 9 | final static private int p = 1; 10 | 11 | static public int i; 12 | static protected int j; 13 | static int k; 14 | static private int l; 15 | 16 | final public int e = 1; 17 | final protected int f = 1; 18 | final int g = 1; 19 | final private int h = 1; 20 | 21 | public int a; 22 | protected int b; 23 | int c; 24 | private int d; 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/EnumFields.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields; 2 | 3 | public class EnumFields { 4 | 5 | private final TestEnum1 nullEnum = null; 6 | private final SingleEnum singleEnum1 = SingleEnum.ENUM1; 7 | private final SingleEnum singleEnum2 = null; 8 | private TestEnum1 testEnum1 = TestEnum1.ENUM1; 9 | private Object object; 10 | 11 | public EnumFields(final TestEnum1 testEnum1) { 12 | this.testEnum1 = testEnum1; 13 | } 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/EnumWithoutConstants.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields; 2 | 3 | public enum EnumWithoutConstants { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/Permutation1.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields; 2 | 3 | 4 | public class Permutation1 { 5 | 6 | private int a; 7 | private int b; 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/Permutation2.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields; 2 | 3 | 4 | public class Permutation2 { 5 | 6 | private int a; 7 | private int b; 8 | private int c; 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/SingleEnum.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields; 2 | 3 | public enum SingleEnum { 4 | ENUM1 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/TestEnum1.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields; 2 | 3 | public enum TestEnum1 { 4 | ENUM1, 5 | ENUM2, 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/collections/collection/Collections.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields.collections.collection; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.Deque; 6 | import java.util.HashSet; 7 | import java.util.LinkedHashSet; 8 | import java.util.LinkedList; 9 | import java.util.List; 10 | import java.util.Queue; 11 | import java.util.Set; 12 | import java.util.SortedSet; 13 | import java.util.Stack; 14 | import java.util.TreeSet; 15 | import java.util.Vector; 16 | 17 | public class Collections { 18 | 19 | private ArrayList arrayList; 20 | private Deque deque; 21 | private HashSet hashSet; 22 | private LinkedHashSet linkedHashSet; 23 | private LinkedList linkedList; 24 | private List list; 25 | private Queue queue; 26 | private Set set; 27 | private SortedSet sortedSet; 28 | private Stack stack; 29 | private TreeSet treeSet; 30 | private Vector vector; 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/collections/iterators/Iterators.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields.collections.iterators; 2 | 3 | 4 | import java.util.Iterator; 5 | 6 | public class Iterators { 7 | 8 | Iterator iterator; 9 | Iterable iterable; 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/fields/collections/map/Maps.java: -------------------------------------------------------------------------------- 1 | package classesForTest.fields.collections.map; 2 | 3 | 4 | import java.util.HashMap; 5 | import java.util.Hashtable; 6 | import java.util.LinkedHashMap; 7 | import java.util.Map; 8 | import java.util.SortedMap; 9 | import java.util.TreeMap; 10 | 11 | public class Maps { 12 | 13 | Hashtable hashtable; 14 | LinkedHashMap linkedHashMap; 15 | Map map; 16 | SortedMap sortedMap; 17 | TreeMap treeMap; 18 | HashMap hashMap; 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/packageFilter/A.java: -------------------------------------------------------------------------------- 1 | package classesForTest.packageFilter; 2 | 3 | 4 | public class A { 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/packageFilter/B.java: -------------------------------------------------------------------------------- 1 | package classesForTest.packageFilter; 2 | 3 | 4 | public class B { 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/packageFilter/C.java: -------------------------------------------------------------------------------- 1 | package classesForTest.packageFilter; 2 | 3 | 4 | public class C { 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/packageFilter/next/D.java: -------------------------------------------------------------------------------- 1 | package classesForTest.packageFilter.next; 2 | 3 | 4 | public class D { 5 | 6 | private int d; 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/packageFilter/next/E.java: -------------------------------------------------------------------------------- 1 | package classesForTest.packageFilter.next; 2 | 3 | 4 | public class E { 5 | 6 | private int e; 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/packageFilter/next/notAClass: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sta-szek/pojo-tester/0860ba76af2e675e1143f6060fe3192c05d69be5/src/test/java/classesForTest/packageFilter/next/notAClass -------------------------------------------------------------------------------- /src/test/java/classesForTest/permutator/A.java: -------------------------------------------------------------------------------- 1 | package classesForTest.permutator; 2 | 3 | public class A { 4 | private int a; 5 | private int b; 6 | } 7 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/reflectionUtils/base/AExtendsBase.java: -------------------------------------------------------------------------------- 1 | package classesForTest.reflectionUtils.base; 2 | 3 | public class AExtendsBase extends Base { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/reflectionUtils/base/BExtendsBase.java: -------------------------------------------------------------------------------- 1 | package classesForTest.reflectionUtils.base; 2 | 3 | public class BExtendsBase extends Base { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/reflectionUtils/base/Base.java: -------------------------------------------------------------------------------- 1 | package classesForTest.reflectionUtils.base; 2 | 3 | public class Base { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/reflectionUtils/base/CNotExtendsBase.java: -------------------------------------------------------------------------------- 1 | package classesForTest.reflectionUtils.base; 2 | 3 | public class CNotExtendsBase { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/reflectionUtils/next/D.java: -------------------------------------------------------------------------------- 1 | package classesForTest.reflectionUtils.next; 2 | 3 | 4 | public class D { 5 | 6 | private int d; 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/reflectionUtils/next/E.java: -------------------------------------------------------------------------------- 1 | package classesForTest.reflectionUtils.next; 2 | 3 | 4 | public class E { 5 | 6 | private int e; 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/classesForTest/reflectionUtils/next/notAClass: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sta-szek/pojo-tester/0860ba76af2e675e1143f6060fe3192c05d69be5/src/test/java/classesForTest/reflectionUtils/next/notAClass -------------------------------------------------------------------------------- /src/test/java/helpers/ClassAndFieldPredicatePairArgumentMatcher.java: -------------------------------------------------------------------------------- 1 | package helpers; 2 | 3 | import org.mockito.ArgumentMatcher; 4 | import pl.pojo.tester.api.ClassAndFieldPredicatePair; 5 | 6 | public class ClassAndFieldPredicatePairArgumentMatcher implements ArgumentMatcher { 7 | private final Class clazz; 8 | private final String fieldName; 9 | 10 | public ClassAndFieldPredicatePairArgumentMatcher(final Class clazz, final String fieldName) { 11 | this.clazz = clazz; 12 | this.fieldName = fieldName; 13 | } 14 | 15 | @Override 16 | public boolean matches(final ClassAndFieldPredicatePair argument) { 17 | final boolean classesMatches = argument.getClazz() 18 | .equals(clazz); 19 | 20 | final boolean predicateMatches = argument.getFieldsPredicate() 21 | .test(fieldName); 22 | return classesMatches && predicateMatches; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/helpers/ClassNameAndFieldPredicatePairArgumentMatcher.java: -------------------------------------------------------------------------------- 1 | package helpers; 2 | 3 | import org.mockito.ArgumentMatcher; 4 | import pl.pojo.tester.api.ClassAndFieldPredicatePair; 5 | 6 | class ClassNameAndFieldPredicatePairArgumentMatcher implements ArgumentMatcher { 7 | private final String className; 8 | private final String fieldName; 9 | 10 | public ClassNameAndFieldPredicatePairArgumentMatcher(final String className, final String fieldName) { 11 | this.className = className; 12 | this.fieldName = fieldName; 13 | } 14 | 15 | @Override 16 | public boolean matches(final ClassAndFieldPredicatePair argument) { 17 | final boolean classesMatches = argument.getClazz() 18 | .getName() 19 | .equals(className); 20 | 21 | final boolean predicateMatches = argument.getFieldsPredicate() 22 | .test(fieldName); 23 | return classesMatches && predicateMatches; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/helpers/MapMatcher.java: -------------------------------------------------------------------------------- 1 | package helpers; 2 | 3 | import org.mockito.ArgumentMatcher; 4 | import pl.pojo.tester.api.ConstructorParameters; 5 | 6 | import java.util.Arrays; 7 | import java.util.Map; 8 | 9 | class MapMatcher implements ArgumentMatcher, ConstructorParameters>> { 10 | 11 | private final Class expectedClass; 12 | private final ConstructorParameters expectedArguments; 13 | 14 | public MapMatcher(final Class expectedClass, final ConstructorParameters expectedArguments) { 15 | this.expectedClass = expectedClass; 16 | this.expectedArguments = expectedArguments; 17 | } 18 | 19 | 20 | @Override 21 | public boolean matches(final Map, ConstructorParameters> argument) { 22 | if (!argument.containsKey(expectedClass)) { 23 | return false; 24 | } 25 | final ConstructorParameters actualArguments = argument.get(expectedClass); 26 | return Arrays.equals(actualArguments.getParameters(), expectedArguments.getParameters()) && 27 | Arrays.equals(actualArguments.getParametersTypes(), expectedArguments.getParametersTypes()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/helpers/MultiValuedMapMatcher.java: -------------------------------------------------------------------------------- 1 | package helpers; 2 | 3 | import org.apache.commons.collections4.MultiValuedMap; 4 | import org.mockito.ArgumentMatcher; 5 | import pl.pojo.tester.api.ConstructorParameters; 6 | 7 | import java.util.Arrays; 8 | 9 | public class MultiValuedMapMatcher implements ArgumentMatcher, ConstructorParameters>> { 10 | 11 | private final Class expectedClass; 12 | private final ConstructorParameters expectedArguments; 13 | 14 | public MultiValuedMapMatcher(final Class expectedClass, final ConstructorParameters expectedArguments) { 15 | this.expectedClass = expectedClass; 16 | this.expectedArguments = expectedArguments; 17 | } 18 | 19 | 20 | @Override 21 | public boolean matches(final MultiValuedMap, ConstructorParameters> argument) { 22 | if (!argument.containsKey(expectedClass)) { 23 | return false; 24 | } 25 | return argument.get(expectedClass) 26 | .stream() 27 | .map(actualArgument -> Arrays.equals(actualArgument.getParameters(), 28 | expectedArguments.getParameters()) 29 | && 30 | Arrays.equals(actualArgument.getParametersTypes(), 31 | expectedArguments.getParametersTypes())) 32 | .findAny() 33 | .isPresent(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/helpers/RecursivelyEqualArgumentMatcher.java: -------------------------------------------------------------------------------- 1 | package helpers; 2 | 3 | import org.mockito.ArgumentMatcher; 4 | import pl.pojo.tester.api.ClassAndFieldPredicatePair; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | public class RecursivelyEqualArgumentMatcher implements ArgumentMatcher { 9 | private final ClassAndFieldPredicatePair expectedParameter; 10 | 11 | public RecursivelyEqualArgumentMatcher(final ClassAndFieldPredicatePair expectedParameter) { 12 | this.expectedParameter = expectedParameter; 13 | } 14 | 15 | @Override 16 | public boolean matches(final ClassAndFieldPredicatePair argument) { 17 | assertThat(argument).isEqualToComparingFieldByFieldRecursively(expectedParameter); 18 | return true; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/helpers/StringPredicateArgumentMatcher.java: -------------------------------------------------------------------------------- 1 | package helpers; 2 | 3 | import java.util.function.Predicate; 4 | import org.mockito.ArgumentMatcher; 5 | 6 | public class StringPredicateArgumentMatcher implements ArgumentMatcher> { 7 | 8 | 9 | @Override 10 | public boolean matches(final Predicate argument) { 11 | return argument.test("a"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/helpers/TestHelper.java: -------------------------------------------------------------------------------- 1 | package helpers; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.Modifier; 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | 10 | public class TestHelper { 11 | 12 | public static List getAllFieldsExceptDummyJacocoField(final Class clazz) { 13 | return Arrays.stream(clazz.getDeclaredFields()) 14 | .filter(field -> !Modifier.isStatic(field.getModifiers())) 15 | .filter(field -> !field.getName() 16 | .equals("$jacocoData")) 17 | .collect(Collectors.toList()); 18 | } 19 | 20 | public static String getDefaultDisplayName(final Object value) { 21 | return "------> " + String.valueOf(value) + " <------"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/api/assertion/MultiClassAssertionTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.api.assertion; 2 | 3 | import helpers.ClassAndFieldPredicatePairArgumentMatcher; 4 | import lombok.Data; 5 | import org.junit.jupiter.api.Test; 6 | import pl.pojo.tester.api.ClassAndFieldPredicatePair; 7 | import pl.pojo.tester.internal.tester.EqualsTester; 8 | import pl.pojo.tester.internal.utils.CollectionUtils; 9 | 10 | import static org.mockito.Mockito.*; 11 | import static org.powermock.reflect.Whitebox.setInternalState; 12 | 13 | 14 | class MultiClassAssertionTest { 15 | 16 | @Test 17 | void Should_Test_Against_Each_Tester() { 18 | // given 19 | final ClassAndFieldPredicatePair caf = new ClassAndFieldPredicatePair(A.class); 20 | final MultiClassAssertion multiClassAssertion = new MultiClassAssertion(CollectionUtils.asList(caf)); 21 | final EqualsTester equalsTester1 = mock(EqualsTester.class); 22 | final EqualsTester equalsTester2 = mock(EqualsTester.class); 23 | setInternalState(multiClassAssertion, "testers", CollectionUtils.asSet(equalsTester1, equalsTester2)); 24 | 25 | // when 26 | multiClassAssertion.runAssertions(); 27 | 28 | // then 29 | verify(equalsTester1, only()).testAll(argThat(new ClassAndFieldPredicatePairArgumentMatcher(A.class, "a"))); 30 | verify(equalsTester2, only()).testAll(argThat(new ClassAndFieldPredicatePairArgumentMatcher(A.class, "a"))); 31 | } 32 | 33 | @Data 34 | private class A { 35 | private int a; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/api/assertion/SingleClassAssetionTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.api.assertion; 2 | 3 | import lombok.Data; 4 | import org.junit.jupiter.api.Test; 5 | import pl.pojo.tester.api.ClassAndFieldPredicatePair; 6 | import pl.pojo.tester.internal.tester.EqualsTester; 7 | import pl.pojo.tester.internal.utils.CollectionUtils; 8 | 9 | import static org.mockito.Mockito.*; 10 | import static org.powermock.reflect.Whitebox.setInternalState; 11 | 12 | 13 | class SingleClassAssetionTest { 14 | 15 | @Test 16 | void Should_Test_Against_Each_Tester() { 17 | // given 18 | final ClassAndFieldPredicatePair classAndFieldPredicatePair = new ClassAndFieldPredicatePair(A.class); 19 | final ClassAndFieldPredicatePair[] classAndFieldPredicatePairs = {classAndFieldPredicatePair}; 20 | final SingleClassAssertion singleClassAssertion = new SingleClassAssertion(classAndFieldPredicatePair, 21 | classAndFieldPredicatePairs); 22 | final EqualsTester equalsTester1 = mock(EqualsTester.class); 23 | final EqualsTester equalsTester2 = mock(EqualsTester.class); 24 | setInternalState(singleClassAssertion, "testers", CollectionUtils.asSet(equalsTester1, equalsTester2)); 25 | 26 | // when 27 | singleClassAssertion.runAssertions(); 28 | 29 | // then 30 | verify(equalsTester1, only()).test(classAndFieldPredicatePair, classAndFieldPredicatePairs); 31 | verify(equalsTester2, only()).test(classAndFieldPredicatePair, classAndFieldPredicatePairs); 32 | } 33 | 34 | @Data 35 | private class A { 36 | private int a; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/GetOrSetValueExceptionTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal; 2 | 3 | import lombok.Data; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | 9 | class GetOrSetValueExceptionTest { 10 | 11 | @Test 12 | void Should_Create_Message_Containing_Field_Name_And_Class_And_Cause_Message() { 13 | // given 14 | final String causeMessage = "cause-message"; 15 | final String fieldName = "class_a_field_name"; 16 | final Class clazz = A.class; 17 | final String className = clazz.getName(); 18 | final Exception cause = new Exception(causeMessage); 19 | 20 | // when 21 | final GetOrSetValueException exception = new GetOrSetValueException(fieldName, clazz, cause); 22 | 23 | // then 24 | assertThat(exception.getCause()).isEqualTo(cause); 25 | assertThat(exception.getMessage()).contains(causeMessage) 26 | .contains(fieldName) 27 | .contains(className); 28 | } 29 | 30 | @Data 31 | private class A { 32 | private int class_a_field_name; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/AbstractAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | 8 | class AbstractAssertionErrorTest { 9 | 10 | @Test 11 | void Should_Set_Stack_Trace_To_Empty_Array() { 12 | // given 13 | final Class testedCass = String.class; 14 | final StackTraceElement[] expectedResult = new StackTraceElement[]{}; 15 | final AbstractAssertionError error = new MockOfAssertionError(testedCass); 16 | 17 | // when 18 | final StackTraceElement[] result = error.getStackTrace(); 19 | 20 | // then 21 | assertThat(result).isEqualTo(expectedResult); 22 | } 23 | 24 | @Test 25 | void Should_Return_Expected_Message() { 26 | // given 27 | final Class testedCass = String.class; 28 | final String expectedResult = "\n" 29 | + "\n" 30 | + "\n" 31 | + "errorPrefix\n" 32 | + "detailedMessage"; 33 | final AbstractAssertionError error = new MockOfAssertionError(testedCass); 34 | 35 | // when 36 | final String result = error.getMessage(); 37 | 38 | // then 39 | assertThat(result).isEqualTo(expectedResult); 40 | } 41 | 42 | class MockOfAssertionError extends AbstractAssertionError { 43 | 44 | MockOfAssertionError(final Class testedCass) { 45 | super(testedCass); 46 | } 47 | 48 | @Override 49 | protected String getErrorPrefix() { 50 | return "errorPrefix"; 51 | } 52 | 53 | @Override 54 | protected String getDetailedMessage() { 55 | return "detailedMessage"; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/equals/ConsistentEqualsAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | 9 | class ConsistentEqualsAssertionErrorTest { 10 | 11 | @Test 12 | void Should_Return_Expected_Detailed_Message() { 13 | // given 14 | final String expectedMessage = "The equals method should be consistent when comparing same objects multiple times.\n" 15 | + "Current implementation returns different results.\n" 16 | + "When comparing object:\n" 17 | + "testedObject\n" 18 | + "to itself, first result was 'true' and second time was 'false'."; 19 | final Class testedCass = String.class; 20 | final String testedObject = "testedObject"; 21 | final boolean firstResult = true; 22 | final boolean secondResult = false; 23 | final ConsistentEqualsAssertionError error = new ConsistentEqualsAssertionError(testedCass, 24 | testedObject, 25 | firstResult, 26 | secondResult); 27 | // when 28 | final String result = error.getDetailedMessage(); 29 | 30 | // then 31 | assertThat(result).isEqualTo(expectedMessage); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/equals/EqualEqualsAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | 9 | class EqualEqualsAssertionErrorTest { 10 | 11 | @Test 12 | void Should_Return_Expected_Detailed_Message() { 13 | // given 14 | final String expectedMessage = "The equals method should return true if objects should be equal.\n" 15 | + "Current implementation returns false.\n" 16 | + "Object:\n" 17 | + "testedObject\n" 18 | + "should be equal to:\n" 19 | + "otherObject"; 20 | final Class testedCass = String.class; 21 | final String testedObject = "testedObject"; 22 | final String otherObject = "otherObject"; 23 | final EqualEqualsAssertionError error = new EqualEqualsAssertionError(testedCass, testedObject, otherObject); 24 | 25 | // when 26 | final String result = error.getDetailedMessage(); 27 | 28 | // then 29 | assertThat(result).isEqualTo(expectedMessage); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/equals/EqualsAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | 8 | class EqualsAssertionErrorTest { 9 | 10 | @Test 11 | void Should_Return_Expected_Error_Prefix() { 12 | // given 13 | final String expectedMessage = "Class java.lang.String has bad 'equals' method implementation."; 14 | final AbstractEqualsAssertionError error = new MockOfEqualsAssertionError(String.class); 15 | 16 | // when 17 | final String result = error.getErrorPrefix(); 18 | 19 | // then 20 | assertThat(result).isEqualTo(expectedMessage); 21 | } 22 | 23 | class MockOfEqualsAssertionError extends AbstractEqualsAssertionError { 24 | 25 | MockOfEqualsAssertionError(final Class testedCass) { 26 | super(testedCass); 27 | } 28 | 29 | @Override 30 | protected String getDetailedMessage() { 31 | return null; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/equals/NotEqualEqualsAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | 9 | class NotEqualEqualsAssertionErrorTest { 10 | 11 | @Test 12 | void Should_Return_Expected_Detailed_Message() { 13 | // given 14 | final String expectedMessage = "The equals method should return false if objects should not be equal.\n" 15 | + "Current implementation returns true.\n" 16 | + "Object:\n" 17 | + "testedObject\n" 18 | + "should not be equal to:\n" 19 | + "otherObject"; 20 | final Class testedCass = String.class; 21 | final String testedObject = "testedObject"; 22 | final String otherObject = "otherObject"; 23 | final NotEqualEqualsAssertionError error = new NotEqualEqualsAssertionError(testedCass, 24 | testedObject, 25 | otherObject); 26 | // when 27 | final String result = error.getDetailedMessage(); 28 | 29 | // then 30 | assertThat(result).isEqualTo(expectedMessage); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/equals/NullEqualsAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | 9 | class NullEqualsAssertionErrorTest { 10 | 11 | @Test 12 | void Should_Return_Expected_Detailed_Message() { 13 | // given 14 | final String expectedMessage = "The equals method should return false if object is comparing to null.\n" 15 | + "Current implementation returns true."; 16 | final Class testedCass = String.class; 17 | final NullEqualsAssertionError error = new NullEqualsAssertionError(testedCass); 18 | 19 | // when 20 | final String result = error.getDetailedMessage(); 21 | 22 | // then 23 | assertThat(result).isEqualTo(expectedMessage); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/equals/OtherTypeEqualsAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | 9 | class OtherTypeEqualsAssertionErrorTest { 10 | 11 | @Test 12 | void Should_Return_Expected_Detailed_Message() { 13 | // given 14 | final String expectedMessage = "The equals method should return false if object is comparing to object with different type.\n" 15 | + "Current implementation returns true.\n" 16 | + "Object:\n" 17 | + "testedObject\n" 18 | + "should not be equal to:\n" 19 | + "otherObject"; 20 | final Class testedCass = String.class; 21 | final String testedObject = "testedObject"; 22 | final String otherObject = "otherObject"; 23 | final OtherTypeEqualsAssertionError error = new OtherTypeEqualsAssertionError(testedCass, 24 | testedObject, 25 | otherObject); 26 | // when 27 | final String result = error.getDetailedMessage(); 28 | 29 | // then 30 | assertThat(result).isEqualTo(expectedMessage); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/equals/ReflexiveEqualsAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | 9 | class ReflexiveEqualsAssertionErrorTest { 10 | 11 | @Test 12 | void Should_Return_Expected_Detailed_Message() { 13 | // given 14 | final String expectedMessage = "The equals method should return true if object is comparing to itself.\n" 15 | + "Current implementation returns false.\n" 16 | + "Object:\n" 17 | + "testedObject\n" 18 | + "should be equal to:\n" 19 | + "testedObject"; 20 | final Class testedCass = String.class; 21 | final String testedObject = "testedObject"; 22 | final ReflexiveEqualsAssertionError error = new ReflexiveEqualsAssertionError(testedCass, testedObject); 23 | 24 | // when 25 | final String result = error.getDetailedMessage(); 26 | 27 | // then 28 | assertThat(result).isEqualTo(expectedMessage); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/equals/SymmetricEqualsAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.equals; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | 9 | class SymmetricEqualsAssertionErrorTest { 10 | 11 | @Test 12 | void Should_Return_Expected_Detailed_Message() { 13 | // given 14 | final String expectedMessage = "The equals method should return true for both a.equals(b) and b.equals(a).\n" 15 | + "Current implementation returns:\n" 16 | + "true for a.equals(b),\n" 17 | + "false for b.equals(a),\n" 18 | + "where 'a' is:\n" 19 | + "testedObject\n" 20 | + "and 'b' is:\n" 21 | + "otherObject"; 22 | final Class testedCass = String.class; 23 | final String testedObject = "testedObject"; 24 | final String otherObject = "otherObject"; 25 | final boolean firstResult = true; 26 | final boolean secondResult = false; 27 | final SymmetricEqualsAssertionError error = new SymmetricEqualsAssertionError(testedCass, 28 | testedObject, 29 | otherObject, 30 | firstResult, 31 | secondResult); 32 | // when 33 | final String result = error.getDetailedMessage(); 34 | 35 | // then 36 | assertThat(result).isEqualTo(expectedMessage); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/hashcode/AbstractHashCodeAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.hashcode; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | 8 | class AbstractHashCodeAssertionErrorTest { 9 | 10 | @Test 11 | void Should_Return_Expected_Error_Prefix() { 12 | // given 13 | final String expectedMessage = "Class java.lang.String has bad 'hashCode' method implementation."; 14 | final Class testedCass = String.class; 15 | final AbstractHashCodeAssertionError error = new MockOfEqualsAssertionError(testedCass); 16 | 17 | // when 18 | final String result = error.getErrorPrefix(); 19 | 20 | // then 21 | assertThat(result).isEqualTo(expectedMessage); 22 | } 23 | 24 | class MockOfEqualsAssertionError extends AbstractHashCodeAssertionError { 25 | MockOfEqualsAssertionError(final Class testedCass) { 26 | super(testedCass); 27 | } 28 | 29 | @Override 30 | protected String getDetailedMessage() { 31 | return null; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/hashcode/ConsistentHashCodeAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.hashcode; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | 8 | class ConsistentHashCodeAssertionErrorTest { 9 | 10 | @Test 11 | void Should_Return_Expected_Detailed_Message() { 12 | // given 13 | final String expectedMessage = "The hashCode method should return same hash code for same object.\n" 14 | + "Current implementation returns different values.\n" 15 | + "Object:\n" 16 | + "testedObject\n" 17 | + "has two different hash codes:\n" 18 | + "1\n" 19 | + "and\n" 20 | + "2"; 21 | final Class testedCass = String.class; 22 | final String testedObject = "testedObject"; 23 | final int secondHashCode = 2; 24 | final int firstHashCode = 1; 25 | final ConsistentHashCodeAssertionError error = new ConsistentHashCodeAssertionError(testedCass, 26 | testedObject, 27 | firstHashCode, 28 | secondHashCode); 29 | // when 30 | final String result = error.getDetailedMessage(); 31 | 32 | // then 33 | assertThat(result).isEqualTo(expectedMessage); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/hashcode/EqualHashCodeAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.hashcode; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | 8 | class EqualHashCodeAssertionErrorTest { 9 | 10 | @Test 11 | void Should_Return_Expected_Detailed_Message() { 12 | // given 13 | final String expectedMessage = "The hashCode method should return same hash code for equal objects.\n" 14 | + "Current implementation returns different values.\n" 15 | + "Object:\n" 16 | + "testedObject\n" 17 | + "and\n" 18 | + "otherObject\n" 19 | + "have two different hash codes:\n" 20 | + "1\n" 21 | + "and\n" 22 | + "2"; 23 | final Class testedCass = String.class; 24 | final String testedObject = "testedObject"; 25 | final String otherObject = "otherObject"; 26 | final int secondHashCode = 2; 27 | final int firstHashCode = 1; 28 | final EqualHashCodeAssertionError error = new EqualHashCodeAssertionError(testedCass, 29 | testedObject, 30 | otherObject, 31 | firstHashCode, 32 | secondHashCode); 33 | // when 34 | final String result = error.getDetailedMessage(); 35 | 36 | // then 37 | assertThat(result).isEqualTo(expectedMessage); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/hashcode/NotEqualHashCodeAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.hashcode; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | 8 | class NotEqualHashCodeAssertionErrorTest { 9 | 10 | @Test 11 | void Should_Return_Expected_Detailed_Message() { 12 | // given 13 | final String expectedMessage = "The hashCode method should return different hash codes for non equal objects.\n" 14 | + "Current implementation returns same hash codes.\n" 15 | + "Object:\n" 16 | + "testedObject\n" 17 | + "and\n" 18 | + "otherObject\n" 19 | + "should have different hash codes:\n" 20 | + "1\n" 21 | + "and\n" 22 | + "2"; 23 | final Class testedCass = String.class; 24 | final String testedObject = "testedObject"; 25 | final String otherObject = "otherObject"; 26 | final int secondHashCode = 2; 27 | final int firstHashCode = 1; 28 | final NotEqualHashCodeAssertionError error = new NotEqualHashCodeAssertionError(testedCass, 29 | testedObject, 30 | otherObject, 31 | firstHashCode, 32 | secondHashCode); 33 | // when 34 | final String result = error.getDetailedMessage(); 35 | 36 | // then 37 | assertThat(result).isEqualTo(expectedMessage); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/tostring/AbstractToStringAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.tostring; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | 8 | class AbstractToStringAssertionErrorTest { 9 | 10 | @Test 11 | void Should_Return_Expected_Error_Prefix() { 12 | // given 13 | final String expectedMessage = "Class java.lang.String has bad 'toString' method implementation."; 14 | final Class testedCass = String.class; 15 | final AbstractToStringAssertionError error = new MockOfToStringAssertionError(testedCass); 16 | 17 | // when 18 | final String result = error.getErrorPrefix(); 19 | 20 | // then 21 | assertThat(result).isEqualTo(expectedMessage); 22 | } 23 | 24 | class MockOfToStringAssertionError extends AbstractToStringAssertionError { 25 | MockOfToStringAssertionError(final Class testedCass) { 26 | super(testedCass); 27 | } 28 | 29 | @Override 30 | protected String getDetailedMessage() { 31 | return null; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/tostring/ContainsToStringAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.tostring; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | 8 | class ContainsToStringAssertionErrorTest { 9 | 10 | @Test 11 | void Should_Return_Expected_Detailed_Message() { 12 | // given 13 | final String expectedMessage = "The toString method should contain:\n" 14 | + "value\n" 15 | + "But does not.\n" 16 | + "Result of toString:\n" 17 | + "toString"; 18 | final Class testedCass = String.class; 19 | final String value = "value"; 20 | final String toString = "toString"; 21 | final ContainsToStringAssertionError error = new ContainsToStringAssertionError(testedCass, value, toString); 22 | 23 | // when 24 | final String result = error.getDetailedMessage(); 25 | 26 | // then 27 | assertThat(result).isEqualTo(expectedMessage); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/assertion/tostring/NotContainToStringAssertionErrorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.assertion.tostring; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | 8 | class NotContainToStringAssertionErrorTest { 9 | 10 | @Test 11 | void Should_Return_Expected_Detailed_Message() { 12 | // given 13 | final String expectedMessage = "The toString method should not contain:\n" 14 | + "value\n" 15 | + "but does.\n" 16 | + "Result of toString:\n" 17 | + "toString"; 18 | final Class testedCass = String.class; 19 | final String value = "value"; 20 | final String toString = "toString"; 21 | final NotContainToStringAssertionError error = new NotContainToStringAssertionError(testedCass, 22 | value, 23 | toString); 24 | 25 | // when 26 | final String result = error.getDetailedMessage(); 27 | 28 | // then 29 | assertThat(result).isEqualTo(expectedMessage); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/collection/ArrayListValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.ArrayList; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | 11 | class ArrayListValueChangerTest { 12 | 13 | @Test 14 | void Should_Return_Null_When_Value_Is_Not_Null_And_Not_Empty() { 15 | // given 16 | final ArrayList value = new ArrayList<>(); 17 | value.add("test"); 18 | final Class type = value.getClass(); 19 | 20 | final ArrayListValueChanger valueChanger = new ArrayListValueChanger(); 21 | 22 | // when 23 | final ArrayList result = valueChanger.increaseValue(value, type); 24 | 25 | // then 26 | assertThat(result).isNull(); 27 | } 28 | 29 | @Test 30 | void Should_Return_Any_Instance_When_Value_Is_Null() { 31 | // given 32 | final ArrayList value = null; 33 | final Class type = ArrayList.class; 34 | 35 | final ArrayListValueChanger valueChanger = new ArrayListValueChanger(); 36 | 37 | // when 38 | final ArrayList result = valueChanger.increaseValue(value, type); 39 | 40 | // then 41 | assertThat(result).isInstanceOf(type); 42 | } 43 | 44 | @Test 45 | void Should_Return_Any_Instance_When_Value_Is_Empty() { 46 | // given 47 | final ArrayList value = new ArrayList<>(); 48 | final Class type = ArrayList.class; 49 | 50 | final ArrayListValueChanger valueChanger = new ArrayListValueChanger(); 51 | 52 | // when 53 | final ArrayList result = valueChanger.increaseValue(value, type); 54 | 55 | // then 56 | assertThat(result).isInstanceOf(type); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/collection/DequeValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.Deque; 7 | import java.util.LinkedList; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | 12 | class DequeValueChangerTest { 13 | 14 | @Test 15 | void Should_Return_Null_When_Value_Is_Not_Null_And_Not_Empty() { 16 | // given 17 | final Deque value = new LinkedList<>(); 18 | value.add("test"); 19 | final Class type = value.getClass(); 20 | 21 | final DequeValueChanger valueChanger = new DequeValueChanger(); 22 | 23 | // when 24 | final Deque result = valueChanger.increaseValue(value, type); 25 | 26 | // then 27 | assertThat(result).isNull(); 28 | } 29 | 30 | @Test 31 | void Should_Return_Any_Instance_When_Value_Is_Null() { 32 | // given 33 | final Deque value = null; 34 | final Class type = Deque.class; 35 | 36 | final DequeValueChanger valueChanger = new DequeValueChanger(); 37 | 38 | // when 39 | final Deque result = valueChanger.increaseValue(value, type); 40 | 41 | // then 42 | assertThat(result).isInstanceOf(type); 43 | } 44 | 45 | @Test 46 | void Should_Return_Any_Instance_When_Value_Is_Empty() { 47 | // given 48 | final Deque value = new LinkedList<>(); 49 | final Class type = Deque.class; 50 | 51 | final DequeValueChanger valueChanger = new DequeValueChanger(); 52 | 53 | // when 54 | final Deque result = valueChanger.increaseValue(value, type); 55 | 56 | // then 57 | assertThat(result).isInstanceOf(type); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/collection/HashSetValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.HashSet; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | 11 | class HashSetValueChangerTest { 12 | 13 | @Test 14 | void Should_Return_Null_When_Value_Is_Not_Null_And_Not_Empty() { 15 | // given 16 | final HashSet value = new HashSet<>(); 17 | value.add("test"); 18 | final Class type = value.getClass(); 19 | 20 | final HashSetValueChanger valueChanger = new HashSetValueChanger(); 21 | 22 | // when 23 | final HashSet result = valueChanger.increaseValue(value, type); 24 | 25 | // then 26 | assertThat(result).isNull(); 27 | } 28 | 29 | @Test 30 | void Should_Return_Any_Instance_When_Value_Is_Null() { 31 | // given 32 | final HashSet value = null; 33 | final Class type = HashSet.class; 34 | 35 | final HashSetValueChanger valueChanger = new HashSetValueChanger(); 36 | 37 | // when 38 | final HashSet result = valueChanger.increaseValue(value, type); 39 | 40 | // then 41 | assertThat(result).isInstanceOf(type); 42 | } 43 | 44 | @Test 45 | void Should_Return_Any_Instance_When_Value_Is_Empty() { 46 | // given 47 | final HashSet value = new HashSet<>(); 48 | final Class type = HashSet.class; 49 | 50 | final HashSetValueChanger valueChanger = new HashSetValueChanger(); 51 | 52 | // when 53 | final HashSet result = valueChanger.increaseValue(value, type); 54 | 55 | // then 56 | assertThat(result).isInstanceOf(type); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/collection/ListValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | 12 | class ListValueChangerTest { 13 | 14 | @Test 15 | void Should_Return_Null_When_Value_Is_Not_Null_And_Not_Empty() { 16 | // given 17 | final List value = new ArrayList<>(); 18 | value.add("test"); 19 | final Class type = value.getClass(); 20 | 21 | final ListValueChanger valueChanger = new ListValueChanger(); 22 | 23 | // when 24 | final List result = valueChanger.increaseValue(value, type); 25 | 26 | // then 27 | assertThat(result).isNull(); 28 | } 29 | 30 | @Test 31 | void Should_Return_Any_Instance_When_Value_Is_Null() { 32 | // given 33 | final List value = null; 34 | final Class type = List.class; 35 | 36 | final ListValueChanger valueChanger = new ListValueChanger(); 37 | 38 | // when 39 | final List result = valueChanger.increaseValue(value, type); 40 | 41 | // then 42 | assertThat(result).isInstanceOf(type); 43 | } 44 | 45 | @Test 46 | void Should_Return_Any_Instance_When_Value_Is_Empty() { 47 | // given 48 | final List value = new ArrayList<>(); 49 | final Class type = List.class; 50 | 51 | final ListValueChanger valueChanger = new ListValueChanger(); 52 | 53 | // when 54 | final List result = valueChanger.increaseValue(value, type); 55 | 56 | // then 57 | assertThat(result).isInstanceOf(type); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/collection/QueueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.LinkedList; 7 | import java.util.Queue; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | 12 | class QueueChangerTest { 13 | 14 | @Test 15 | void Should_Return_Null_When_Value_Is_Not_Null_And_Not_Empty() { 16 | // given 17 | final Queue value = new LinkedList<>(); 18 | value.add("test"); 19 | final Class type = value.getClass(); 20 | 21 | final QueueValueChanger valueChanger = new QueueValueChanger(); 22 | 23 | // when 24 | final Queue result = valueChanger.increaseValue(value, type); 25 | 26 | // then 27 | assertThat(result).isNull(); 28 | } 29 | 30 | @Test 31 | void Should_Return_Any_Instance_When_Value_Is_Null() { 32 | // given 33 | final Queue value = null; 34 | final Class type = Queue.class; 35 | 36 | final QueueValueChanger valueChanger = new QueueValueChanger(); 37 | 38 | // when 39 | final Queue result = valueChanger.increaseValue(value, type); 40 | 41 | // then 42 | assertThat(result).isInstanceOf(type); 43 | } 44 | 45 | @Test 46 | void Should_Return_Any_Instance_When_Value_Is_Empty() { 47 | // given 48 | final Queue value = new LinkedList<>(); 49 | final Class type = Queue.class; 50 | 51 | final QueueValueChanger valueChanger = new QueueValueChanger(); 52 | 53 | // when 54 | final Queue result = valueChanger.increaseValue(value, type); 55 | 56 | // then 57 | assertThat(result).isInstanceOf(type); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/collection/SetChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.HashSet; 7 | import java.util.Set; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | 12 | class SetChangerTest { 13 | 14 | @Test 15 | void Should_Return_Null_When_Value_Is_Not_Null_And_Not_Empty() { 16 | // given 17 | final Set value = new HashSet<>(); 18 | value.add("test"); 19 | final Class type = value.getClass(); 20 | 21 | final SetValueChanger valueChanger = new SetValueChanger(); 22 | 23 | // when 24 | final Set result = valueChanger.increaseValue(value, type); 25 | 26 | // then 27 | assertThat(result).isNull(); 28 | } 29 | 30 | @Test 31 | void Should_Return_Any_Instance_When_Value_Is_Null() { 32 | // given 33 | final Set value = null; 34 | final Class type = Set.class; 35 | 36 | final SetValueChanger valueChanger = new SetValueChanger(); 37 | 38 | // when 39 | final Set result = valueChanger.increaseValue(value, type); 40 | 41 | // then 42 | assertThat(result).isInstanceOf(type); 43 | } 44 | 45 | @Test 46 | void Should_Return_Any_Instance_When_Value_Is_Empty() { 47 | // given 48 | final Set value = new HashSet<>(); 49 | final Class type = Set.class; 50 | 51 | final SetValueChanger valueChanger = new SetValueChanger(); 52 | 53 | // when 54 | final Set result = valueChanger.increaseValue(value, type); 55 | 56 | // then 57 | assertThat(result).isInstanceOf(type); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/collection/SortedSetChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.SortedSet; 7 | import java.util.TreeSet; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | 12 | class SortedSetChangerTest { 13 | 14 | @Test 15 | void Should_Return_Null_When_Value_Is_Not_Null_And_Not_Empty() { 16 | // given 17 | final SortedSet value = new TreeSet<>(); 18 | value.add("test"); 19 | final Class type = value.getClass(); 20 | 21 | final SortedSetValueChanger valueChanger = new SortedSetValueChanger(); 22 | 23 | // when 24 | final SortedSet result = valueChanger.increaseValue(value, type); 25 | 26 | // then 27 | assertThat(result).isNull(); 28 | } 29 | 30 | @Test 31 | void Should_Return_Any_Instance_When_Value_Is_Null() { 32 | // given 33 | final SortedSet value = null; 34 | final Class type = SortedSet.class; 35 | 36 | final SortedSetValueChanger valueChanger = new SortedSetValueChanger(); 37 | 38 | // when 39 | final SortedSet result = valueChanger.increaseValue(value, type); 40 | 41 | // then 42 | assertThat(result).isInstanceOf(type); 43 | } 44 | 45 | @Test 46 | void Should_Return_Any_Instance_When_Value_Is_Empty() { 47 | // given 48 | final SortedSet value = new TreeSet<>(); 49 | final Class type = SortedSet.class; 50 | 51 | final SortedSetValueChanger valueChanger = new SortedSetValueChanger(); 52 | 53 | // when 54 | final SortedSet result = valueChanger.increaseValue(value, type); 55 | 56 | // then 57 | assertThat(result).isInstanceOf(type); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/collection/StackChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.Stack; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | 11 | class StackChangerTest { 12 | 13 | @Test 14 | void Should_Return_Null_When_Value_Is_Not_Null_And_Not_Empty() { 15 | // given 16 | final Stack value = new Stack<>(); 17 | value.add("test"); 18 | final Class type = value.getClass(); 19 | 20 | final StackValueChanger valueChanger = new StackValueChanger(); 21 | 22 | // when 23 | final Stack result = valueChanger.increaseValue(value, type); 24 | 25 | // then 26 | assertThat(result).isNull(); 27 | } 28 | 29 | @Test 30 | void Should_Return_Any_Instance_When_Value_Is_Null() { 31 | // given 32 | final Stack value = null; 33 | final Class type = Stack.class; 34 | 35 | final StackValueChanger valueChanger = new StackValueChanger(); 36 | 37 | // when 38 | final Stack result = valueChanger.increaseValue(value, type); 39 | 40 | // then 41 | assertThat(result).isInstanceOf(type); 42 | } 43 | 44 | @Test 45 | void Should_Return_Any_Instance_When_Value_Is_Empty() { 46 | // given 47 | final Stack value = new Stack<>(); 48 | final Class type = Stack.class; 49 | 50 | final StackValueChanger valueChanger = new StackValueChanger(); 51 | 52 | // when 53 | final Stack result = valueChanger.increaseValue(value, type); 54 | 55 | // then 56 | assertThat(result).isInstanceOf(type); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/collection/TreeSetChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.TreeSet; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | 11 | class TreeSetChangerTest { 12 | 13 | @Test 14 | void Should_Return_Null_When_Value_Is_Not_Null_And_Not_Empty() { 15 | // given 16 | final TreeSet value = new TreeSet<>(); 17 | value.add("test"); 18 | final Class type = value.getClass(); 19 | 20 | final TreeSetValueChanger valueChanger = new TreeSetValueChanger(); 21 | 22 | // when 23 | final TreeSet result = valueChanger.increaseValue(value, type); 24 | 25 | // then 26 | assertThat(result).isNull(); 27 | } 28 | 29 | @Test 30 | void Should_Return_Any_Instance_When_Value_Is_Null() { 31 | // given 32 | final TreeSet value = null; 33 | final Class type = TreeSet.class; 34 | 35 | final TreeSetValueChanger valueChanger = new TreeSetValueChanger(); 36 | 37 | // when 38 | final TreeSet result = valueChanger.increaseValue(value, type); 39 | 40 | // then 41 | assertThat(result).isInstanceOf(type); 42 | } 43 | 44 | @Test 45 | void Should_Return_Any_Instance_When_Value_Is_Empty() { 46 | // given 47 | final TreeSet value = new TreeSet<>(); 48 | final Class type = TreeSet.class; 49 | 50 | final TreeSetValueChanger valueChanger = new TreeSetValueChanger(); 51 | 52 | // when 53 | final TreeSet result = valueChanger.increaseValue(value, type); 54 | 55 | // then 56 | assertThat(result).isInstanceOf(type); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/collection/VectorChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.collection; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.Vector; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | 11 | class VectorChangerTest { 12 | 13 | @Test 14 | void Should_Return_Null_When_Value_Is_Not_Null_And_Not_Empty() { 15 | // given 16 | final Vector value = new Vector<>(); 17 | value.add("test"); 18 | final Class type = value.getClass(); 19 | 20 | final VectorValueChanger valueChanger = new VectorValueChanger(); 21 | 22 | // when 23 | final Vector result = valueChanger.increaseValue(value, type); 24 | 25 | // then 26 | assertThat(result).isNull(); 27 | } 28 | 29 | @Test 30 | void Should_Return_Any_Instance_When_Value_Is_Null() { 31 | // given 32 | final Vector value = null; 33 | final Class type = Vector.class; 34 | 35 | final VectorValueChanger valueChanger = new VectorValueChanger(); 36 | 37 | // when 38 | final Vector result = valueChanger.increaseValue(value, type); 39 | 40 | // then 41 | assertThat(result).isInstanceOf(type); 42 | } 43 | 44 | @Test 45 | void Should_Return_Any_Instance_When_Value_Is_Empty() { 46 | // given 47 | final Vector value = new Vector<>(); 48 | final Class type = Vector.class; 49 | 50 | final VectorValueChanger valueChanger = new VectorValueChanger(); 51 | 52 | // when 53 | final Vector result = valueChanger.increaseValue(value, type); 54 | 55 | // then 56 | assertThat(result).isInstanceOf(type); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/map/HashMapValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.HashMap; 6 | 7 | import static org.assertj.core.api.Assertions.assertThat; 8 | 9 | 10 | class HashMapValueChangerTest { 11 | 12 | @Test 13 | void Should_Return_Null_When_Value_Is_Not_Null() { 14 | // given 15 | final HashMap value = new HashMap<>(); 16 | final Class type = value.getClass(); 17 | 18 | final HashMapValueChanger valueChanger = new HashMapValueChanger(); 19 | 20 | // when 21 | final HashMap result = valueChanger.increaseValue(value, type); 22 | 23 | // then 24 | assertThat(result).isNull(); 25 | } 26 | 27 | @Test 28 | void Should_Return_Any_Instance_When_Value_Is_Null() { 29 | // given 30 | final HashMap value = null; 31 | final Class type = HashMap.class; 32 | 33 | final HashMapValueChanger valueChanger = new HashMapValueChanger(); 34 | 35 | // when 36 | final HashMap result = valueChanger.increaseValue(value, type); 37 | 38 | // then 39 | assertThat(result).isInstanceOf(type); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/map/HashtableValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.Hashtable; 6 | 7 | import static org.assertj.core.api.Assertions.assertThat; 8 | 9 | 10 | class HashtableValueChangerTest { 11 | 12 | @Test 13 | void Should_Return_Null_When_Value_Is_Not_Null() { 14 | // given 15 | final Hashtable value = new Hashtable<>(); 16 | final Class type = value.getClass(); 17 | 18 | final HashtableValueChanger valueChanger = new HashtableValueChanger(); 19 | 20 | // when 21 | final Hashtable result = valueChanger.increaseValue(value, type); 22 | 23 | // then 24 | assertThat(result).isNull(); 25 | } 26 | 27 | @Test 28 | void Should_Return_Any_Instance_When_Value_Is_Null() { 29 | // given 30 | final Hashtable value = null; 31 | final Class type = Hashtable.class; 32 | 33 | final HashtableValueChanger valueChanger = new HashtableValueChanger(); 34 | 35 | // when 36 | final Hashtable result = valueChanger.increaseValue(value, type); 37 | 38 | // then 39 | assertThat(result).isInstanceOf(type); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/map/LinkedHashMapValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.LinkedHashMap; 6 | 7 | import static org.assertj.core.api.Assertions.assertThat; 8 | 9 | 10 | class LinkedHashMapValueChangerTest { 11 | 12 | @Test 13 | void Should_Return_Null_When_Value_Is_Not_Null() { 14 | // given 15 | final LinkedHashMap value = new LinkedHashMap<>(); 16 | final Class type = value.getClass(); 17 | 18 | final LinkedHashMapValueChanger valueChanger = new LinkedHashMapValueChanger(); 19 | 20 | // when 21 | final LinkedHashMap result = valueChanger.increaseValue(value, type); 22 | 23 | // then 24 | assertThat(result).isNull(); 25 | } 26 | 27 | @Test 28 | void Should_Return_Any_Instance_When_Value_Is_Null() { 29 | // given 30 | final LinkedHashMap value = null; 31 | final Class type = LinkedHashMap.class; 32 | 33 | final LinkedHashMapValueChanger valueChanger = new LinkedHashMapValueChanger(); 34 | 35 | // when 36 | final LinkedHashMap result = valueChanger.increaseValue(value, type); 37 | 38 | // then 39 | assertThat(result).isInstanceOf(type); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/map/MapValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | 11 | class MapValueChangerTest { 12 | 13 | @Test 14 | void Should_Return_Null_When_Value_Is_Not_Null() { 15 | // given 16 | final Map value = new HashMap<>(); 17 | final Class type = value.getClass(); 18 | 19 | final MapValueChanger valueChanger = new MapValueChanger(); 20 | 21 | // when 22 | final Map result = valueChanger.increaseValue(value, type); 23 | 24 | // then 25 | assertThat(result).isNull(); 26 | } 27 | 28 | @Test 29 | void Should_Return_Any_Instance_When_Value_Is_Null() { 30 | // given 31 | final Map value = null; 32 | final Class type = Map.class; 33 | 34 | final MapValueChanger valueChanger = new MapValueChanger(); 35 | 36 | // when 37 | final Map result = valueChanger.increaseValue(value, type); 38 | 39 | // then 40 | assertThat(result).isInstanceOf(type); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/map/SortedMapValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.SortedMap; 6 | import java.util.TreeMap; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | 11 | class SortedMapValueChangerTest { 12 | 13 | @Test 14 | void Should_Return_Null_When_Value_Is_Not_Null() { 15 | // given 16 | final SortedMap value = new TreeMap<>(); 17 | final Class type = value.getClass(); 18 | 19 | final SortedMapValueChanger valueChanger = new SortedMapValueChanger(); 20 | 21 | // when 22 | final SortedMap result = valueChanger.increaseValue(value, type); 23 | 24 | // then 25 | assertThat(result).isNull(); 26 | } 27 | 28 | @Test 29 | void Should_Return_Any_Instance_When_Value_Is_Null() { 30 | // given 31 | final SortedMap value = null; 32 | final Class type = SortedMap.class; 33 | 34 | final SortedMapValueChanger valueChanger = new SortedMapValueChanger(); 35 | 36 | // when 37 | final SortedMap result = valueChanger.increaseValue(value, type); 38 | 39 | // then 40 | assertThat(result).isInstanceOf(type); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/collections/map/TreeMapValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.collections.map; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.TreeMap; 6 | 7 | import static org.assertj.core.api.Assertions.assertThat; 8 | 9 | 10 | class TreeMapValueChangerTest { 11 | 12 | @Test 13 | void Should_Return_Null_When_Value_Is_Not_Null() { 14 | // given 15 | final TreeMap value = new TreeMap<>(); 16 | final Class type = value.getClass(); 17 | 18 | final TreeMapValueChanger valueChanger = new TreeMapValueChanger(); 19 | 20 | // when 21 | final TreeMap result = valueChanger.increaseValue(value, type); 22 | 23 | // then 24 | assertThat(result).isNull(); 25 | } 26 | 27 | @Test 28 | void Should_Return_Any_Instance_When_Value_Is_Null() { 29 | // given 30 | final TreeMap value = null; 31 | final Class type = TreeMap.class; 32 | 33 | final TreeMapValueChanger valueChanger = new TreeMapValueChanger(); 34 | 35 | // when 36 | final TreeMap result = valueChanger.increaseValue(value, type); 37 | 38 | // then 39 | assertThat(result).isInstanceOf(type); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/field/primitive/AbstractPrimitiveValueChangerTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.field.primitive; 2 | 3 | 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.lang.reflect.Field; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | 11 | class AbstractPrimitiveValueChangerTest { 12 | 13 | @Test 14 | void Should_Return_False_When_Field_Is_Not_Primitive() throws Exception { 15 | // given 16 | final Field field = Thread.class.getDeclaredField("threadQ"); 17 | final AbstractPrimitiveValueChanger changerMock = new ImplementationForTest(); 18 | 19 | // when 20 | final boolean result = changerMock.canChange(field.getType()); 21 | 22 | // then 23 | assertThat(result).isFalse(); 24 | } 25 | 26 | private class ImplementationForTest extends AbstractPrimitiveValueChanger { 27 | 28 | @Override 29 | protected Object increase(final Object value) { 30 | return null; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/instantiator/EnumInstantiatorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.instantiator; 2 | 3 | 4 | import classesForTest.EmptyEnum; 5 | import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | 11 | public class EnumInstantiatorTest { 12 | 13 | @Test 14 | void Should_Return_Null_When_Enum_Is_Empty() { 15 | // given 16 | final EnumInstantiator instantiator = new EnumInstantiator(EmptyEnum.class, new ArrayListValuedHashMap<>()); 17 | 18 | // when 19 | final Object result = instantiator.instantiate(); 20 | 21 | // then 22 | assertThat(result).isNull(); 23 | } 24 | 25 | @Test 26 | void Should_Return_Any_Enum_Value() { 27 | // given 28 | final Class doubleEnumClass = DoubleEnum.class; 29 | final EnumInstantiator instantiator = new EnumInstantiator(doubleEnumClass, new ArrayListValuedHashMap<>()); 30 | 31 | // when 32 | final Object result = instantiator.instantiate(); 33 | 34 | // then 35 | assertThat(result).isInstanceOf(doubleEnumClass); 36 | } 37 | 38 | @Test 39 | void Should_Return_One_Enum_Value() { 40 | // given 41 | final Class oneEnumClass = OneEnum.class; 42 | final EnumInstantiator instantiator = new EnumInstantiator(oneEnumClass, new ArrayListValuedHashMap<>()); 43 | 44 | // when 45 | final Object result = instantiator.instantiate(); 46 | 47 | // then 48 | assertThat(result).isInstanceOf(oneEnumClass); 49 | } 50 | 51 | enum DoubleEnum { 52 | FIRST, 53 | SECOND 54 | } 55 | 56 | enum OneEnum { 57 | FIRST 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/utils/ReflectionUtilsTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | import classesForTest.reflectionUtils.next.D; 4 | import classesForTest.reflectionUtils.next.E; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.io.IOException; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | class ReflectionUtilsTest { 12 | 13 | @Test 14 | void Should_Return_Classes_From_Given_Package_Name() throws IOException { 15 | // given 16 | final Class[] expectedClasses = new Class[]{ D.class, E.class }; 17 | 18 | // when 19 | final Class[] result = ReflectionUtils.getClassesFromPackage("classesForTest.reflectionUtils.next"); 20 | 21 | // then 22 | assertThat(result).containsExactlyInAnyOrder(expectedClasses); 23 | } 24 | } -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/utils/SublistFieldPermutatorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | import classesForTest.permutator.A; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.lang.reflect.Field; 7 | import java.util.List; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | import static pl.pojo.tester.internal.utils.CollectionUtils.asList; 11 | 12 | class SublistFieldPermutatorTest { 13 | 14 | @Test 15 | void Should_Create_Permutations() throws NoSuchFieldException { 16 | // given 17 | final SublistFieldPermutator permutator = new SublistFieldPermutator(); 18 | final Field aField = A.class.getDeclaredField("a"); 19 | final Field bField = A.class.getDeclaredField("b"); 20 | final List elements = asList(aField, bField); 21 | final List> expectedResult = asList(asList(aField, bField), asList(bField)); 22 | 23 | // when 24 | final List> result = permutator.permute(elements); 25 | 26 | // then 27 | assertThat(result).isEqualTo(expectedResult); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /src/test/java/pl/pojo/tester/internal/utils/ThoroughFieldPermutatorTest.java: -------------------------------------------------------------------------------- 1 | package pl.pojo.tester.internal.utils; 2 | 3 | import classesForTest.permutator.A; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.lang.reflect.Field; 7 | import java.util.List; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | import static pl.pojo.tester.internal.utils.CollectionUtils.asList; 11 | 12 | class ThoroughFieldPermutatorTest { 13 | 14 | @Test 15 | void Should_Create_Permutations() throws NoSuchFieldException { 16 | // given 17 | final ThoroughFieldPermutator permutator = new ThoroughFieldPermutator(); 18 | final Field aField = A.class.getDeclaredField("a"); 19 | final Field bField = A.class.getDeclaredField("b"); 20 | final List elements = asList(aField, bField); 21 | final List> expectedResult = asList(asList(aField), asList(bField), asList(aField, bField)); 22 | 23 | // when 24 | final List> result = permutator.permute(elements); 25 | 26 | // then 27 | assertThat(result).isEqualTo(expectedResult); 28 | } 29 | 30 | } --------------------------------------------------------------------------------