Skip to content

Commit

Permalink
fix formatting with 'mvn spotless:apply'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Dos Santos authored and jqno committed Apr 19, 2021
1 parent a369c9c commit 2ff8f10
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 61 deletions.
5 changes: 4 additions & 1 deletion src/main/java/nl/jqno/equalsverifier/EqualsVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ public static MultipleTypeEqualsVerifierApi forPackage(String packageName) {
* @param scanRecursively true to scan all sub-packages
* @return A fluent API for EqualsVerifier.
*/
public static MultipleTypeEqualsVerifierApi forPackage(String packageName, boolean scanRecursively) {
public static MultipleTypeEqualsVerifierApi forPackage(
String packageName,
boolean scanRecursively
) {
List<Class<?>> classes = PackageScanner.getClassesIn(packageName, scanRecursively);
Validations.validatePackageContainsClasses(packageName, classes);
return new MultipleTypeEqualsVerifierApi(classes, new ConfiguredEqualsVerifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,29 @@ private static List<File> getDirs(String packageName) {
);
}

private static List<Class<?>> getClassesInDir(String packageName, File dir, boolean scanRecursively) {
private static List<Class<?>> getClassesInDir(
String packageName,
File dir,
boolean scanRecursively
) {
if (!dir.exists()) {
return Collections.emptyList();
}
return Arrays
.stream(dir.listFiles())
.filter(f -> (scanRecursively && f.isDirectory()) || f.getName().endsWith(".class"))
.flatMap(f -> {
List<Class<?>> classes;
if(f.isDirectory()) {
classes = getClassesInDir(packageName + "." + f.getName(), f, scanRecursively);
} else {
classes = Collections.singletonList(fileToClass(packageName, f));
.flatMap(
f -> {
List<Class<?>> classes;
if (f.isDirectory()) {
classes =
getClassesInDir(packageName + "." + f.getName(), f, scanRecursively);
} else {
classes = Collections.singletonList(fileToClass(packageName, f));
}
return classes.stream();
}
return classes.stream();
})
)
.filter(c -> !c.getName().endsWith("Test"))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ public void fail_whenVerifyingAPackageWithTwoIncorrectClasses() {
@Test
public void fail_whenVerifyingAPackageRecursivelyWithFourIncorrectClasses() {
ExpectedException
.when(() -> EqualsVerifier.forPackage(INCORRECT_PACKAGE, true).verify())
.assertFailure()
.assertMessageContains(
"EqualsVerifier found a problem in 4 classes.",
"* " + INCORRECT_M,
"* " + INCORRECT_N,
"* " + INCORRECT_O,
"* " + INCORRECT_P,
"Subclass: equals is not final.",
"Reflexivity: object does not equal itself:"
);
.when(() -> EqualsVerifier.forPackage(INCORRECT_PACKAGE, true).verify())
.assertFailure()
.assertMessageContains(
"EqualsVerifier found a problem in 4 classes.",
"* " + INCORRECT_M,
"* " + INCORRECT_N,
"* " + INCORRECT_O,
"* " + INCORRECT_P,
"Subclass: equals is not final.",
"Reflexivity: object does not equal itself:"
);
}

@Test
Expand All @@ -130,17 +130,17 @@ public void fail_whenCallingForPackage_givenTwoClassesInPackageAreIncorrect() {
@Test
public void fail_whenCallingForPackageRecursively_givenFourClassesInPackageAreIncorrect() {
ExpectedException
.when(() -> EqualsVerifier.forPackage(INCORRECT_PACKAGE, true).verify())
.assertFailure()
.assertMessageContains(
"EqualsVerifier found a problem in 4 classes.",
"IncorrectM",
"IncorrectN",
"IncorrectO",
"IncorrectP",
"Subclass: equals is not final.",
"Reflexivity: object does not equal itself:"
);
.when(() -> EqualsVerifier.forPackage(INCORRECT_PACKAGE, true).verify())
.assertFailure()
.assertMessageContains(
"EqualsVerifier found a problem in 4 classes.",
"IncorrectM",
"IncorrectN",
"IncorrectO",
"IncorrectP",
"Subclass: equals is not final.",
"Reflexivity: object does not equal itself:"
);
}

@Test
Expand All @@ -157,12 +157,12 @@ public void fail_whenCallingForPackage_whenPackageHasNoClasses() {
@Test
public void fail_whenCallingForPackageRecursively_whenPackageHasNoClasses() {
ExpectedException
.when(() -> EqualsVerifier.forPackage("nl.jqno.equalsverifier.doesnotexist", true))
.assertThrows(IllegalStateException.class)
.assertMessageContains(
"nl.jqno.equalsverifier.doesnotexist",
"doesn't contain any (non-Test) types"
);
.when(() -> EqualsVerifier.forPackage("nl.jqno.equalsverifier.doesnotexist", true))
.assertThrows(IllegalStateException.class)
.assertMessageContains(
"nl.jqno.equalsverifier.doesnotexist",
"doesn't contain any (non-Test) types"
);
}

@Test
Expand All @@ -176,9 +176,9 @@ public void succeed_whenCallingForPackageOnAPackageContainingFailingClasses_give
@Test
public void succeed_whenCallingForPackageRecursivelyOnAPackageContainingFailingClasses_givenFailingClassesAreExcepted() {
EqualsVerifier
.forPackage(INCORRECT_PACKAGE, true)
.except(IncorrectM.class, IncorrectN.class, IncorrectO.class, IncorrectP.class)
.verify();
.forPackage(INCORRECT_PACKAGE, true)
.except(IncorrectM.class, IncorrectN.class, IncorrectO.class, IncorrectP.class)
.verify();
}

@Test
Expand All @@ -192,9 +192,9 @@ public void fail_whenExceptingAClassThatDoesntExistInThePackage() {
@Test
public void fail_whenExceptingAClassThatDoesntExistInThePackageAndSubPackages() {
ExpectedException
.when(() -> EqualsVerifier.forPackage(CORRECT_PACKAGE, true).except(IncorrectM.class))
.assertThrows(IllegalStateException.class)
.assertMessageContains("Unknown class(es) found", "IncorrectM");
.when(() -> EqualsVerifier.forPackage(CORRECT_PACKAGE, true).except(IncorrectM.class))
.assertThrows(IllegalStateException.class)
.assertMessageContains("Unknown class(es) found", "IncorrectM");
}

@Test
Expand All @@ -208,9 +208,9 @@ public void succeed_whenCallingForPackageOnAPackageContainingFailingClasses_give
@Test
public void succeed_whenCallingForPackageRecursivelyOnAPackageContainingFailingClasses_givenFailingClassesAreExceptedByPredicate() {
EqualsVerifier
.forPackage(INCORRECT_PACKAGE, true)
.except(c -> c.getSimpleName().contains("Incorrect"))
.verify();
.forPackage(INCORRECT_PACKAGE, true)
.except(c -> c.getSimpleName().contains("Incorrect"))
.verify();
}

@Test
Expand All @@ -224,9 +224,11 @@ public void fail_whenCallingForPackageOnAPackageContainingFailingClasses_givenFa
@Test
public void fail_whenCallingForPackageRecursivelyOnAPackageContainingFailingClasses_givenFailingClassesAreNotExceptedByPredicate() {
ExpectedException
.when(() -> EqualsVerifier.forPackage(INCORRECT_PACKAGE, true).except(c -> false).verify())
.assertFailure()
.assertMessageContains("EqualsVerifier found a problem in 4 classes");
.when(
() -> EqualsVerifier.forPackage(INCORRECT_PACKAGE, true).except(c -> false).verify()
)
.assertFailure()
.assertMessageContains("EqualsVerifier found a problem in 4 classes");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@ public void coverTheConstructor() {
@Test
public void happyPath() {
List<Class<?>> classes = PackageScanner.getClassesIn(
"nl.jqno.equalsverifier.testhelpers.packages.correct", false);
"nl.jqno.equalsverifier.testhelpers.packages.correct",
false
);
classes.sort((a, b) -> a.getName().compareTo(b.getName()));
assertEquals(Arrays.asList(A.class, B.class, C.class), classes);
}

@Test
public void happyPathRecursively() {
List<Class<?>> classes = PackageScanner.getClassesIn(
"nl.jqno.equalsverifier.testhelpers.packages.correct", true);
"nl.jqno.equalsverifier.testhelpers.packages.correct",
true
);
classes.sort(Comparator.comparing(Class::getName));
assertEquals(Arrays.asList(
assertEquals(
Arrays.asList(
A.class,
B.class,
C.class,
Expand All @@ -41,13 +46,17 @@ public void happyPathRecursively() {
nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage.subpackage.A.class,
nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage.subpackage.B.class,
nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage.subpackage.D.class
), classes);
),
classes
);
}

@Test
public void filterOutTestClasses() {
List<Class<?>> classes = PackageScanner.getClassesIn(
"nl.jqno.equalsverifier.internal.reflection", false);
"nl.jqno.equalsverifier.internal.reflection",
false
);
List<Class<?>> testClasses = classes
.stream()
.filter(c -> c.getName().endsWith("Test"))
Expand All @@ -59,26 +68,32 @@ public void filterOutTestClasses() {
@Test
public void filterOutTestClassesRecursively() {
List<Class<?>> classes = PackageScanner.getClassesIn(
"nl.jqno.equalsverifier.internal.reflection", true);
"nl.jqno.equalsverifier.internal.reflection",
true
);
List<Class<?>> testClasses = classes
.stream()
.filter(c -> c.getName().endsWith("Test"))
.collect(Collectors.toList());
.stream()
.filter(c -> c.getName().endsWith("Test"))
.collect(Collectors.toList());
assertEquals(Collections.emptyList(), testClasses);
assertTrue(classes.size() - testClasses.size() > 0);
}

@Test
public void nonexistentPackage() {
List<Class<?>> classes = PackageScanner.getClassesIn(
"nl.jqno.equalsverifier.nonexistentpackage", false);
"nl.jqno.equalsverifier.nonexistentpackage",
false
);
assertEquals(Collections.emptyList(), classes);
}

@Test
public void nonexistentPackageAndSubPackage() {
List<Class<?>> classes = PackageScanner.getClassesIn(
"nl.jqno.equalsverifier.nonexistentpackage", true);
"nl.jqno.equalsverifier.nonexistentpackage",
true
);
assertEquals(Collections.emptyList(), classes);
}
}

0 comments on commit 2ff8f10

Please sign in to comment.