Skip to content

Commit

Permalink
add toClassDependencies()
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitry Polivaev <[email protected]>
  • Loading branch information
dpolivaevUnite committed Feb 15, 2024
1 parent a95c7c3 commit f9305c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ String additionalToStringFields() {
return "";
}

/**
* @return all matching class dependencies.
*/
@PublicAPI(usage = ACCESS)
public Set<Dependency> toClassDependencies() {
return Dependency.tryCreateFromAccess(this);
}

@Override
@PublicAPI(usage = ACCESS)
public String getDescription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

Expand Down Expand Up @@ -62,6 +63,11 @@ public Slice getTarget() {
return target;
}

@PublicAPI(usage = ACCESS)
public Set<Dependency> toClassDependencies() {
return relevantDependencies;
}

@Override
@PublicAPI(usage = ACCESS)
public String getDescription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,6 +26,9 @@ public void when_the_origin_is_an_inner_class_the_toplevel_class_is_displayed_as
.inLineNumber(7);

assertThat(access.getDescription()).contains("(SomeClass.java:7)");
Dependency dependency = getOnlyElement(access.toClassDependencies());
assertThatType(dependency.getTargetClass()).as("target class").isEqualTo(access.getTargetOwner());
Assertions.assertThat(dependency.getDescription()).as("description").isEqualTo(access.getDescription());
}

@Test
Expand Down

0 comments on commit f9305c6

Please sign in to comment.