Skip to content

Commit

Permalink
Add additional tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Mar 13, 2023
1 parent 8e6f438 commit 514e1c9
Show file tree
Hide file tree
Showing 4 changed files with 858 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AdviceRepeatOnDefaultValueTest {

private static final String FOO = "foo";

@Parameterized.Parameters
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{BooleanAdvice.class},
Expand Down Expand Up @@ -128,7 +128,25 @@ public static Collection<Object[]> data() {
{LongDelegatingAdviceWithEnterAdviceAndWithoutArgumentBackupAndExceptionHandler.class},
{FloatDelegatingAdviceWithEnterAdviceAndWithoutArgumentBackupAndExceptionHandler.class},
{DoubleDelegatingAdviceWithEnterAdviceAndWithoutArgumentBackupAndExceptionHandler.class},
{ReferenceDelegatingAdviceWithEnterAdviceAndWithoutArgumentBackupAndExceptionHandler.class}
{ReferenceDelegatingAdviceWithEnterAdviceAndWithoutArgumentBackupAndExceptionHandler.class},
{BooleanArrayAdvice.class},
{ByteArrayAdvice.class},
{ShortArrayAdvice.class},
{CharacterArrayAdvice.class},
{IntegerArrayAdvice.class},
{LongArrayAdvice.class},
{FloatArrayAdvice.class},
{DoubleArrayAdvice.class},
{ReferenceArrayAdvice.class},
{BooleanArrayNullAdvice.class},
{ByteArrayNullAdvice.class},
{ShortArrayNullAdvice.class},
{CharacterArrayNullAdvice.class},
{IntegerArrayNullAdvice.class},
{LongArrayNullAdvice.class},
{FloatArrayNullAdvice.class},
{DoubleArrayNullAdvice.class},
{ReferenceArrayNullAdvice.class}
});
}

Expand Down Expand Up @@ -2668,4 +2686,328 @@ private static Object exit(@Advice.Return int count, @Advice.Exit Object exit) {
return count >= 3 ? FOO : null;
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static boolean[] exit(@Advice.Return int count, @Advice.Exit boolean[] exit) {
if (exit != null && exit[0]) {
throw new AssertionError();
}
return new boolean[]{count >= 3};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static byte[] exit(@Advice.Return int count, @Advice.Exit byte[] exit) {
if (exit != null && exit[0] != 0) {
throw new AssertionError();
}
return new byte[]{(byte) (count >= 3 ? 1 : 0)};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static short[] exit(@Advice.Return int count, @Advice.Exit short[] exit) {
if (exit != null && exit[0] != 0) {
throw new AssertionError();
}
return new short[]{(short) (count >= 3 ? 1 : 0)};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static char[] exit(@Advice.Return int count, @Advice.Exit char[] exit) {
if (exit != null && exit[0] != 0) {
throw new AssertionError();
}
return new char[]{(char) (count >= 3 ? 1 : 0)};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static int[] exit(@Advice.Return int count, @Advice.Exit int[] exit) {
if (exit != null && exit[0] != 0) {
throw new AssertionError();
}
return new int[]{count >= 3 ? 1 : 0};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static long[] exit(@Advice.Return int count, @Advice.Exit long[] exit) {
if (exit != null && exit[0] != 0L) {
throw new AssertionError();
}
return new long[]{count >= 3 ? 1L : 0L};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static float[] exit(@Advice.Return int count, @Advice.Exit float[] exit) {
if (exit != null && exit[0] != 0f) {
throw new AssertionError();
}
return new float[]{count >= 3 ? 1f : 0f};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static double[] exit(@Advice.Return int count, @Advice.Exit double[] exit) {
if (exit != null && exit[0] != 0d) {
throw new AssertionError();
}
return new double[]{count >= 3 ? 1d : 0d};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static Object[] exit(@Advice.Return int count, @Advice.Exit Object[] exit) {
if (exit != null && exit[0] != null) {
throw new AssertionError();
}
return new Object[]{count >= 3 ? FOO : null};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static boolean[] exit(@Advice.Return int count, @Advice.Exit boolean[] exit) {
if (exit != null && exit[0]) {
throw new AssertionError();
}
return count >= 3 ? null : new boolean[]{false};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static byte[] exit(@Advice.Return int count, @Advice.Exit byte[] exit) {
if (exit != null && exit[0] != 0) {
throw new AssertionError();
}
return count >= 3 ? null : new byte[]{(byte) 0};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static short[] exit(@Advice.Return int count, @Advice.Exit short[] exit) {
if (exit != null && exit[0] != 0) {
throw new AssertionError();
}
return count >= 3 ? null : new short[]{(short) 0};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static char[] exit(@Advice.Return int count, @Advice.Exit char[] exit) {
if (exit != null && exit[0] != 0) {
throw new AssertionError();
}
return count >= 3 ? null : new char[]{(char) 0};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static int[] exit(@Advice.Return int count, @Advice.Exit int[] exit) {
if (exit != null && exit[0] != 0) {
throw new AssertionError();
}
return count >= 3 ? null : new int[]{0};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static long[] exit(@Advice.Return int count, @Advice.Exit long[] exit) {
if (exit != null && exit[0] != 0L) {
throw new AssertionError();
}
return count >= 3 ? null : new long[]{0L};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static float[] exit(@Advice.Return int count, @Advice.Exit float[] exit) {
if (exit != null && exit[0] != 0f) {
throw new AssertionError();
}
return count >= 3 ? null : new float[]{0f};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static double[] exit(@Advice.Return int count, @Advice.Exit double[] exit) {
if (exit != null && exit[0] != 0d) {
throw new AssertionError();
}
return count >= 3 ? null : new double[]{0d};
}
}

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

private int count;

public int foo() {
return ++count;
}

@Advice.OnMethodExit(repeatOn = Advice.OnDefaultValue.class, repeatOnIndex = 0)
private static Object[] exit(@Advice.Return int count, @Advice.Exit Object[] exit) {
if (exit != null && exit[0] != null) {
throw new AssertionError();
}
return count >= 3 ? null : new Object[]{null};
}
}
}
Loading

0 comments on commit 514e1c9

Please sign in to comment.