-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add method toClassDependencies() to JavaAccess and to SliceDependency #1250
Changes from all commits
0db41c8
7bfb09b
dc4da28
f46ca50
2d87914
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,18 @@ | |
import com.tngtech.archunit.core.domain.JavaAccess.Functions.Get; | ||
import com.tngtech.archunit.core.importer.testexamples.SomeClass; | ||
import com.tngtech.archunit.core.importer.testexamples.SomeEnum; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
|
||
import static com.google.common.collect.Iterables.getOnlyElement; | ||
import static com.tngtech.archunit.base.DescribedPredicate.alwaysFalse; | ||
import static com.tngtech.archunit.core.domain.TestUtils.importClassWithContext; | ||
import static com.tngtech.archunit.core.domain.TestUtils.importClassesWithContext; | ||
import static com.tngtech.archunit.core.domain.TestUtils.newMethodCallBuilder; | ||
import static com.tngtech.archunit.core.domain.TestUtils.resolvedTargetFrom; | ||
import static com.tngtech.archunit.core.domain.TestUtils.simulateCall; | ||
import static com.tngtech.archunit.testutil.Assertions.assertThat; | ||
import static com.tngtech.archunit.testutil.Assertions.assertThatType; | ||
|
||
public class JavaAccessTest { | ||
@Test | ||
|
@@ -24,6 +27,15 @@ public void when_the_origin_is_an_inner_class_the_toplevel_class_is_displayed_as | |
|
||
assertThat(access.getDescription()).contains("(SomeClass.java:7)"); | ||
} | ||
@Test | ||
public void java_access_transforms_to_class_dependency() { | ||
TestJavaAccess access = anyAccess(); | ||
Dependency dependency = getOnlyElement(access.toClassDependencies()); | ||
|
||
assertThatType(dependency.getOriginClass()).as("origin class").isEqualTo(access.getOriginOwner()); | ||
assertThatType(dependency.getTargetClass()).as("target class").isEqualTo(access.getTargetOwner()); | ||
Assertions.assertThat(dependency.getDescription()).as("description").isEqualTo(access.getDescription()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd move the test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
|
||
@Test | ||
public void location_of_origin_of_deeper_inner_class_hierarchies() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name might be inspired by the previous usage of
Dependency.tryCreateFromAccess
inJavaClassDependencies
(which is no public API). I wonder whether the namegetDependencies
might be more intuitive? (Same inSliceDependency
.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method name was chosen as in the existing method com.tngtech.archunit.library.modules.ModuleDependency#toClassDependencies
To be honest, I would use getDependencies otherwise.
I have also considered adding an interface declaring this method. It might be called
SomeDependency
and implemented by JavaAccess, SliceDependency, ModuleDependency, and Dependency. I decided against it only because I was not sure about its name.