Skip to content

Commit 3a5a025

Browse files
committed
convert to java
1 parent d28b0cd commit 3a5a025

File tree

2 files changed

+41
-45
lines changed

2 files changed

+41
-45
lines changed

javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/LoggingFailSafeMatcherTest.groovy

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package io.opentelemetry.javaagent.tooling.bytebuddy.matcher;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatCode;
5+
import static org.mockito.ArgumentMatchers.any;
6+
import static org.mockito.Mockito.mock;
7+
import static org.mockito.Mockito.when;
8+
9+
import io.opentelemetry.javaagent.tooling.bytebuddy.LoggingFailSafeMatcher;
10+
import net.bytebuddy.matcher.ElementMatcher;
11+
import org.junit.jupiter.params.ParameterizedTest;
12+
import org.junit.jupiter.params.provider.ValueSource;
13+
import org.junit.jupiter.api.Test;
14+
15+
@SuppressWarnings({"unchecked", "rawtypes"})
16+
class LoggingFailSafeMatcherTest {
17+
18+
@ParameterizedTest
19+
@ValueSource(booleans = {true, false})
20+
void testMatcher(boolean match) {
21+
ElementMatcher mockMatcher = mock(ElementMatcher.class);
22+
when(mockMatcher.matches(any())).thenReturn(match);
23+
24+
LoggingFailSafeMatcher<Object> matcher = new LoggingFailSafeMatcher<>(mockMatcher, "test");
25+
26+
boolean result = matcher.matches(new Object());
27+
28+
assertThat(result).isEqualTo(match);
29+
}
30+
31+
@Test
32+
void testMatcherException() {
33+
ElementMatcher mockMatcher = mock(ElementMatcher.class);
34+
when(mockMatcher.matches(any())).thenThrow(new RuntimeException("matcher exception"));
35+
36+
LoggingFailSafeMatcher<Object> matcher = new LoggingFailSafeMatcher<>(mockMatcher, "test");
37+
38+
assertThatCode(() -> matcher.matches(new Object())).doesNotThrowAnyException();
39+
assertThat(matcher.matches(new Object())).isFalse();
40+
}
41+
}

0 commit comments

Comments
 (0)