Skip to content

Commit

Permalink
Review: Minor class renaming
Browse files Browse the repository at this point in the history
I think `InnerMemberClass` is more narrow than `NonStaticNestedClass`, because technically a local or anonymous class also is a non-static nested class. It might not always be relevant in the context, but `InnerMemberClass` at least gives me a quick understanding of exactly what type of class this is. Also `ClassAccessingLocalClass` is AFAIS a `ClassBeingAccessedByLocalClass` (it does not access the local class, but vice versa, and this is also correct for the test).

Signed-off-by: Peter Gafert <[email protected]>
  • Loading branch information
codecholeric committed Jan 10, 2020
1 parent 6c75e21 commit 264220f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1491,12 +1491,12 @@ public void notBeMemberClasses(ArchRule rule, Class<?> satisfied, Class<?> viola

@DataProvider
public static Object[][] beInnerClasses_rules() {
Class<?> nonStaticNestedClass = NestedClassWithSomeMoreClasses.NonStaticNestedClass.class;
Class<?> innerMemberClass = NestedClassWithSomeMoreClasses.InnerMemberClass.class;
Class<?> staticNestedClass = NestedClassWithSomeMoreClasses.StaticNestedClass.class;

return $$(
$(classes().should().beInnerClasses(), nonStaticNestedClass, staticNestedClass),
$(classes().should(ArchConditions.beInnerClasses()), nonStaticNestedClass, staticNestedClass)
$(classes().should().beInnerClasses(), innerMemberClass, staticNestedClass),
$(classes().should(ArchConditions.beInnerClasses()), innerMemberClass, staticNestedClass)
);
}

Expand All @@ -1513,7 +1513,7 @@ public void beInnerClasses(ArchRule rule, Class<?> satisfied, Class<?> violated)

@DataProvider
public static Object[][] notBeInnerClasses_rules() {
Class<?> nonStaticNestedClass = NestedClassWithSomeMoreClasses.NonStaticNestedClass.class;
Class<?> nonStaticNestedClass = NestedClassWithSomeMoreClasses.InnerMemberClass.class;
Class<?> staticNestedClass = NestedClassWithSomeMoreClasses.StaticNestedClass.class;

return $$(
Expand Down Expand Up @@ -1952,7 +1952,7 @@ static class StaticNestedClass {
}

@SuppressWarnings("InnerClassMayBeStatic")
class NonStaticNestedClass {
class InnerMemberClass {
}

static Class<?> getAnonymousClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public void areNotEnums_predicate() {
public void areTopLevelClasses_predicate() {
List<JavaClass> classes = filterResultOf(classes().that().areTopLevelClasses())
.on(List.class, Map.class, Map.Entry.class, NestedClassWithSomeMoreClasses.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.NonStaticNestedClass.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.InnerMemberClass.class,
NestedClassWithSomeMoreClasses.getAnonymousClass(), NestedClassWithSomeMoreClasses.getLocalClass());

assertThatClasses(classes).matchInAnyOrder(List.class, Map.class);
Expand All @@ -668,33 +668,33 @@ public void areTopLevelClasses_predicate() {
public void areNotTopLevelClasses_predicate() {
List<JavaClass> classes = filterResultOf(classes().that().areNotTopLevelClasses())
.on(List.class, Map.class, Map.Entry.class, NestedClassWithSomeMoreClasses.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.NonStaticNestedClass.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.InnerMemberClass.class,
NestedClassWithSomeMoreClasses.getAnonymousClass(), NestedClassWithSomeMoreClasses.getLocalClass());

assertThatClasses(classes)
.matchInAnyOrder(Map.Entry.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());
}

@Test
public void areNestedClasses_predicate() {
List<JavaClass> classes = filterResultOf(classes().that().areNestedClasses())
.on(List.class, Map.class, Map.Entry.class, NestedClassWithSomeMoreClasses.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.NonStaticNestedClass.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.InnerMemberClass.class,
NestedClassWithSomeMoreClasses.getAnonymousClass(), NestedClassWithSomeMoreClasses.getLocalClass());

assertThatClasses(classes)
.matchInAnyOrder(Map.Entry.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());
}

@Test
public void areNotNestedClasses_predicate() {
List<JavaClass> classes = filterResultOf(classes().that().areNotNestedClasses())
.on(List.class, Map.class, Map.Entry.class, NestedClassWithSomeMoreClasses.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.NonStaticNestedClass.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.InnerMemberClass.class,
NestedClassWithSomeMoreClasses.getAnonymousClass(), NestedClassWithSomeMoreClasses.getLocalClass());

assertThatClasses(classes).matchInAnyOrder(List.class, Map.class);
Expand All @@ -704,19 +704,19 @@ public void areNotNestedClasses_predicate() {
public void areMemberClasses_predicate() {
List<JavaClass> classes = filterResultOf(classes().that().areMemberClasses())
.on(List.class, Map.class, Map.Entry.class, NestedClassWithSomeMoreClasses.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.NonStaticNestedClass.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.InnerMemberClass.class,
NestedClassWithSomeMoreClasses.getAnonymousClass(), NestedClassWithSomeMoreClasses.getLocalClass());

assertThatClasses(classes)
.matchInAnyOrder(Map.Entry.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class);
NestedClassWithSomeMoreClasses.InnerMemberClass.class);
}

@Test
public void areNotMemberClasses_predicate() {
List<JavaClass> classes = filterResultOf(classes().that().areNotMemberClasses())
.on(List.class, Map.class, Map.Entry.class, NestedClassWithSomeMoreClasses.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.NonStaticNestedClass.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.InnerMemberClass.class,
NestedClassWithSomeMoreClasses.getAnonymousClass(), NestedClassWithSomeMoreClasses.getLocalClass());

assertThatClasses(classes).matchInAnyOrder(List.class, Map.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
Expand All @@ -727,19 +727,19 @@ public void areNotMemberClasses_predicate() {
public void areInnerClasses_predicate() {
List<JavaClass> classes = filterResultOf(classes().that().areInnerClasses())
.on(List.class, Map.class, Map.Entry.class, NestedClassWithSomeMoreClasses.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.NonStaticNestedClass.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.InnerMemberClass.class,
NestedClassWithSomeMoreClasses.getAnonymousClass(), NestedClassWithSomeMoreClasses.getLocalClass());

assertThatClasses(classes)
.matchInAnyOrder(NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
.matchInAnyOrder(NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());
}

@Test
public void areNotInnerClasses_predicate() {
List<JavaClass> classes = filterResultOf(classes().that().areNotInnerClasses())
.on(List.class, Map.class, Map.Entry.class, NestedClassWithSomeMoreClasses.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.NonStaticNestedClass.class,
NestedClassWithSomeMoreClasses.StaticNestedClass.class, NestedClassWithSomeMoreClasses.InnerMemberClass.class,
NestedClassWithSomeMoreClasses.getAnonymousClass(), NestedClassWithSomeMoreClasses.getLocalClass());

assertThatClasses(classes).matchInAnyOrder(List.class, Map.class, Map.Entry.class, NestedClassWithSomeMoreClasses.class,
Expand Down Expand Up @@ -911,7 +911,7 @@ static class StaticNestedClass {
}

@SuppressWarnings("InnerClassMayBeStatic")
class NonStaticNestedClass {
class InnerMemberClass {
}

static Class<?> getAnonymousClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ public void areNotEnums_predicate() {
public void areTopLevelClasses_predicate() {
List<JavaMember> members = filterResultOf(members().that().areDeclaredInClassesThat().areTopLevelClasses())
.on(String.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());

assertThatMembers(members).matchInAnyOrderMembersOf(String.class);
Expand All @@ -665,33 +665,33 @@ public void areTopLevelClasses_predicate() {
public void areNotTopLevelClasses_predicate() {
List<JavaMember> members = filterResultOf(members().that().areDeclaredInClassesThat().areNotTopLevelClasses())
.on(String.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());

assertThatMembers(members)
.matchInAnyOrderMembersOf(NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());
}

@Test
public void areNestedClasses_predicate() {
List<JavaMember> members = filterResultOf(members().that().areDeclaredInClassesThat().areNestedClasses())
.on(String.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());

assertThatMembers(members)
.matchInAnyOrderMembersOf(NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());
}

@Test
public void areNotNestedClasses_predicate() {
List<JavaMember> members = filterResultOf(members().that().areDeclaredInClassesThat().areNotNestedClasses())
.on(String.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());

assertThatMembers(members).matchInAnyOrderMembersOf(String.class);
Expand All @@ -701,19 +701,19 @@ public void areNotNestedClasses_predicate() {
public void areMemberClasses_predicate() {
List<JavaMember> members = filterResultOf(members().that().areDeclaredInClassesThat().areMemberClasses())
.on(String.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());

assertThatMembers(members)
.matchInAnyOrderMembersOf(NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class);
NestedClassWithSomeMoreClasses.InnerMemberClass.class);
}

@Test
public void areNotMemberClasses_predicate() {
List<JavaMember> members = filterResultOf(members().that().areDeclaredInClassesThat().areNotMemberClasses())
.on(String.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());

assertThatMembers(members).matchInAnyOrderMembersOf(String.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
Expand All @@ -724,18 +724,18 @@ public void areNotMemberClasses_predicate() {
public void areInnerClasses_predicate() {
List<JavaMember> members = filterResultOf(members().that().areDeclaredInClassesThat().areInnerClasses())
.on(String.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());

assertThatMembers(members).matchInAnyOrderMembersOf(NestedClassWithSomeMoreClasses.NonStaticNestedClass.class,
assertThatMembers(members).matchInAnyOrderMembersOf(NestedClassWithSomeMoreClasses.InnerMemberClass.class,
NestedClassWithSomeMoreClasses.getAnonymousClass(), NestedClassWithSomeMoreClasses.getLocalClass());
}

@Test
public void areNotInnerClasses_predicate() {
List<JavaMember> members = filterResultOf(members().that().areDeclaredInClassesThat().areNotInnerClasses())
.on(String.class, NestedClassWithSomeMoreClasses.class, NestedClassWithSomeMoreClasses.StaticNestedClass.class,
NestedClassWithSomeMoreClasses.NonStaticNestedClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.InnerMemberClass.class, NestedClassWithSomeMoreClasses.getAnonymousClass(),
NestedClassWithSomeMoreClasses.getLocalClass());

assertThatMembers(members)
Expand Down Expand Up @@ -905,7 +905,7 @@ static class StaticNestedClass {
}

@SuppressWarnings("InnerClassMayBeStatic")
class NonStaticNestedClass {
class InnerMemberClass {
String member;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,17 +837,17 @@ public void areNotMemberClasses_predicate(ClassesThat<ClassesShouldConjunction>
public void areInnerClasses_predicate(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
Set<JavaClass> classes = filterClassesAppearingInFailureReport(
noClassesShouldThatRuleStart.areInnerClasses())
.on(ClassAccessingNonStaticNestedClass.class, ClassAccessingTopLevelClass.class);
.on(ClassAccessingInnerMemberClass.class, ClassAccessingTopLevelClass.class);

assertThatClasses(classes).matchInAnyOrder(ClassAccessingNonStaticNestedClass.class);
assertThatClasses(classes).matchInAnyOrder(ClassAccessingInnerMemberClass.class);
}

@Test
@UseDataProvider("no_classes_should_that_rule_starts")
public void areNotInnerClasses_predicate(ClassesThat<ClassesShouldConjunction> noClassesShouldThatRuleStart) {
Set<JavaClass> classes = filterClassesAppearingInFailureReport(
noClassesShouldThatRuleStart.areNotInnerClasses())
.on(ClassAccessingNonStaticNestedClass.class, ClassAccessingTopLevelClass.class);
.on(ClassAccessingInnerMemberClass.class, ClassAccessingTopLevelClass.class);

assertThatClasses(classes).matchInAnyOrder(ClassAccessingTopLevelClass.class);
}
Expand Down Expand Up @@ -1821,14 +1821,14 @@ static void access() {
}
}

private static class ClassAccessingNonStaticNestedClass {
private static class ClassAccessingInnerMemberClass {
@SuppressWarnings("unused")
void access() {
new NonStaticNestedClass().access();
new InnerMemberClass().access();
}

@SuppressWarnings("InnerClassMayBeStatic")
private class NonStaticNestedClass {
private class InnerMemberClass {
void access() {
}
}
Expand Down
Loading

0 comments on commit 264220f

Please sign in to comment.