-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added tests for MatcherChainBuilder and CustomElementMatchers
- Loading branch information
1 parent
a8bbf46
commit 9f09115
Showing
6 changed files
with
184 additions
and
5 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
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
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
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
29 changes: 29 additions & 0 deletions
29
src/test/java/rocks/inspectit/gepard/agent/resolver/matcher/CustomElementMatchersTest.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,29 @@ | ||
package rocks.inspectit.gepard.agent.resolver.matcher; | ||
|
||
import net.bytebuddy.description.NamedElement; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class CustomElementMatchersTest { | ||
@Nested | ||
public class NameIs { | ||
|
||
@Test | ||
public void emptyNameReturnsNull() { | ||
String method = ""; | ||
ElementMatcher.Junction<NamedElement> result = CustomElementMatchers.nameIs(method); | ||
assertNull(result); | ||
} | ||
|
||
@Test | ||
public void validNameMatcherIsReturned () { | ||
String method = "testMethod"; | ||
ElementMatcher.Junction<NamedElement> result = CustomElementMatchers.nameIs(method); | ||
assertNotNull(result); | ||
} | ||
} | ||
|
||
} |
137 changes: 137 additions & 0 deletions
137
src/test/java/rocks/inspectit/gepard/agent/resolver/matcher/MatcherChainBuilderTest.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,137 @@ | ||
package rocks.inspectit.gepard.agent.resolver.matcher; | ||
|
||
import net.bytebuddy.matcher.ElementMatcher; | ||
import net.bytebuddy.matcher.ElementMatchers; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.not; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class MatcherChainBuilderTest { | ||
private MatcherChainBuilder<Object> builder; | ||
|
||
private ElementMatcher.Junction<Object> anyMatcher = ElementMatchers.any(); | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
builder = new MatcherChainBuilder<>(); | ||
} | ||
|
||
@Nested | ||
public class Or { | ||
|
||
@Test | ||
public void nullMatcher() { | ||
builder.or(null); | ||
|
||
assertNull(builder.build()); | ||
assertTrue(builder.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void singleMatcher() { | ||
builder.or(anyMatcher); | ||
|
||
Assertions.assertEquals(builder.build(), anyMatcher); | ||
assertFalse(builder.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void multipleMatcher() { | ||
builder.or(anyMatcher); | ||
builder.or(anyMatcher); | ||
|
||
assertEquals(builder.build(), anyMatcher.or(anyMatcher)); | ||
} | ||
|
||
@Test | ||
public void nullOnNotEmpty() { | ||
builder.or(anyMatcher); | ||
builder.or(null); | ||
|
||
assertEquals(builder.build(), anyMatcher); | ||
} | ||
} | ||
|
||
@Nested | ||
public class And { | ||
|
||
@Test | ||
public void nullMatcher() { | ||
builder.and(null); | ||
|
||
assertNull(builder.build()); | ||
assertTrue(builder.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void singleMatcher() { | ||
builder.and(anyMatcher); | ||
|
||
assertEquals(builder.build(), anyMatcher); | ||
assertFalse(builder.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void multipleMatcher() { | ||
builder.and(anyMatcher); | ||
builder.and(anyMatcher); | ||
|
||
assertEquals(builder.build(), anyMatcher.and(anyMatcher)); | ||
} | ||
|
||
@Test | ||
public void nullOnNotEmpty() { | ||
builder.and(anyMatcher); | ||
builder.and(null); | ||
|
||
assertEquals(builder.build(), anyMatcher); | ||
} | ||
|
||
@Test | ||
public void conditionalTrue() { | ||
builder.and(true, anyMatcher); | ||
|
||
assertEquals(builder.build(), anyMatcher); | ||
} | ||
|
||
@Test | ||
public void conditionalFalse() { | ||
builder.and(false, anyMatcher); | ||
|
||
assertEquals(builder.build(), not(anyMatcher)); | ||
} | ||
|
||
@Test | ||
public void conditionalFalseOnNotEmpty() { | ||
builder.and(anyMatcher); | ||
builder.and(false, anyMatcher); | ||
|
||
assertEquals(builder.build(), anyMatcher.and(not(anyMatcher))); | ||
} | ||
} | ||
|
||
@Nested | ||
public class IsEmpty { | ||
|
||
@Test | ||
public void empty() { | ||
boolean result = builder.isEmpty(); | ||
|
||
assertTrue(result); | ||
} | ||
|
||
@Test | ||
public void notEmpty() { | ||
builder.and(ElementMatchers.any()); | ||
|
||
boolean result = builder.isEmpty(); | ||
|
||
assertFalse(result); | ||
} | ||
} | ||
|
||
} |