Skip to content

Commit

Permalink
Fix Review Aftermath:
Browse files Browse the repository at this point in the history
- Class naming in test was confused
- Workaround for JDK < 11 Javadoc arity bug (anonymous classes with varargs constructor crash javadoc tool)

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
  • Loading branch information
codecholeric committed Jul 29, 2019
1 parent b8890f4 commit d01365f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -906,14 +906,7 @@ private static class HaveOnlyModifiersCondition<T extends HasModifiers & HasDesc
private final Function<JavaClass, ? extends Collection<T>> getHasModifiers;

HaveOnlyModifiersCondition(String description, final JavaModifier modifier, Function<JavaClass, ? extends Collection<T>> getHasModifiers) {
super("have only " + description, new ArchCondition<T>("") {
@Override
public void check(T hasModifiers, ConditionEvents events) {
boolean satisfied = hasModifiers.getModifiers().contains(modifier);
String infix = (satisfied ? "is " : "is not ") + modifier.toString().toLowerCase();
events.add(new SimpleConditionEvent(hasModifiers, satisfied, createMessage(hasModifiers, infix)));
}
});
super("have only " + description, new ModifierCondition<T>(modifier));
this.getHasModifiers = getHasModifiers;
}

Expand All @@ -923,6 +916,22 @@ Collection<T> relevantAttributes(JavaClass javaClass) {
}
}

private static class ModifierCondition<T extends HasModifiers & HasDescription & HasSourceCodeLocation> extends ArchCondition<T> {
private final JavaModifier modifier;

ModifierCondition(JavaModifier modifier) {
super("modifier " + modifier);
this.modifier = modifier;
}

@Override
public void check(T hasModifiers, ConditionEvents events) {
boolean satisfied = hasModifiers.getModifiers().contains(modifier);
String infix = (satisfied ? "is " : "is not ") + modifier.toString().toLowerCase();
events.add(new SimpleConditionEvent(hasModifiers, satisfied, createMessage(hasModifiers, infix)));
}
}

private static class ImplementsCondition extends ArchCondition<JavaClass> {
private final DescribedPredicate<? super JavaClass> implement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;

import static com.google.common.collect.Iterables.getOnlyElement;
import static com.tngtech.archunit.core.domain.JavaClass.Functions.GET_CODE_UNITS;
import static com.tngtech.archunit.core.domain.JavaClass.Functions.GET_CONSTRUCTORS;
import static com.tngtech.archunit.core.domain.JavaClass.Functions.GET_FIELDS;
import static com.tngtech.archunit.core.domain.JavaClass.Functions.GET_MEMBERS;
import static com.tngtech.archunit.core.domain.JavaClass.Functions.GET_METHODS;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.INTERFACES;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.assignableFrom;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.assignableTo;
Expand Down Expand Up @@ -107,7 +107,7 @@ public void finds_fields_and_methods() {

@Test
public void finds_constructors() {
JavaClass javaClass = importClassWithContext(ClassWithSeveralConstructors.class);
JavaClass javaClass = importClassWithContext(ClassWithSeveralConstructorsFieldsAndMethods.class);

assertThat(javaClass.getConstructors()).hasSize(3);
assertThat(javaClass.getConstructors()).is(containing(codeUnitWithSignature(CONSTRUCTOR_NAME)));
Expand Down Expand Up @@ -1011,6 +1011,7 @@ public Object objectMethod() {
}
}

@SuppressWarnings("unused")
interface InterfaceWithMethod {
Object objectMethod();
}
Expand All @@ -1020,17 +1021,17 @@ abstract static class Parent {
}

@SuppressWarnings("unused")
static class ClassWithSeveralConstructors {
static class ClassWithSeveralConstructorsFieldsAndMethods {
String stringField;
private int intField;

private ClassWithSeveralConstructors() {
private ClassWithSeveralConstructorsFieldsAndMethods() {
}

ClassWithSeveralConstructors(String string) {
ClassWithSeveralConstructorsFieldsAndMethods(String string) {
}

public ClassWithSeveralConstructors(int number, Object[] objects) {
public ClassWithSeveralConstructorsFieldsAndMethods(int number, Object[] objects) {
}

void voidMethod() {
Expand All @@ -1041,18 +1042,6 @@ protected String stringMethod() {
}
}

@SuppressWarnings("unused")
static class ClassWithSeveralConstructorsFieldsAndMethods {
private ClassWithSeveralConstructorsFieldsAndMethods() {
}

ClassWithSeveralConstructorsFieldsAndMethods(String string) {
}

public ClassWithSeveralConstructorsFieldsAndMethods(int number, Object[] objects) {
}
}

static class ClassWithInnerClass {
class Inner {
}
Expand Down Expand Up @@ -1082,6 +1071,7 @@ public void parentMethod() {
}
}

@SuppressWarnings("unused")
private static class ChildWithFieldAndMethod extends ParentWithFieldAndMethod {
static class Members {
// If we put this in the class, we affect tests for members
Expand All @@ -1102,6 +1092,7 @@ void childMethod(String param) {
}
}

@SuppressWarnings("unused")
private interface InterfaceWithFieldAndMethod {
class Members {
// If we put this in the class, we affect tests for members
Expand All @@ -1115,6 +1106,7 @@ class Members {
void parentMethod();
}

@SuppressWarnings("unused")
private static class ClassWithNamedAndAnonymousInnerClasses {
static final String name_of_fieldIndicatingOuterAnonymousInnerClass = "fieldIndicatingOuterAnonymousInnerClass";
static final String name_of_fieldIndicatingNestedAnonymousInnerClass = "fieldIndicatingNestedAnonymousInnerClass";
Expand Down

0 comments on commit d01365f

Please sign in to comment.