use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassCacheTest method if_whole_classpath_is_set_true_then_the_whole_classpath_is_imported.
@Test
public void if_whole_classpath_is_set_true_then_the_whole_classpath_is_imported() {
TestAnalysisRequest defaultOptions = new TestAnalysisRequest().withWholeClasspath(true);
Class<?>[] expectedImportResult = new Class[] { getClass() };
doReturn(new ClassFileImporter().importClasses(expectedImportResult)).when(cacheClassFileImporter).importClasses(any(ImportOptions.class), ArgumentMatchers.<Location>anyCollection());
JavaClasses classes = cache.getClassesToAnalyzeFor(TestClass.class, defaultOptions);
assertThatTypes(classes).matchExactly(expectedImportResult);
verify(cacheClassFileImporter).importClasses(any(ImportOptions.class), locationCaptor.capture());
assertThat(locationCaptor.getValue()).has(locationContaining("archunit")).has(locationContaining("asm")).has(locationContaining("google")).has(locationContaining("mockito"));
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterLambdaAccessesTest method imports_multiple_method_calls_from_single_lambda.
@Test
public void imports_multiple_method_calls_from_single_lambda() {
class Target {
void target() {
}
}
@SuppressWarnings("unused")
class Caller {
private Target target;
Runnable call() {
return () -> {
target.target();
target.target();
};
}
}
JavaClasses classes = new ClassFileImporter().importClasses(Target.class, Caller.class);
Set<JavaMethodCall> calls = classes.get(Caller.class).getMethodCallsFromSelf();
assertThat(calls).hasSize(2);
calls.forEach(call -> assertThatCall(call).isFrom("call").isTo(Target.class, "target"));
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterLambdaAccessesTest method imports_multiple_method_calls_from_multiple_lambda_in_one_method.
@Test
public void imports_multiple_method_calls_from_multiple_lambda_in_one_method() {
@SuppressWarnings("unused")
class Target {
Target target(String s) {
return this;
}
Target target(int i) {
return this;
}
}
@SuppressWarnings("unused")
class Caller {
private Target target;
Function<String, Target> call(int i) {
Function<Target, Target> function = t -> t.target(i);
return s -> target.target(s);
}
}
JavaClasses classes = new ClassFileImporter().importClasses(Target.class, Caller.class);
Set<JavaMethodCall> calls = classes.get(Caller.class).getMethodCallsFromSelf();
assertThat(filterOriginByName(calls, "call")).extracting(JavaMethodCall::getTarget).areExactly(1, targetCodeUnit("target", String.class)).areExactly(1, targetCodeUnit("target", int.class)).hasSize(2);
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterLambdaAccessesTest method imports_constructor_call_from_lambda_without_parameter.
@Test
public void imports_constructor_call_from_lambda_without_parameter() {
class Target {
}
@SuppressWarnings({ "unused", "Convert2MethodRef" })
class Caller {
Runnable call() {
return () -> new Target();
}
}
JavaClasses classes = new ClassFileImporter().importClasses(Target.class, Caller.class);
JavaConstructorCall call = getOnlyElement(filterOriginByName(classes.get(Caller.class).getConstructorCallsFromSelf(), "call"));
assertThatCall(call).isFrom("call").isTo(Target.class, CONSTRUCTOR_NAME, getClass());
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterLambdaAccessesTest method imports_method_call_from_lambda_with_parameter.
@Test
public void imports_method_call_from_lambda_with_parameter() {
@SuppressWarnings("unused")
class Target {
void target(String param) {
}
}
@SuppressWarnings("unused")
class Caller {
private Target target;
Consumer<String> call() {
return s -> target.target(s);
}
}
JavaClasses classes = new ClassFileImporter().importClasses(Target.class, Caller.class);
JavaMethodCall call = getOnlyElement(classes.get(Caller.class).getMethodCallsFromSelf());
assertThatCall(call).isFrom("call").isTo(Target.class, "target", String.class);
}
Aggregations