use of com.tngtech.archunit.core.domain.JavaField in project ArchUnit by TNG.
the class ClassFileImporterTest method handles_synthetic_modifiers.
@Test
public void handles_synthetic_modifiers() {
JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/syntheticimport"));
JavaField syntheticField = getOnlyElement(classes.get(ClassWithSynthetics.ClassWithSyntheticField.class).getFields());
assertThat(syntheticField.getModifiers()).as("modifiers of field in ClassWithSynthetics.ClassWithSyntheticField").contains(SYNTHETIC);
JavaMethod syntheticMethod = getMethodWithReturnType(classes.get(ClassWithSynthetics.ClassWithSyntheticMethod.class), Object.class);
assertThat(syntheticMethod.getModifiers()).as("modifiers of method in ClassWithSynthetics.ClassWithSyntheticMethod").contains(SYNTHETIC);
JavaMethod compareMethod = classes.get(ClassWithSynthetics.class).getMethod("compare", Object.class, Object.class);
assertThat(compareMethod.getModifiers()).as("modifiers of bridge method in ClassWithSynthetics").contains(BRIDGE, SYNTHETIC);
}
use of com.tngtech.archunit.core.domain.JavaField in project AngularPortfolioMgr by Angular2Guy.
the class MyArchitectureTests method createNoFieldInjectionRule.
private static ArchRule createNoFieldInjectionRule() {
ArchCondition<JavaField> annotatedWithSpringAutowired = beAnnotatedWith("org.springframework.beans.factory.annotation.Autowired");
ArchCondition<JavaField> annotatedWithGuiceInject = beAnnotatedWith("com.google.inject.Inject");
ArchCondition<JavaField> annotatedWithJakartaInject = beAnnotatedWith("javax.inject.Inject");
ArchRule beAnnotatedWithAnInjectionAnnotation = ArchRuleDefinition.noFields().should(annotatedWithSpringAutowired.or(annotatedWithGuiceInject).or(annotatedWithJakartaInject).as("be annotated with an injection annotation"));
return beAnnotatedWithAnInjectionAnnotation;
}
use of com.tngtech.archunit.core.domain.JavaField in project AngularAndSpring by Angular2Guy.
the class MyArchitectureTests method createNoFieldInjectionRule.
private static ArchRule createNoFieldInjectionRule() {
ArchCondition<JavaField> annotatedWithSpringAutowired = beAnnotatedWith("org.springframework.beans.factory.annotation.Autowired");
ArchCondition<JavaField> annotatedWithGuiceInject = beAnnotatedWith("com.google.inject.Inject");
ArchCondition<JavaField> annotatedWithJakartaInject = beAnnotatedWith("javax.inject.Inject");
ArchRule beAnnotatedWithAnInjectionAnnotation = ArchRuleDefinition.noFields().should(annotatedWithSpringAutowired.or(annotatedWithGuiceInject).or(annotatedWithJakartaInject).as("be annotated with an injection annotation"));
return beAnnotatedWithAnInjectionAnnotation;
}
use of com.tngtech.archunit.core.domain.JavaField in project sirius-components by eclipse-sirius.
the class AbstractImmutableTests method haveAPublicGetter.
private ArchCondition<JavaField> haveAPublicGetter() {
return new // $NON-NLS-1$
ArchCondition<>(// $NON-NLS-1$
"have a public getter") {
@Override
public void check(JavaField javaField, ConditionEvents events) {
if (!javaField.getModifiers().contains(STATIC)) {
JavaClass javaClass = javaField.getOwner();
// $NON-NLS-1$
String getterName = "get" + javaField.getName().substring(0, 1).toUpperCase() + javaField.getName().substring(1);
if (javaField.getRawType().getFullName().equals("java.lang.Boolean") || javaField.getRawType().getFullName().equals("boolean")) {
// $NON-NLS-1$ //$NON-NLS-2$
// $NON-NLS-1$
getterName = "is" + javaField.getName().substring(0, 1).toUpperCase() + javaField.getName().substring(1);
}
boolean isConditionSatisfied = false;
try {
JavaMethod method = javaClass.getMethod(getterName);
isConditionSatisfied = method != null && method.getModifiers().contains(PUBLIC);
} catch (IllegalArgumentException exception) {
// Getter not found
isConditionSatisfied = false;
}
// $NON-NLS-1$
String message = "The field has a getter";
if (!isConditionSatisfied) {
// $NON-NLS-1$ //$NON-NLS-2$
message = "The field " + javaField.getFullName() + " does not have a getter";
}
events.add(new SimpleConditionEvent(javaField, isConditionSatisfied, message));
}
}
};
}
Aggregations