Skip to content

Commit

Permalink
Reuse supplied import options in ClassFileImporter.importClasspath()
Browse files Browse the repository at this point in the history
Before this commit, all custom import options were ignored and replaced
with DO_NOT_INCLUDE_ARCHIVES.

From this commit on DO_NOT_INCLUDE_ARCHIVES will be added to the already
supplied import options.

Fixes TNG#296

Signed-off-by: Roland Weisleder <[email protected]>
  • Loading branch information
rweisleder authored and codecholeric committed Apr 11, 2020
1 parent 7fe9370 commit 2d5b17e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public JavaClasses importPackagesOf(Collection<Class<?>> classes) {
*/
@PublicAPI(usage = ACCESS)
public JavaClasses importClasspath() {
return importClasspath(new ImportOptions().with(ImportOption.Predefined.DO_NOT_INCLUDE_ARCHIVES));
return importClasspath(importOptions.with(ImportOption.Predefined.DO_NOT_INCLUDE_ARCHIVES));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static com.tngtech.archunit.core.domain.SourceTest.urlOf;
import static com.tngtech.archunit.core.importer.ClassFileImporterTest.jarFileOf;
import static com.tngtech.archunit.core.importer.ImportOption.Predefined.DO_NOT_INCLUDE_TESTS;
import static com.tngtech.archunit.testutil.Assertions.assertThat;
import static com.tngtech.archunit.testutil.Assertions.assertThatClasses;

Expand All @@ -40,6 +41,14 @@ public void imports_the_classpath() {
assertThatClasses(javaBaseClasses).doNotContain(ClassFileImporter.class, getClass(), Rule.class);
}

@Test
public void respects_ImportOptions_when_using_the_default_importClasspath_method() {
JavaClasses classes = new ClassFileImporter().withImportOption(DO_NOT_INCLUDE_TESTS).importClasspath();

assertThatClasses(classes).contain(ClassFileImporter.class);
assertThatClasses(classes).doNotContain(getClass(), Rule.class, String.class);
}

@Test
public void imports_packages() {
JavaClasses classes = new ClassFileImporter().importPackages(
Expand Down

0 comments on commit 2d5b17e

Please sign in to comment.