-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added JavaCodeUnit.getCallsFromSelf() and JavaCodeUnit.getAccessesFro…
…mSelf() for convenience. Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
- Loading branch information
1 parent
4a413be
commit 5025a5c
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
archunit/src/test/java/com/tngtech/archunit/core/domain/JavaCodeUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.tngtech.archunit.core.domain; | ||
|
||
import org.junit.Test; | ||
|
||
import static com.google.common.collect.Sets.union; | ||
import static com.tngtech.archunit.core.domain.TestUtils.importClassWithContext; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class JavaCodeUnitTest { | ||
|
||
@Test | ||
public void offers_all_calls_from_Self() { | ||
JavaMethod method = importClassWithContext(ClassAccessingOtherClass.class).getMethod("access", ClassBeingAccessed.class); | ||
|
||
assertThat(method.getCallsFromSelf()) | ||
.hasSize(4) | ||
.containsOnlyElementsOf(union(method.getConstructorCallsFromSelf(), method.getMethodCallsFromSelf())); | ||
} | ||
|
||
@Test | ||
public void offers_all_accesses_from_Self() { | ||
JavaMethod method = importClassWithContext(ClassAccessingOtherClass.class).getMethod("access", ClassBeingAccessed.class); | ||
|
||
assertThat(method.getAccessesFromSelf()) | ||
.hasSize(6) | ||
.containsOnlyElementsOf(union(union( | ||
method.getConstructorCallsFromSelf(), | ||
method.getMethodCallsFromSelf()), | ||
method.getFieldAccesses())); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
private static class ClassAccessingOtherClass { | ||
void access(ClassBeingAccessed classBeingAccessed) { | ||
new ClassBeingAccessed(); | ||
new ClassBeingAccessed(""); | ||
classBeingAccessed.field1 = ""; | ||
classBeingAccessed.field2 = null; | ||
classBeingAccessed.method1(); | ||
classBeingAccessed.method2(); | ||
} | ||
} | ||
|
||
private static class ClassBeingAccessed { | ||
String field1; | ||
Object field2; | ||
|
||
ClassBeingAccessed() { | ||
} | ||
|
||
ClassBeingAccessed(String field1) { | ||
this.field1 = field1; | ||
} | ||
|
||
void method1() { | ||
} | ||
|
||
void method2() { | ||
} | ||
} | ||
} |