diff --git a/src/main/java/pl/pojo/tester/api/ConstructorParameters.java b/src/main/java/pl/pojo/tester/api/ConstructorParameters.java index c5336f12..b5fb1705 100644 --- a/src/main/java/pl/pojo/tester/api/ConstructorParameters.java +++ b/src/main/java/pl/pojo/tester/api/ConstructorParameters.java @@ -23,7 +23,7 @@ public class ConstructorParameters { private final Class[] constructorParametersTypes; /** - * Instantaites {@code ConstructorParameters} with given constructor parameters and constructor parameter's types. + * Instantiates {@code ConstructorParameters} with given constructor parameters and constructor parameter's types. * * @param constructorParameters constructor parameters * @param constructorParametersTypes constructor parameter's types diff --git a/src/main/java/pl/pojo/tester/api/DefaultPackageFilter.java b/src/main/java/pl/pojo/tester/api/DefaultPackageFilter.java index 5a9788a0..b26ec304 100644 --- a/src/main/java/pl/pojo/tester/api/DefaultPackageFilter.java +++ b/src/main/java/pl/pojo/tester/api/DefaultPackageFilter.java @@ -77,7 +77,7 @@ public Class[] getClasses() { .map(ClassLoader::loadClass) .toArray(Class[]::new); } catch (final IOException e) { - throw new PacakgeFilterException(packageFile.toString(), e); + throw new PackageFilterException(packageFile.toString(), e); } } @@ -103,7 +103,7 @@ private File getFile(final String packageName) { .getContextClassLoader() .getResource(packagePath); if (fileUrl == null) { - throw new PacakgeFilterException(packagePath, null); + throw new PackageFilterException(packagePath, null); } return new File(fileUrl.getFile()); } diff --git a/src/main/java/pl/pojo/tester/api/PacakgeFilterException.java b/src/main/java/pl/pojo/tester/api/PackageFilterException.java similarity index 82% rename from src/main/java/pl/pojo/tester/api/PacakgeFilterException.java rename to src/main/java/pl/pojo/tester/api/PackageFilterException.java index f8ed24ed..f374b244 100644 --- a/src/main/java/pl/pojo/tester/api/PacakgeFilterException.java +++ b/src/main/java/pl/pojo/tester/api/PackageFilterException.java @@ -9,7 +9,7 @@ * @author Piotr JoĊ„ski * @since 0.5.0 */ -public class PacakgeFilterException extends RuntimeException { +public class PackageFilterException extends RuntimeException { /** * Instantiates exception. @@ -17,7 +17,7 @@ public class PacakgeFilterException extends RuntimeException { * @param packageName package name or file of package * @param cause cause, which raised this exception */ - public PacakgeFilterException(final String packageName, final IOException cause) { + public PackageFilterException(final String packageName, final IOException cause) { super(createMessage(packageName), cause); } diff --git a/src/main/java/pl/pojo/tester/api/assertion/AbstractAssertion.java b/src/main/java/pl/pojo/tester/api/assertion/AbstractAssertion.java index 77518c9c..3f77a4d9 100644 --- a/src/main/java/pl/pojo/tester/api/assertion/AbstractAssertion.java +++ b/src/main/java/pl/pojo/tester/api/assertion/AbstractAssertion.java @@ -110,10 +110,10 @@ public void areWellImplemented() { /** * Indicates, that class should be constructed using given constructor parameters. Constructor will be selected - * based on constructor paramter's types. + * based on constructor parameter's types. * * @param qualifiedClassName class to instantiate - * @param constructorParameters constructor paramters + * @param constructorParameters constructor parameters * @param constructorParameterTypes constructor parameter's types * * @return itself @@ -130,10 +130,10 @@ public AbstractAssertion create(final String qualifiedClassName, final Object[] /** * Indicates, that class should be constructed using given constructor parameters. Constructor will be selected - * based on constructor paramter's types. + * based on constructor parameter's types. * * @param qualifiedClassName class to instantiate - * @param constructorParameters constructor paramters + * @param constructorParameters constructor parameters * * @return itself * @@ -150,10 +150,10 @@ public AbstractAssertion create(final String qualifiedClassName, final Construct /** * Indicates, that class should be constructed using given constructor parameters. Constructor will be selected - * based on constructor paramter's types. + * based on constructor parameter's types. * * @param clazz class to instantiate - * @param constructorParameters constructor paramters + * @param constructorParameters constructor parameters * @param constructorParameterTypes constructor parameter's types * * @return itself @@ -171,10 +171,10 @@ public AbstractAssertion create(final Class clazz, final Object[] constructor /** * Indicates, that class should be constructed using given constructor parameters. Constructor will be selected - * based on constructor paramter's types. + * based on constructor parameter's types. * * @param clazz class to instantiate - * @param constructorParameters constructor paramters + * @param constructorParameters constructor parameters * * @return itself * diff --git a/src/main/java/pl/pojo/tester/internal/instantiator/AbstractObjectInstantiator.java b/src/main/java/pl/pojo/tester/internal/instantiator/AbstractObjectInstantiator.java index 1e81e7cf..3daa3309 100644 --- a/src/main/java/pl/pojo/tester/internal/instantiator/AbstractObjectInstantiator.java +++ b/src/main/java/pl/pojo/tester/internal/instantiator/AbstractObjectInstantiator.java @@ -2,7 +2,7 @@ abstract class AbstractObjectInstantiator { - protected Class clazz; + protected final Class clazz; AbstractObjectInstantiator(final Class clazz) { this.clazz = clazz; diff --git a/src/main/java/pl/pojo/tester/internal/instantiator/Instantiable.java b/src/main/java/pl/pojo/tester/internal/instantiator/Instantiable.java index 39d59bc1..47b4f413 100644 --- a/src/main/java/pl/pojo/tester/internal/instantiator/Instantiable.java +++ b/src/main/java/pl/pojo/tester/internal/instantiator/Instantiable.java @@ -91,9 +91,7 @@ private static boolean canBeCreatedByDefaultConstructor(final Class clazz) { final Constructor[] constructors = clazz.getConstructors(); return !qualifiesForProxy(clazz) && Arrays.stream(constructors) .filter(Instantiable::isNoArgs) - .filter(Instantiable::isPublic) - .findAny() - .isPresent(); + .anyMatch(Instantiable::isPublic); } private static boolean isPublic(final Constructor constructor) { diff --git a/src/main/java/pl/pojo/tester/internal/tester/AbstractTester.java b/src/main/java/pl/pojo/tester/internal/tester/AbstractTester.java index 54600e37..9158a579 100644 --- a/src/main/java/pl/pojo/tester/internal/tester/AbstractTester.java +++ b/src/main/java/pl/pojo/tester/internal/tester/AbstractTester.java @@ -19,20 +19,29 @@ public abstract class AbstractTester { - ObjectGenerator objectGenerator; - TestAssertions testAssertions = new TestAssertions(); - private MultiValuedMap, ConstructorParameters> constructorParameters = new ArrayListValuedHashMap<>(); - private AbstractFieldValueChanger fieldValuesChanger = DefaultFieldValueChanger.INSTANCE; + new + final TestAsserti - public AbstractTester() { + estAsserti +ObjectGenerator obje dMap< + public AbstractTe + t eneCl ss ator;ons = private Multi + ConstructorParamet rs, constructorPar m> private AbstractFieldValueChanger fieldValuesChanger = DefaultFieldValueChanger.INSTANCE; ters = new ArrayListValuedHashMap< + + r() +{ this(DefaultFieldValueChanger.INSTANCE); } + public AbstractTester(final AbstractFieldValueChanger abstractFieldValueChanger) { - objectGenerator = new ObjectGenerator(abstractFieldValueChanger, constructorParameters); + objectGenerator = new ObjectGenerator(abstractFieldValueChanger, constructorParamet rs); } +TestAsserti + ; + public void test(final Class clazz) { final Predicate predicateAcceptingAllFields = FieldPredicate.includeAllFields(clazz); test(clazz, predicateAcceptingAllFields); diff --git a/src/main/java/pl/pojo/tester/internal/utils/MethodUtils.java b/src/main/java/pl/pojo/tester/internal/utils/MethodUtils.java index 86b2b4c4..bb87d2cf 100644 --- a/src/main/java/pl/pojo/tester/internal/utils/MethodUtils.java +++ b/src/main/java/pl/pojo/tester/internal/utils/MethodUtils.java @@ -55,19 +55,20 @@ private static boolean prefixMatchesGettersPrefixAndHasExpectedLength(final Meth final Class returnType = method.getReturnType(); final String methodName = method.getName(); final int fieldNameLength = fieldName.length(); - final String upperCaseFirstLetterfieldName = upperCaseFirstLetter(fieldName); + final String upperCaseFirstLetterFieldName = upperCaseFirstLetter(fieldName); if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) { return (methodName.startsWith("is") && methodName.equals(fieldName)) - || ((methodName.endsWith(upperCaseFirstLetterfieldName)) + || ((methodName.endsWith(upperCaseFirstLetterFieldName)) && ((methodName.startsWith("is") && (methodName.length() == (fieldNameLength + 2))) || (methodName.startsWith("has") && (methodName.length() == (fieldNameLength + 3))) || (methodName.startsWith("get") && (methodName.length() == (fieldNameLength + 3))) || (methodName.startsWith("have") && (methodName.length() == (fieldNameLength + 4))) || (methodName.startsWith("contains") && (methodName.length() == (fieldNameLength + 8))))); } else { - return methodName.startsWith("get") && methodName.length() == fieldNameLength + 3 && methodName.endsWith( - upperCaseFirstLetterfieldName); + return methodName.startsWith("get") + && methodName.length() == fieldNameLength + 3 + && methodName.endsWith(upperCaseFirstLetterFieldName); } } @@ -83,8 +84,9 @@ private static boolean prefixMatchesSettersPrefixAndHasExpectedLength(final Meth return methodName.startsWith("set") && methodName.endsWith(fieldNameWithoutPrefix); } else { - return methodName.startsWith("set") && methodName.length() == fieldNameLength + 3 && methodName.endsWith( - upperCaseFirstLetterFieldName); + return methodName.startsWith("set") + && methodName.length() == fieldNameLength + 3 + && methodName.endsWith(upperCaseFirstLetterFieldName); } } diff --git a/src/test/java/pl/pojo/tester/api/DefaultPackageFilterTest.java b/src/test/java/pl/pojo/tester/api/DefaultPackageFilterTest.java index 6be0366c..f8381557 100644 --- a/src/test/java/pl/pojo/tester/api/DefaultPackageFilterTest.java +++ b/src/test/java/pl/pojo/tester/api/DefaultPackageFilterTest.java @@ -51,6 +51,6 @@ public void Should_Throw_Exception_When_Invalid_Package_Name() { .getClasses()); // then - assertThat(result).isInstanceOf(PacakgeFilterException.class); + assertThat(result).isInstanceOf(PackageFilterException.class); } } \ No newline at end of file