Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Apr 18, 2016
1 parent bf7a20a commit bd9d0dd
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java
Expand Up @@ -918,6 +918,24 @@ public void testExceptionSuppressionAdvice() throws Exception {
assertThat(type.getDeclaredMethod(FOO + BAR).invoke(type.newInstance()), nullValue(Object.class));
}

@Test
public void testExceptionTypeTest() throws Exception {
Class<?> type = new ByteBuddy()
.redefine(ExceptionTypeAdvice.class)
.visit(Advice.to(ExceptionTypeAdvice.class).on(named(FOO)))
.make()
.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
try {
type.getDeclaredMethod(FOO).invoke(type.newInstance());
fail();
} catch (InvocationTargetException exception) {
assertThat(exception.getCause(), instanceOf(IllegalStateException.class));
}
assertThat(type.getDeclaredField(ENTER).get(null), is((Object) 1));
assertThat(type.getDeclaredField(EXIT).get(null), is((Object) 1));
}

@Test
public void testUserTypeValue() throws Exception {
Class<?> type = new ByteBuddy()
Expand Down Expand Up @@ -1183,7 +1201,7 @@ public void testAdviceWithNonAssignableEnterValue() throws Exception {
}

@Test(expected = IllegalStateException.class)
public void test() throws Exception {
public void testIllegalThrowableRequest() throws Exception {
Advice.to(IllegalThrowableRequestAdvice.class);
}

Expand Down Expand Up @@ -2253,6 +2271,27 @@ private static void exit(@Advice.Enter String value) {
}
}

public static class ExceptionTypeAdvice {

public static int enter, exit;

public void foo() {
throw new IllegalStateException();
}

@Advice.OnMethodEnter(suppress = UnsupportedOperationException.class)
private static void enter() {
enter++;
throw new UnsupportedOperationException();
}

@Advice.OnMethodExit(suppress = ArrayIndexOutOfBoundsException.class, onThrowable = IllegalStateException.class)
private static void exit() {
exit++;
throw new ArrayIndexOutOfBoundsException();
}
}

@SuppressWarnings("unused")
public static class FieldAdviceIllegalExplicit {

Expand Down

0 comments on commit bd9d0dd

Please sign in to comment.