|
205 | 205 | import static com.tngtech.archunit.testutil.ReflectionTestUtils.field;
|
206 | 206 | import static com.tngtech.archunit.testutil.ReflectionTestUtils.method;
|
207 | 207 | import static com.tngtech.archunit.testutil.TestUtils.namesOf;
|
| 208 | +import static com.tngtech.java.junit.dataprovider.DataProviders.$; |
| 209 | +import static com.tngtech.java.junit.dataprovider.DataProviders.$$; |
208 | 210 | import static com.tngtech.java.junit.dataprovider.DataProviders.testForEach;
|
209 | 211 | import static java.nio.charset.StandardCharsets.UTF_8;
|
210 | 212 | import static org.junit.Assume.assumeTrue;
|
@@ -1711,6 +1713,48 @@ public void resolve_missing_dependencies_from_classpath_can_be_toogled() throws
|
1711 | 1713 | assertThat(clazz.getSuperClass().get().getMethods()).isEmpty();
|
1712 | 1714 | }
|
1713 | 1715 |
|
| 1716 | + @DataProvider |
| 1717 | + public static Object[][] classes_not_directly_imported() { |
| 1718 | + class Element { |
| 1719 | + } |
| 1720 | + @SuppressWarnings("unused") |
| 1721 | + class DependsOnArray { |
| 1722 | + Element[] array; |
| 1723 | + } |
| 1724 | + ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(true); |
| 1725 | + JavaClass resolvedFromClasspath = new ClassFileImporter().importClasses(DependsOnArray.class) |
| 1726 | + .get(DependsOnArray.class).getField("array").getRawType().getComponentType(); |
| 1727 | + |
| 1728 | + ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(false); |
| 1729 | + JavaClass stub = new ClassFileImporter().importClasses(DependsOnArray.class) |
| 1730 | + .get(DependsOnArray.class).getField("array").getRawType().getComponentType(); |
| 1731 | + |
| 1732 | + return $$( |
| 1733 | + $("Resolved from classpath", resolvedFromClasspath), |
| 1734 | + $("Stub class", stub) |
| 1735 | + ); |
| 1736 | + } |
| 1737 | + |
| 1738 | + @Test |
| 1739 | + @UseDataProvider("classes_not_directly_imported") |
| 1740 | + public void classes_not_directly_imported_have_empty_dependencies(@SuppressWarnings("unused") String description, JavaClass notDirectlyImported) { |
| 1741 | + assertThat(notDirectlyImported.getDirectDependenciesFromSelf()).isEmpty(); |
| 1742 | + assertThat(notDirectlyImported.getDirectDependenciesToSelf()).isEmpty(); |
| 1743 | + assertThat(notDirectlyImported.getFieldAccessesToSelf()).isEmpty(); |
| 1744 | + assertThat(notDirectlyImported.getMethodCallsToSelf()).isEmpty(); |
| 1745 | + assertThat(notDirectlyImported.getConstructorCallsToSelf()).isEmpty(); |
| 1746 | + assertThat(notDirectlyImported.getAccessesToSelf()).isEmpty(); |
| 1747 | + assertThat(notDirectlyImported.getFieldsWithTypeOfSelf()).isEmpty(); |
| 1748 | + assertThat(notDirectlyImported.getMethodsWithParameterTypeOfSelf()).isEmpty(); |
| 1749 | + assertThat(notDirectlyImported.getMethodsWithReturnTypeOfSelf()).isEmpty(); |
| 1750 | + assertThat(notDirectlyImported.getMethodThrowsDeclarationsWithTypeOfSelf()).isEmpty(); |
| 1751 | + assertThat(notDirectlyImported.getConstructorsWithParameterTypeOfSelf()).isEmpty(); |
| 1752 | + assertThat(notDirectlyImported.getConstructorsWithThrowsDeclarationTypeOfSelf()).isEmpty(); |
| 1753 | + assertThat(notDirectlyImported.getAnnotationsWithTypeOfSelf()).isEmpty(); |
| 1754 | + assertThat(notDirectlyImported.getAnnotationsWithParameterTypeOfSelf()).isEmpty(); |
| 1755 | + assertThat(notDirectlyImported.getInstanceofChecksWithTypeOfSelf()).isEmpty(); |
| 1756 | + } |
| 1757 | + |
1714 | 1758 | @Test
|
1715 | 1759 | public void import_is_resilient_against_broken_class_files() throws Exception {
|
1716 | 1760 | Class<?> expectedClass = getClass();
|
|
0 commit comments