java.lang.reflect.Method

Here are the examples of the java api class java.lang.reflect.Method taken from open source projects.

1. BignumTest#testCompare()

Project: openjdk
Source File: BignumTest.java
View license
@Test
public void testCompare() throws Exception {
    final Object bignum1 = ctor.newInstance();
    final Object bignum2 = ctor.newInstance();
    final Method assignUInt16 = method("assignUInt16", char.class);
    final Method assignHexString = method("assignHexString", String.class);
    final Method compare = method("compare", Bignum, Bignum);
    final Method equal = method("equal", Bignum, Bignum);
    final Method less = method("less", Bignum, Bignum);
    final Method lessEqual = method("lessEqual", Bignum, Bignum);
    final Method shiftLeft = method("shiftLeft", int.class);
    assignUInt16.invoke(bignum1, (char) 1);
    assignUInt16.invoke(bignum2, (char) 1);
    assertEquals(0, compare.invoke(null, bignum1, bignum2));
    assertTrue((boolean) equal.invoke(null, bignum1, bignum2));
    assertTrue((boolean) lessEqual.invoke(null, bignum1, bignum2));
    assertTrue(!(boolean) less.invoke(null, bignum1, bignum2));
    assignUInt16.invoke(bignum1, (char) 0);
    assignUInt16.invoke(bignum2, (char) 1);
    assertEquals(-1, compare.invoke(null, bignum1, bignum2));
    assertEquals(+1, compare.invoke(null, bignum2, bignum1));
    assertTrue(!(boolean) equal.invoke(null, bignum1, bignum2));
    assertTrue(!(boolean) equal.invoke(null, bignum2, bignum1));
    assertTrue((boolean) lessEqual.invoke(null, bignum1, bignum2));
    assertTrue(!(boolean) lessEqual.invoke(null, bignum2, bignum1));
    assertTrue((boolean) less.invoke(null, bignum1, bignum2));
    assertTrue(!(boolean) less.invoke(null, bignum2, bignum1));
    assignHexString.invoke(bignum1, "1234567890ABCDEF12345");
    assignHexString.invoke(bignum2, "1234567890ABCDEF12345");
    assertEquals(0, compare.invoke(null, bignum1, bignum2));
    assignHexString.invoke(bignum1, "1234567890ABCDEF12345");
    assignHexString.invoke(bignum2, "1234567890ABCDEF12346");
    assertEquals(-1, compare.invoke(null, bignum1, bignum2));
    assertEquals(+1, compare.invoke(null, bignum2, bignum1));
    assignHexString.invoke(bignum1, "1234567890ABCDEF12345");
    shiftLeft.invoke(bignum1, 500);
    assignHexString.invoke(bignum2, "1234567890ABCDEF12345");
    shiftLeft.invoke(bignum2, 500);
    assertEquals(0, compare.invoke(null, bignum1, bignum2));
    assignHexString.invoke(bignum1, "1234567890ABCDEF12345");
    shiftLeft.invoke(bignum1, 500);
    assignHexString.invoke(bignum2, "1234567890ABCDEF12346");
    shiftLeft.invoke(bignum2, 500);
    assertEquals(-1, compare.invoke(null, bignum1, bignum2));
    assertEquals(+1, compare.invoke(null, bignum2, bignum1));
    assignUInt16.invoke(bignum1, (char) 1);
    shiftLeft.invoke(bignum1, 64);
    assignHexString.invoke(bignum2, "10000000000000000");
    assertEquals(0, compare.invoke(null, bignum1, bignum2));
    assertEquals(0, compare.invoke(null, bignum2, bignum1));
    assignUInt16.invoke(bignum1, (char) 1);
    shiftLeft.invoke(bignum1, 64);
    assignHexString.invoke(bignum2, "10000000000000001");
    assertEquals(-1, compare.invoke(null, bignum1, bignum2));
    assertEquals(+1, compare.invoke(null, bignum2, bignum1));
    assignUInt16.invoke(bignum1, (char) 1);
    shiftLeft.invoke(bignum1, 96);
    assignHexString.invoke(bignum2, "10000000000000001");
    shiftLeft.invoke(bignum2, 32);
    assertEquals(-1, compare.invoke(null, bignum1, bignum2));
    assertEquals(+1, compare.invoke(null, bignum2, bignum1));
    assignHexString.invoke(bignum1, "FFFFFFFFFFFFFFFF");
    assignUInt16.invoke(bignum2, (char) 1);
    shiftLeft.invoke(bignum2, 64);
    assertEquals(-1, compare.invoke(null, bignum1, bignum2));
    assertEquals(+1, compare.invoke(null, bignum2, bignum1));
    assignHexString.invoke(bignum1, "FFFFFFFFFFFFFFFF");
    shiftLeft.invoke(bignum1, 32);
    assignUInt16.invoke(bignum2, (char) 1);
    shiftLeft.invoke(bignum2, 96);
    assertEquals(-1, compare.invoke(null, bignum1, bignum2));
    assertEquals(+1, compare.invoke(null, bignum2, bignum1));
    assignHexString.invoke(bignum1, "FFFFFFFFFFFFFFFF");
    shiftLeft.invoke(bignum1, 32);
    assignUInt16.invoke(bignum2, (char) 1);
    shiftLeft.invoke(bignum2, 95);
    assertEquals(+1, compare.invoke(null, bignum1, bignum2));
    assertEquals(-1, compare.invoke(null, bignum2, bignum1));
    assignHexString.invoke(bignum1, "FFFFFFFFFFFFFFFF");
    shiftLeft.invoke(bignum1, 32);
    assignUInt16.invoke(bignum2, (char) 1);
    shiftLeft.invoke(bignum2, 100);
    assertEquals(-1, compare.invoke(null, bignum1, bignum2));
    assertEquals(+1, compare.invoke(null, bignum2, bignum1));
    assignHexString.invoke(bignum1, "100000000000000");
    assignUInt16.invoke(bignum2, (char) 1);
    shiftLeft.invoke(bignum2, 14 * 4);
    assertEquals(0, compare.invoke(null, bignum1, bignum2));
    assertEquals(0, compare.invoke(null, bignum2, bignum1));
    assignHexString.invoke(bignum1, "100000000000001");
    assignUInt16.invoke(bignum2, (char) 1);
    shiftLeft.invoke(bignum2, 14 * 4);
    assertEquals(+1, compare.invoke(null, bignum1, bignum2));
    assertEquals(-1, compare.invoke(null, bignum2, bignum1));
    assignHexString.invoke(bignum1, "200000000000000");
    assignUInt16.invoke(bignum2, (char) 3);
    shiftLeft.invoke(bignum2, 14 * 4);
    assertEquals(-1, compare.invoke(null, bignum1, bignum2));
    assertEquals(+1, compare.invoke(null, bignum2, bignum1));
}

2. BignumTest#testSubtractBignum()

Project: openjdk
Source File: BignumTest.java
View license
@Test
public void testSubtractBignum() throws Exception {
    final Object bignum = ctor.newInstance();
    final Object other = ctor.newInstance();
    final Method assignUInt16 = method("assignUInt16", char.class);
    final Method assignHexString = method("assignHexString", String.class);
    final Method shiftLeft = method("shiftLeft", int.class);
    final Method subtractBignum = method("subtractBignum", Bignum);
    final Method toHexString = method("toHexString");
    assignHexString.invoke(bignum, "1");
    assignHexString.invoke(other, "0");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "1");
    assignHexString.invoke(bignum, "2");
    assignHexString.invoke(other, "0");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "2");
    assignHexString.invoke(bignum, "10000000");
    assignHexString.invoke(other, "1");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "FFFFFFF");
    assignHexString.invoke(bignum, "100000000000000");
    assignHexString.invoke(other, "1");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "FFFFFFFFFFFFFF");
    assignHexString.invoke(bignum, "10000000000000000000000000000000000000000001");
    assignHexString.invoke(other, "1");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "10000000000000000000000000000000000000000000");
    assignHexString.invoke(bignum, "1000000000001");
    assignHexString.invoke(other, "1000000000000");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "1");
    assignHexString.invoke(bignum, "100000FFFFFFF");
    assignHexString.invoke(other, "1000000000000");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "FFFFFFF");
    assignHexString.invoke(bignum, "10000000000000000000000000000001000000000000");
    assignHexString.invoke(other, "1000000000000");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "10000000000000000000000000000000000000000000");
    assignHexString.invoke(bignum, "1000000000000000000000000000000FFFFFFFFFFFF");
    assignHexString.invoke(other, "1000000000000");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    // "10 0000 0000 0000 0000 0000 0000"
    assignHexString.invoke(other, "1000000000000");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "FFFFFFFFFFFFF000000000000");
    assignHexString.invoke(other, "1000000000000");
    shiftLeft.invoke(other, 48);
    // other == "1000000000000000000000000"
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    // bignum == "10000000000000000000000000"
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "F000000000000000000000000");
    assignUInt16.invoke(other, (char) 0x1);
    shiftLeft.invoke(other, 35);
    // other == "800000000"
    assignHexString.invoke(bignum, "FFFFFFF");
    shiftLeft.invoke(bignum, 60);
    // bignum = FFFFFFF000000000000000
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "FFFFFFEFFFFFF800000000");
    assignHexString.invoke(bignum, "10000000000000000000000000000000000000000000");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF800000000");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    subtractBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFF");
}

3. BignumTest#testAddUInt64()

Project: openjdk
Source File: BignumTest.java
View license
@Test
public void testAddUInt64() throws Exception {
    final Object bignum = ctor.newInstance();
    final Method addUInt64 = method("addUInt64", long.class);
    final Method assignUInt16 = method("assignUInt16", char.class);
    final Method assignHexString = method("assignHexString", String.class);
    final Method shiftLeft = method("shiftLeft", int.class);
    final Method toHexString = method("toHexString");
    assignHexString.invoke(bignum, "0");
    addUInt64.invoke(bignum, 0xA);
    assertEquals(toHexString.invoke(bignum), "A");
    assignHexString.invoke(bignum, "1");
    addUInt64.invoke(bignum, 0xA);
    assertEquals(toHexString.invoke(bignum), "B");
    assignHexString.invoke(bignum, "1");
    addUInt64.invoke(bignum, 0x100);
    assertEquals(toHexString.invoke(bignum), "101");
    assignHexString.invoke(bignum, "1");
    addUInt64.invoke(bignum, 0xFFFF);
    assertEquals(toHexString.invoke(bignum), "10000");
    assignHexString.invoke(bignum, "FFFFFFF");
    addUInt64.invoke(bignum, 0x1);
    assertEquals(toHexString.invoke(bignum), "10000000");
    assignHexString.invoke(bignum, "10000000000000000000000000000000000000000000");
    addUInt64.invoke(bignum, 0xFFFF);
    assertEquals(toHexString.invoke(bignum), "1000000000000000000000000000000000000000FFFF");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    addUInt64.invoke(bignum, 0x1);
    assertEquals(toHexString.invoke(bignum), "100000000000000000000000000000000000000000000");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    addUInt64.invoke(bignum, 0x1);
    assertEquals(toHexString.invoke(bignum), "100000000000000000000000000000000000000000000");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    addUInt64.invoke(bignum, 1);
    assertEquals(toHexString.invoke(bignum), "10000000000000000000000001");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    addUInt64.invoke(bignum, 0xFFFF);
    assertEquals(toHexString.invoke(bignum), "1000000000000000000000FFFF");
    assignHexString.invoke(bignum, "0");
    addUInt64.invoke(bignum, 0xA00000000L);
    assertEquals(toHexString.invoke(bignum), "A00000000");
    assignHexString.invoke(bignum, "1");
    addUInt64.invoke(bignum, 0xA00000000L);
    assertEquals(toHexString.invoke(bignum), "A00000001");
    assignHexString.invoke(bignum, "1");
    addUInt64.invoke(bignum, 0x10000000000L);
    assertEquals(toHexString.invoke(bignum), "10000000001");
    assignHexString.invoke(bignum, "1");
    addUInt64.invoke(bignum, 0xFFFF00000000L);
    assertEquals(toHexString.invoke(bignum), "FFFF00000001");
    assignHexString.invoke(bignum, "FFFFFFF");
    addUInt64.invoke(bignum, 0x100000000L);
    assertEquals(toHexString.invoke(bignum), "10FFFFFFF");
    assignHexString.invoke(bignum, "10000000000000000000000000000000000000000000");
    addUInt64.invoke(bignum, 0xFFFF00000000L);
    assertEquals(toHexString.invoke(bignum), "10000000000000000000000000000000FFFF00000000");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    addUInt64.invoke(bignum, 0x100000000L);
    assertEquals(toHexString.invoke(bignum), "1000000000000000000000000000000000000FFFFFFFF");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    addUInt64.invoke(bignum, 0x100000000L);
    assertEquals(toHexString.invoke(bignum), "10000000000000000100000000");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    addUInt64.invoke(bignum, 0xFFFF00000000L);
    assertEquals(toHexString.invoke(bignum), "10000000000000FFFF00000000");
}

4. BignumTest#testMultiplyUInt32()

Project: openjdk
Source File: BignumTest.java
View license
@Test
public void testMultiplyUInt32() throws Exception {
    final Object bignum = ctor.newInstance();
    final Method assignHexString = method("assignHexString", String.class);
    final Method assignDecimalString = method("assignDecimalString", String.class);
    final Method assignUInt16 = method("assignUInt16", char.class);
    final Method multiplyByUInt32 = method("multiplyByUInt32", int.class);
    final Method shiftLeft = method("shiftLeft", int.class);
    final Method toHexString = method("toHexString");
    assignHexString.invoke(bignum, "0");
    multiplyByUInt32.invoke(bignum, 0x25);
    assertEquals(toHexString.invoke(bignum), "0");
    assignHexString.invoke(bignum, "2");
    multiplyByUInt32.invoke(bignum, 0x5);
    assertEquals(toHexString.invoke(bignum), "A");
    assignHexString.invoke(bignum, "10000000");
    multiplyByUInt32.invoke(bignum, 0x9);
    assertEquals(toHexString.invoke(bignum), "90000000");
    assignHexString.invoke(bignum, "100000000000000");
    multiplyByUInt32.invoke(bignum, 0xFFFF);
    assertEquals(toHexString.invoke(bignum), "FFFF00000000000000");
    assignHexString.invoke(bignum, "100000000000000");
    multiplyByUInt32.invoke(bignum, 0xFFFFFFFF);
    assertEquals(toHexString.invoke(bignum), "FFFFFFFF00000000000000");
    assignHexString.invoke(bignum, "1234567ABCD");
    multiplyByUInt32.invoke(bignum, 0xFFF);
    assertEquals(toHexString.invoke(bignum), "12333335552433");
    assignHexString.invoke(bignum, "1234567ABCD");
    multiplyByUInt32.invoke(bignum, 0xFFFFFFF);
    assertEquals(toHexString.invoke(bignum), "12345679998A985433");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFF");
    multiplyByUInt32.invoke(bignum, 0x2);
    assertEquals(toHexString.invoke(bignum), "1FFFFFFFFFFFFFFFE");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFF");
    multiplyByUInt32.invoke(bignum, 0x4);
    assertEquals(toHexString.invoke(bignum), "3FFFFFFFFFFFFFFFC");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFF");
    multiplyByUInt32.invoke(bignum, 0xF);
    assertEquals(toHexString.invoke(bignum), "EFFFFFFFFFFFFFFF1");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFF");
    multiplyByUInt32.invoke(bignum, 0xFFFFFF);
    assertEquals(toHexString.invoke(bignum), "FFFFFEFFFFFFFFFF000001");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    // "10 0000 0000 0000 0000 0000 0000"
    multiplyByUInt32.invoke(bignum, 2);
    assertEquals(toHexString.invoke(bignum), "20000000000000000000000000");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    // "10 0000 0000 0000 0000 0000 0000"
    multiplyByUInt32.invoke(bignum, 0xF);
    assertEquals(toHexString.invoke(bignum), "F0000000000000000000000000");
    assignUInt16.invoke(bignum, (char) 0xFFFF);
    shiftLeft.invoke(bignum, 100);
    // "FFFF0 0000 0000 0000 0000 0000 0000"
    multiplyByUInt32.invoke(bignum, 0xFFFF);
    assertEquals(toHexString.invoke(bignum), "FFFE00010000000000000000000000000");
    assignUInt16.invoke(bignum, (char) 0xFFFF);
    shiftLeft.invoke(bignum, 100);
    // "FFFF0 0000 0000 0000 0000 0000 0000"
    multiplyByUInt32.invoke(bignum, 0xFFFFFFFF);
    assertEquals(toHexString.invoke(bignum), "FFFEFFFF00010000000000000000000000000");
    assignUInt16.invoke(bignum, (char) 0xFFFF);
    shiftLeft.invoke(bignum, 100);
    // "FFFF0 0000 0000 0000 0000 0000 0000"
    multiplyByUInt32.invoke(bignum, 0xFFFFFFFF);
    assertEquals(toHexString.invoke(bignum), "FFFEFFFF00010000000000000000000000000");
    assignDecimalString.invoke(bignum, "15611230384529777");
    multiplyByUInt32.invoke(bignum, 10000000);
    assertEquals(toHexString.invoke(bignum), "210EDD6D4CDD2580EE80");
}

5. BignumTest#testMultiplyUInt64()

Project: openjdk
Source File: BignumTest.java
View license
@Test
public void testMultiplyUInt64() throws Exception {
    final Object bignum = ctor.newInstance();
    final Method assignUInt16 = method("assignUInt16", char.class);
    final Method assignDecimalString = method("assignDecimalString", String.class);
    final Method assignHexString = method("assignHexString", String.class);
    final Method multiplyByUInt64 = method("multiplyByUInt64", long.class);
    final Method shiftLeft = method("shiftLeft", int.class);
    final Method toHexString = method("toHexString");
    assignHexString.invoke(bignum, "0");
    multiplyByUInt64.invoke(bignum, 0x25);
    assertEquals(toHexString.invoke(bignum), "0");
    assignHexString.invoke(bignum, "2");
    multiplyByUInt64.invoke(bignum, 0x5);
    assertEquals(toHexString.invoke(bignum), "A");
    assignHexString.invoke(bignum, "10000000");
    multiplyByUInt64.invoke(bignum, 0x9);
    assertEquals(toHexString.invoke(bignum), "90000000");
    assignHexString.invoke(bignum, "100000000000000");
    multiplyByUInt64.invoke(bignum, 0xFFFF);
    assertEquals(toHexString.invoke(bignum), "FFFF00000000000000");
    assignHexString.invoke(bignum, "100000000000000");
    multiplyByUInt64.invoke(bignum, 0xFFFFFFFFFFFFFFFFL);
    assertEquals(toHexString.invoke(bignum), "FFFFFFFFFFFFFFFF00000000000000");
    assignHexString.invoke(bignum, "1234567ABCD");
    multiplyByUInt64.invoke(bignum, 0xFFF);
    assertEquals(toHexString.invoke(bignum), "12333335552433");
    assignHexString.invoke(bignum, "1234567ABCD");
    multiplyByUInt64.invoke(bignum, 0xFFFFFFFFFFL);
    assertEquals(toHexString.invoke(bignum), "1234567ABCBDCBA985433");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFF");
    multiplyByUInt64.invoke(bignum, 0x2);
    assertEquals(toHexString.invoke(bignum), "1FFFFFFFFFFFFFFFE");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFF");
    multiplyByUInt64.invoke(bignum, 0x4);
    assertEquals(toHexString.invoke(bignum), "3FFFFFFFFFFFFFFFC");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFF");
    multiplyByUInt64.invoke(bignum, 0xF);
    assertEquals(toHexString.invoke(bignum), "EFFFFFFFFFFFFFFF1");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFF");
    multiplyByUInt64.invoke(bignum, 0xFFFFFFFFFFFFFFFFL);
    assertEquals(toHexString.invoke(bignum), "FFFFFFFFFFFFFFFE0000000000000001");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    // "10 0000 0000 0000 0000 0000 0000"
    multiplyByUInt64.invoke(bignum, 2);
    assertEquals(toHexString.invoke(bignum), "20000000000000000000000000");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    // "10 0000 0000 0000 0000 0000 0000"
    multiplyByUInt64.invoke(bignum, 0xF);
    assertEquals(toHexString.invoke(bignum), "F0000000000000000000000000");
    assignUInt16.invoke(bignum, (char) 0xFFFF);
    shiftLeft.invoke(bignum, 100);
    // "FFFF0 0000 0000 0000 0000 0000 0000"
    multiplyByUInt64.invoke(bignum, 0xFFFF);
    assertEquals(toHexString.invoke(bignum), "FFFE00010000000000000000000000000");
    assignUInt16.invoke(bignum, (char) 0xFFFF);
    shiftLeft.invoke(bignum, 100);
    // "FFFF0 0000 0000 0000 0000 0000 0000"
    multiplyByUInt64.invoke(bignum, 0xFFFFFFFFL);
    assertEquals(toHexString.invoke(bignum), "FFFEFFFF00010000000000000000000000000");
    assignUInt16.invoke(bignum, (char) 0xFFFF);
    shiftLeft.invoke(bignum, 100);
    // "FFFF0 0000 0000 0000 0000 0000 0000"
    multiplyByUInt64.invoke(bignum, 0xFFFFFFFFFFFFFFFFL);
    assertEquals(toHexString.invoke(bignum), "FFFEFFFFFFFFFFFF00010000000000000000000000000");
    assignDecimalString.invoke(bignum, "15611230384529777");
    multiplyByUInt64.invoke(bignum, 0x8ac7230489e80000L);
    assertEquals(toHexString.invoke(bignum), "1E10EE4B11D15A7F3DE7F3C7680000");
}

6. BignumTest#testDivideModuloIntBignum()

Project: openjdk
Source File: BignumTest.java
View license
@Test
public void testDivideModuloIntBignum() throws Exception {
    final Object bignum = ctor.newInstance();
    final Object other = ctor.newInstance();
    final Object third = ctor.newInstance();
    final Method addBignum = method("addBignum", Bignum);
    final Method assignBignum = method("assignBignum", Bignum);
    final Method assignUInt16 = method("assignUInt16", char.class);
    final Method assignHexString = method("assignHexString", String.class);
    final Method divideModuloIntBignum = method("divideModuloIntBignum", Bignum);
    final Method multiplyByUInt32 = method("multiplyByUInt32", int.class);
    final Method shiftLeft = method("shiftLeft", int.class);
    final Method subtractBignum = method("subtractBignum", Bignum);
    final Method toHexString = method("toHexString");
    assignUInt16.invoke(bignum, (char) 10);
    assignUInt16.invoke(other, (char) 2);
    assertEquals((char) 5, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "0");
    assignUInt16.invoke(bignum, (char) 10);
    shiftLeft.invoke(bignum, 500);
    assignUInt16.invoke(other, (char) 2);
    shiftLeft.invoke(other, 500);
    assertEquals((char) 5, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "0");
    assignUInt16.invoke(bignum, (char) 11);
    assignUInt16.invoke(other, (char) 2);
    assertEquals((char) 5, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "1");
    assignUInt16.invoke(bignum, (char) 10);
    shiftLeft.invoke(bignum, 500);
    assignUInt16.invoke(other, (char) 1);
    addBignum.invoke(bignum, other);
    assignUInt16.invoke(other, (char) 2);
    shiftLeft.invoke(other, 500);
    assertEquals((char) 5, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "1");
    assignUInt16.invoke(bignum, (char) 10);
    shiftLeft.invoke(bignum, 500);
    assignBignum.invoke(other, bignum);
    multiplyByUInt32.invoke(bignum, 0x1234);
    assignUInt16.invoke(third, (char) 0xFFF);
    addBignum.invoke(bignum, third);
    assertEquals((char) 0x1234, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "FFF");
    assignUInt16.invoke(bignum, (char) 10);
    assignHexString.invoke(other, "1234567890");
    assertEquals((char) 0, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "A");
    assignHexString.invoke(bignum, "12345678");
    assignHexString.invoke(other, "3789012");
    assertEquals((char) 5, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "D9861E");
    assignHexString.invoke(bignum, "70000001");
    assignHexString.invoke(other, "1FFFFFFF");
    assertEquals((char) 3, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "10000004");
    assignHexString.invoke(bignum, "28000000");
    assignHexString.invoke(other, "12A05F20");
    assertEquals((char) 2, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "2BF41C0");
    assignUInt16.invoke(bignum, (char) 10);
    shiftLeft.invoke(bignum, 500);
    assignBignum.invoke(other, bignum);
    multiplyByUInt32.invoke(bignum, 0x1234);
    assignUInt16.invoke(third, (char) 0xFFF);
    subtractBignum.invoke(other, third);
    assertEquals((char) 0x1234, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "1232DCC");
    assertEquals((char) 0, (char) divideModuloIntBignum.invoke(bignum, other));
    assertEquals(toHexString.invoke(bignum), "1232DCC");
}

7. BignumTest#testAddBignum()

Project: openjdk
Source File: BignumTest.java
View license
@Test
public void testAddBignum() throws Exception {
    final Object bignum = ctor.newInstance();
    final Object other = ctor.newInstance();
    final Method addBignum = method("addBignum", Bignum);
    final Method assignUInt16 = method("assignUInt16", char.class);
    final Method assignHexString = method("assignHexString", String.class);
    final Method shiftLeft = method("shiftLeft", int.class);
    final Method toHexString = method("toHexString");
    assignHexString.invoke(other, "1");
    assignHexString.invoke(bignum, "0");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "1");
    assignHexString.invoke(bignum, "1");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "2");
    assignHexString.invoke(bignum, "FFFFFFF");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "10000000");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFF");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "100000000000000");
    assignHexString.invoke(bignum, "10000000000000000000000000000000000000000000");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "10000000000000000000000000000000000000000001");
    assignHexString.invoke(other, "1000000000000");
    assignHexString.invoke(bignum, "1");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "1000000000001");
    assignHexString.invoke(bignum, "FFFFFFF");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "100000FFFFFFF");
    assignHexString.invoke(bignum, "10000000000000000000000000000000000000000000");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "10000000000000000000000000000001000000000000");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "1000000000000000000000000000000FFFFFFFFFFFF");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "10000000000001000000000000");
    shiftLeft.invoke(other, 64);
    // other == "10000000000000000000000000000"
    assignUInt16.invoke(bignum, (char) 0x1);
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "10000000000000000000000000001");
    assignHexString.invoke(bignum, "FFFFFFF");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "1000000000000000000000FFFFFFF");
    assignHexString.invoke(bignum, "10000000000000000000000000000000000000000000");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "10000000000000010000000000000000000000000000");
    assignHexString.invoke(bignum, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "100000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    assignUInt16.invoke(bignum, (char) 0x1);
    shiftLeft.invoke(bignum, 100);
    addBignum.invoke(bignum, other);
    assertEquals(toHexString.invoke(bignum), "10010000000000000000000000000");
}

8. BignumTest#testAssignPowerUInt16()

Project: openjdk
Source File: BignumTest.java
View license
@Test
public void testAssignPowerUInt16() throws Exception {
    final Object bignum = ctor.newInstance();
    final Method assignPowerUInt16 = method("assignPowerUInt16", int.class, int.class);
    final Method toHexString = method("toHexString");
    assignPowerUInt16.invoke(bignum, 1, 0);
    assertEquals(toHexString.invoke(bignum), "1");
    assignPowerUInt16.invoke(bignum, 1, 1);
    assertEquals(toHexString.invoke(bignum), "1");
    assignPowerUInt16.invoke(bignum, 1, 2);
    assertEquals(toHexString.invoke(bignum), "1");
    assignPowerUInt16.invoke(bignum, 2, 0);
    assertEquals(toHexString.invoke(bignum), "1");
    assignPowerUInt16.invoke(bignum, 2, 1);
    assertEquals(toHexString.invoke(bignum), "2");
    assignPowerUInt16.invoke(bignum, 2, 2);
    assertEquals(toHexString.invoke(bignum), "4");
    assignPowerUInt16.invoke(bignum, 16, 1);
    assertEquals(toHexString.invoke(bignum), "10");
    assignPowerUInt16.invoke(bignum, 16, 2);
    assertEquals(toHexString.invoke(bignum), "100");
    assignPowerUInt16.invoke(bignum, 16, 5);
    assertEquals(toHexString.invoke(bignum), "100000");
    assignPowerUInt16.invoke(bignum, 16, 8);
    assertEquals(toHexString.invoke(bignum), "100000000");
    assignPowerUInt16.invoke(bignum, 16, 16);
    assertEquals(toHexString.invoke(bignum), "10000000000000000");
    assignPowerUInt16.invoke(bignum, 16, 30);
    assertEquals(toHexString.invoke(bignum), "1000000000000000000000000000000");
    assignPowerUInt16.invoke(bignum, 10, 0);
    assertEquals(toHexString.invoke(bignum), "1");
    assignPowerUInt16.invoke(bignum, 10, 1);
    assertEquals(toHexString.invoke(bignum), "A");
    assignPowerUInt16.invoke(bignum, 10, 2);
    assertEquals(toHexString.invoke(bignum), "64");
    assignPowerUInt16.invoke(bignum, 10, 5);
    assertEquals(toHexString.invoke(bignum), "186A0");
    assignPowerUInt16.invoke(bignum, 10, 8);
    assertEquals(toHexString.invoke(bignum), "5F5E100");
    assignPowerUInt16.invoke(bignum, 10, 16);
    assertEquals(toHexString.invoke(bignum), "2386F26FC10000");
    assignPowerUInt16.invoke(bignum, 10, 30);
    assertEquals(toHexString.invoke(bignum), "C9F2C9CD04674EDEA40000000");
    assignPowerUInt16.invoke(bignum, 10, 31);
    assertEquals(toHexString.invoke(bignum), "7E37BE2022C0914B2680000000");
    assignPowerUInt16.invoke(bignum, 2, 0);
    assertEquals(toHexString.invoke(bignum), "1");
    assignPowerUInt16.invoke(bignum, 2, 100);
    assertEquals(toHexString.invoke(bignum), "10000000000000000000000000");
    assignPowerUInt16.invoke(bignum, 17, 0);
    assertEquals(toHexString.invoke(bignum), "1");
    assignPowerUInt16.invoke(bignum, 17, 99);
    assertEquals(toHexString.invoke(bignum), "1942BB9853FAD924A3D4DD92B89B940E0207BEF05DB9C26BC1B757" + "80BE0C5A2C2990E02A681224F34ED68558CE4C6E33760931");
    assignPowerUInt16.invoke(bignum, 0xFFFF, 99);
    assertEquals(toHexString.invoke(bignum), "FF9D12F09B886C54E77E7439C7D2DED2D34F669654C0C2B6B8C288250" + "5A2211D0E3DC9A61831349EAE674B11D56E3049D7BD79DAAD6C9FA2BA" + "528E3A794299F2EE9146A324DAFE3E88967A0358233B543E233E575B9" + "DD4E3AA7942146426C328FF55BFD5C45E0901B1629260AF9AE2F310C5" + "50959FAF305C30116D537D80CF6EBDBC15C5694062AF1AC3D956D0A41" + "B7E1B79FF11E21D83387A1CE1F5882B31E4B5D8DE415BDBE6854466DF" + "343362267A7E8833119D31D02E18DB5B0E8F6A64B0ED0D0062FFFF");
}

9. MultipleParentClassLoaderTest#testMultipleParentClassLoading()

View license
@Test
public void testMultipleParentClassLoading() throws Exception {
    ClassLoader classLoader = new MultipleParentClassLoader.Builder().append(first, second, null).build();
    assertThat(classLoader.loadClass(FOO), CoreMatchers.<Class<?>>is(Foo.class));
    assertThat(classLoader.loadClass(BAR), CoreMatchers.<Class<?>>is(BarFirst.class));
    assertThat(classLoader.loadClass(QUX), CoreMatchers.<Class<?>>is(Qux.class));
    Method loadClass = ClassLoader.class.getDeclaredMethod("loadClass", String.class, boolean.class);
    loadClass.setAccessible(true);
    loadClass.invoke(verify(first), FOO, false);
    loadClass.invoke(verify(first), BAR, false);
    loadClass.invoke(verify(first), QUX, false);
    verifyNoMoreInteractions(first);
    loadClass.invoke(verify(second), QUX, false);
    verifyNoMoreInteractions(second);
}

10. CompileAndRunTest#sam_support()

Project: golo-lang
Source File: CompileAndRunTest.java
View license
@Test
public void sam_support() throws Throwable {
    Class<?> moduleClass = compileAndLoadGoloModule(SRC, "sam.golo");
    Method func = moduleClass.getMethod("func");
    assertThat((String) func.invoke(null), is("Hey!Hey!"));
    Method ctor = moduleClass.getMethod("ctor");
    assertThat((String) ctor.invoke(null), is("Plop!"));
    Method meth = moduleClass.getMethod("meth");
    assertThat((String) meth.invoke(null), is("Yeah"));
    Method func_varargs = moduleClass.getMethod("func_varargs");
    assertThat((String) func_varargs.invoke(null), is("Hey!Hey!"));
    Method ctor_varargs = moduleClass.getMethod("ctor_varargs");
    assertThat((String) ctor_varargs.invoke(null), is("PlopPlop!"));
    Method meth_varargs = moduleClass.getMethod("meth_varargs");
    assertThat((String) meth_varargs.invoke(null), is("YeahYeah"));
}

11. IntrospectionSupportTest#testOtherIsGetter()

Project: camel
Source File: IntrospectionSupportTest.java
View license
public void testOtherIsGetter() throws Exception {
    OtherExampleBean bean = new OtherExampleBean();
    Method customerId = bean.getClass().getMethod("getCustomerId", (Class<?>[]) null);
    assertEquals(true, IntrospectionSupport.isGetter(customerId));
    assertEquals(false, IntrospectionSupport.isSetter(customerId));
    Method goldCustomer = bean.getClass().getMethod("isGoldCustomer", (Class<?>[]) null);
    assertEquals(true, IntrospectionSupport.isGetter(goldCustomer));
    assertEquals(false, IntrospectionSupport.isSetter(goldCustomer));
    Method silverCustomer = bean.getClass().getMethod("isSilverCustomer", (Class<?>[]) null);
    assertEquals(true, IntrospectionSupport.isGetter(silverCustomer));
    assertEquals(false, IntrospectionSupport.isSetter(silverCustomer));
    Method company = bean.getClass().getMethod("getCompany", (Class<?>[]) null);
    assertEquals(true, IntrospectionSupport.isGetter(company));
    assertEquals(false, IntrospectionSupport.isSetter(company));
    Method setupSomething = bean.getClass().getMethod("setupSomething", Object.class);
    assertEquals(false, IntrospectionSupport.isGetter(setupSomething));
    assertEquals(false, IntrospectionSupport.isSetter(setupSomething));
}

12. IntrospectionSupportTest#testOtherIsSetter()

Project: camel
Source File: IntrospectionSupportTest.java
View license
public void testOtherIsSetter() throws Exception {
    OtherExampleBean bean = new OtherExampleBean();
    Method customerId = bean.getClass().getMethod("setCustomerId", int.class);
    assertEquals(false, IntrospectionSupport.isGetter(customerId));
    assertEquals(true, IntrospectionSupport.isSetter(customerId));
    Method goldCustomer = bean.getClass().getMethod("setGoldCustomer", boolean.class);
    assertEquals(false, IntrospectionSupport.isGetter(goldCustomer));
    assertEquals(true, IntrospectionSupport.isSetter(goldCustomer));
    Method silverCustomer = bean.getClass().getMethod("setSilverCustomer", Boolean.class);
    assertEquals(false, IntrospectionSupport.isGetter(silverCustomer));
    assertEquals(true, IntrospectionSupport.isSetter(silverCustomer));
    Method company = bean.getClass().getMethod("setCompany", String.class);
    assertEquals(false, IntrospectionSupport.isGetter(company));
    assertEquals(true, IntrospectionSupport.isSetter(company));
    Method setupSomething = bean.getClass().getMethod("setupSomething", Object.class);
    assertEquals(false, IntrospectionSupport.isGetter(setupSomething));
    assertEquals(false, IntrospectionSupport.isSetter(setupSomething));
}

13. DexMakerTest#testFloatBinaryOps()

Project: dexmaker
Source File: DexMakerTest.java
View license
public void testFloatBinaryOps() throws Exception {
    Method add = binaryOpMethod(float.class, float.class, BinaryOp.ADD);
    assertEquals(6.75f, add.invoke(null, 5.5f, 1.25f));
    Method subtract = binaryOpMethod(float.class, float.class, BinaryOp.SUBTRACT);
    assertEquals(4.25f, subtract.invoke(null, 5.5f, 1.25f));
    Method multiply = binaryOpMethod(float.class, float.class, BinaryOp.MULTIPLY);
    assertEquals(6.875f, multiply.invoke(null, 5.5f, 1.25f));
    Method divide = binaryOpMethod(float.class, float.class, BinaryOp.DIVIDE);
    assertEquals(4.4f, divide.invoke(null, 5.5f, 1.25f));
    assertEquals(Float.POSITIVE_INFINITY, divide.invoke(null, 5.5f, 0.0f));
    Method remainder = binaryOpMethod(float.class, float.class, BinaryOp.REMAINDER);
    assertEquals(0.5f, remainder.invoke(null, 5.5f, 1.25f));
    assertEquals(Float.NaN, remainder.invoke(null, 5.5f, 0.0f));
}

14. DexMakerTest#testDoubleBinaryOps()

Project: dexmaker
Source File: DexMakerTest.java
View license
public void testDoubleBinaryOps() throws Exception {
    Method add = binaryOpMethod(double.class, double.class, BinaryOp.ADD);
    assertEquals(6.75, add.invoke(null, 5.5, 1.25));
    Method subtract = binaryOpMethod(double.class, double.class, BinaryOp.SUBTRACT);
    assertEquals(4.25, subtract.invoke(null, 5.5, 1.25));
    Method multiply = binaryOpMethod(double.class, double.class, BinaryOp.MULTIPLY);
    assertEquals(6.875, multiply.invoke(null, 5.5, 1.25));
    Method divide = binaryOpMethod(double.class, double.class, BinaryOp.DIVIDE);
    assertEquals(4.4, divide.invoke(null, 5.5, 1.25));
    assertEquals(Double.POSITIVE_INFINITY, divide.invoke(null, 5.5, 0.0));
    Method remainder = binaryOpMethod(double.class, double.class, BinaryOp.REMAINDER);
    assertEquals(0.5, remainder.invoke(null, 5.5, 1.25));
    assertEquals(Double.NaN, remainder.invoke(null, 5.5, 0.0));
}

15. DexMakerTest#testArrayLength()

Project: dexmaker
Source File: DexMakerTest.java
View license
public void testArrayLength() throws Exception {
    Method booleanArrayLength = arrayLengthMethod(BOOLEAN_ARRAY);
    assertEquals(0, booleanArrayLength.invoke(null, new Object[] { new boolean[0] }));
    assertEquals(5, booleanArrayLength.invoke(null, new Object[] { new boolean[5] }));
    Method intArrayLength = arrayLengthMethod(INT_ARRAY);
    assertEquals(0, intArrayLength.invoke(null, new Object[] { new int[0] }));
    assertEquals(5, intArrayLength.invoke(null, new Object[] { new int[5] }));
    Method longArrayLength = arrayLengthMethod(LONG_ARRAY);
    assertEquals(0, longArrayLength.invoke(null, new Object[] { new long[0] }));
    assertEquals(5, longArrayLength.invoke(null, new Object[] { new long[5] }));
    Method objectArrayLength = arrayLengthMethod(OBJECT_ARRAY);
    assertEquals(0, objectArrayLength.invoke(null, new Object[] { new Object[0] }));
    assertEquals(5, objectArrayLength.invoke(null, new Object[] { new Object[5] }));
    Method long2dArrayLength = arrayLengthMethod(LONG_2D_ARRAY);
    assertEquals(0, long2dArrayLength.invoke(null, new Object[] { new long[0][0] }));
    assertEquals(5, long2dArrayLength.invoke(null, new Object[] { new long[5][10] }));
}

16. DexMakerTest#testNewArray()

Project: dexmaker
Source File: DexMakerTest.java
View license
public void testNewArray() throws Exception {
    Method newBooleanArray = newArrayMethod(BOOLEAN_ARRAY);
    assertEquals("[]", Arrays.toString((boolean[]) newBooleanArray.invoke(null, 0)));
    assertEquals("[false, false, false]", Arrays.toString((boolean[]) newBooleanArray.invoke(null, 3)));
    Method newIntArray = newArrayMethod(INT_ARRAY);
    assertEquals("[]", Arrays.toString((int[]) newIntArray.invoke(null, 0)));
    assertEquals("[0, 0, 0]", Arrays.toString((int[]) newIntArray.invoke(null, 3)));
    Method newLongArray = newArrayMethod(LONG_ARRAY);
    assertEquals("[]", Arrays.toString((long[]) newLongArray.invoke(null, 0)));
    assertEquals("[0, 0, 0]", Arrays.toString((long[]) newLongArray.invoke(null, 3)));
    Method newObjectArray = newArrayMethod(OBJECT_ARRAY);
    assertEquals("[]", Arrays.toString((Object[]) newObjectArray.invoke(null, 0)));
    assertEquals("[null, null, null]", Arrays.toString((Object[]) newObjectArray.invoke(null, 3)));
    Method new2dLongArray = newArrayMethod(LONG_2D_ARRAY);
    assertEquals("[]", Arrays.deepToString((long[][]) new2dLongArray.invoke(null, 0)));
    assertEquals("[null, null, null]", Arrays.deepToString((long[][]) new2dLongArray.invoke(null, 3)));
}

17. DirectByteBufferUtils#destroyDirectByteBuffer()

View license
/**
     * Clear and release the internal content of a direct [email protected] ByteBuffer}.
     * Clearing manually the content avoid waiting till the GC do his job.
     * @param buffer : the buffer to clear
     * @throws IllegalArgumentException
     * @throws IllegalAccessException
     * @throws InvocationTargetException
     * @throws SecurityException
     * @throws NoSuchMethodException
     */
public static void destroyDirectByteBuffer(final ByteBuffer buffer) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
    checkArgument(buffer.isDirect(), "toBeDestroyed isn't direct!");
    Method cleanerMethod = buffer.getClass().getMethod("cleaner");
    cleanerMethod.setAccessible(true);
    Object cleaner = cleanerMethod.invoke(buffer);
    Method cleanMethod = cleaner.getClass().getMethod("clean");
    cleanMethod.setAccessible(true);
    cleanMethod.invoke(cleaner);
}

18. CompileAndRunTest#test_BigDecimal_operators()

Project: golo-lang
Source File: CompileAndRunTest.java
View license
@Test
public void test_BigDecimal_operators() throws Throwable {
    Class<?> moduleClass = compileAndLoadGoloModule(SRC, "operators.golo");
    Method plus = moduleClass.getMethod("plus", Object.class, Object.class);
    Method minus = moduleClass.getMethod("minus", Object.class, Object.class);
    Method divide = moduleClass.getMethod("divide", Object.class, Object.class);
    Method multiply = moduleClass.getMethod("multiply", Object.class, Object.class);
    Method modulo = moduleClass.getMethod("modulo", Object.class, Object.class);
    for (Object other : asList(2.0, 2.0f, 2L, 2, BigInteger.valueOf(2), BigDecimal.valueOf(2.0))) {
        checkDecimalOp(plus, BigDecimal.valueOf(2.2), other, 4.2, 4.2);
        checkDecimalOp(minus, BigDecimal.valueOf(2.2), other, 0.2, -0.2);
        checkDecimalOp(divide, BigDecimal.valueOf(0.5), other, 0.25, 4.0);
        checkDecimalOp(multiply, BigDecimal.valueOf(2.1), other, 4.2, 4.2);
        checkDecimalOp(modulo, BigDecimal.valueOf(2.5), other, 0.5, 2.0);
    }
}

19. CompileAndRunTest#test_BigInteger_operators()

Project: golo-lang
Source File: CompileAndRunTest.java
View license
@Test
public void test_BigInteger_operators() throws Throwable {
    Class<?> moduleClass = compileAndLoadGoloModule(SRC, "operators.golo");
    Method plus = moduleClass.getMethod("plus", Object.class, Object.class);
    Method minus = moduleClass.getMethod("minus", Object.class, Object.class);
    Method divide = moduleClass.getMethod("divide", Object.class, Object.class);
    Method multiply = moduleClass.getMethod("multiply", Object.class, Object.class);
    Method modulo = moduleClass.getMethod("modulo", Object.class, Object.class);
    for (Object other : asList(2L, 2, BigInteger.valueOf(2))) {
        checkIntegerOp(plus, BigInteger.valueOf(4L), other, 6, 6);
        checkIntegerOp(minus, BigInteger.valueOf(4L), other, 2, -2);
        checkIntegerOp(divide, BigInteger.valueOf(4L), other, 2, 0);
        checkIntegerOp(multiply, BigInteger.valueOf(4L), other, 8, 8);
        checkIntegerOp(modulo, BigInteger.valueOf(4L), other, 0, 2);
        checkIntegerOp(modulo, BigInteger.valueOf(3L), other, 1, 2);
    }
    for (Object other : asList(2.5, 2.5f, BigDecimal.valueOf(2.5))) {
        checkDecimalOp(plus, BigInteger.valueOf(4L), other, 6.5, 6.5);
        checkDecimalOp(minus, BigInteger.valueOf(4L), other, 1.5, -1.5);
        checkDecimalOp(divide, BigInteger.valueOf(4L), other, 1.6, 0.625);
        checkDecimalOp(multiply, BigInteger.valueOf(4L), other, 10.0, 10.0);
        checkDecimalOp(modulo, BigInteger.valueOf(4L), other, 1.5, 2.5);
    }
}

20. CompileAndRunTest#module_state()

Project: golo-lang
Source File: CompileAndRunTest.java
View license
@Test
public void module_state() throws Throwable {
    Class<?> moduleClass = compileAndLoadGoloModule(SRC, "module-state.golo");
    Method riseUp = moduleClass.getMethod("riseUp");
    Object result = riseUp.invoke(null);
    assertThat(result, is((Object) 1));
    Method display = moduleClass.getMethod("display");
    result = display.invoke(null);
    assertThat(result, is((Object) ">>> 1"));
    riseUp.invoke(null);
    result = display.invoke(null);
    assertThat(result, is((Object) ">>> 2"));
    Method for_fun = moduleClass.getMethod("for_fun");
    result = for_fun.invoke(null);
    assertThat(result, is((Object) ">>> 12"));
    Method give_foo = moduleClass.getMethod("give_foo");
    result = give_foo.invoke(null);
    assertThat(result, is((Object) "Foo!"));
}

21. DirectMemoryUtils#destroyDirectByteBuffer()

Project: hindex
Source File: DirectMemoryUtils.java
View license
/**
   * DirectByteBuffers are garbage collected by using a phantom reference and a
   * reference queue. Every once a while, the JVM checks the reference queue and
   * cleans the DirectByteBuffers. However, as this doesn't happen
   * immediately after discarding all references to a DirectByteBuffer, it's
   * easy to OutOfMemoryError yourself using DirectByteBuffers. This function
   * explicitly calls the Cleaner method of a DirectByteBuffer.
   * 
   * @param toBeDestroyed
   *          The DirectByteBuffer that will be "cleaned". Utilizes reflection.
   *          
   */
public static void destroyDirectByteBuffer(ByteBuffer toBeDestroyed) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
    Preconditions.checkArgument(toBeDestroyed.isDirect(), "toBeDestroyed isn't direct!");
    Method cleanerMethod = toBeDestroyed.getClass().getMethod("cleaner");
    cleanerMethod.setAccessible(true);
    Object cleaner = cleanerMethod.invoke(toBeDestroyed);
    Method cleanMethod = cleaner.getClass().getMethod("clean");
    cleanMethod.setAccessible(true);
    cleanMethod.invoke(cleaner);
}

22. ClientAuthenticationManagerTest#testClientProvidersPropagation()

View license
private void testClientProvidersPropagation(Class<?> type, ClientAuthenticationManager client, ClientAuthenticationManager session) throws Exception {
    String baseName = type.getSimpleName();
    outputDebugMessage("testClientProvidersPropagation(%s)", baseName);
    assertTrue(baseName + ": not an interface", type.isInterface());
    Method getter = ClientAuthenticationManager.class.getMethod("get" + baseName);
    Method setter = ClientAuthenticationManager.class.getMethod("set" + baseName, type);
    Object clientProvider = Mockito.mock(type);
    setter.invoke(client, clientProvider);
    assertSame(baseName + ": mismatched client-only provider", clientProvider, getter.invoke(session));
    Object sessionProvider = Mockito.mock(type);
    setter.invoke(session, sessionProvider);
    assertSame(baseName + ": mismatched session override provider", sessionProvider, getter.invoke(session));
    setter.invoke(session, new Object[] { null });
    assertSame(baseName + ": mismatched nullified session provider", clientProvider, getter.invoke(session));
}

23. RedefineClassTest#loadAgent()

Project: openjdk
Source File: RedefineClassTest.java
View license
public static void loadAgent(Path agent) throws Exception {
    String vmName = ManagementFactory.getRuntimeMXBean().getName();
    int p = vmName.indexOf('@');
    assumeTrue(p != -1);
    String pid = vmName.substring(0, p);
    ClassLoader cl = ToolProvider.getSystemToolClassLoader();
    Class<?> c = Class.forName("com.sun.tools.attach.VirtualMachine", true, cl);
    Method attach = c.getDeclaredMethod("attach", String.class);
    Method loadAgent = c.getDeclaredMethod("loadAgent", String.class, String.class);
    Method detach = c.getDeclaredMethod("detach");
    Object vm = attach.invoke(null, pid);
    loadAgent.invoke(vm, agent.toString(), "");
    detach.invoke(vm);
}

24. Regression636Test#testGetImplementationReflection()

Project: Resteasy
Source File: Regression636Test.java
View license
@Test
public void testGetImplementationReflection() throws Exception {
    Class updatableResource = BackendDataCenterResource.class.getInterfaces()[0].getInterfaces()[0];
    Assert.assertEquals(updatableResource, UpdatableResource.class);
    Method update = null;
    for (Method method : updatableResource.getMethods()) {
        if (method.getName().equals("update"))
            update = method;
    }
    Assert.assertNotNull(update);
    Method implemented = Types.getImplementingMethod(BackendDataCenterResource.class, update);
    Method actual = null;
    for (Method method : BackendDataCenterResource.class.getMethods()) {
        if (method.getName().equals("update") && !method.isSynthetic())
            actual = method;
    }
    Assert.assertEquals(implemented, actual);
}

25. AsyncLoadMethodMatchTest#testMatch_include()

View license
@Test
public void testMatch_include() {
    AsyncLoadPerl5RegexpMethodMatcher matcher = new AsyncLoadPerl5RegexpMethodMatcher();
    matcher.setPatterns(new String[] { METHOD1, METHOD2 });
    Method method1 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD1);
    Assert.assertTrue(matcher.matches(method1));
    Method method2 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD2);
    Assert.assertTrue(matcher.matches(method2));
    Method method3 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD3);
    Assert.assertFalse(matcher.matches(method3));
    Method method4 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD4);
    Assert.assertFalse(matcher.matches(method4));
}

26. AsyncLoadMethodMatchTest#testMatch_exclude()

View license
@Test
public void testMatch_exclude() {
    AsyncLoadPerl5RegexpMethodMatcher matcher = new AsyncLoadPerl5RegexpMethodMatcher();
    matcher.setPatterns(new String[] { METHOD1, METHOD2 });
    // ????????pattern???
    matcher.setExcludedPatterns(new String[] { METHOD2, METHOD4 });
    Method method1 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD1);
    Assert.assertTrue(matcher.matches(method1));
    Method method2 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD2);
    Assert.assertFalse(matcher.matches(method2));
    Method method3 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD3);
    Assert.assertFalse(matcher.matches(method3));
    Method method4 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD4);
    Assert.assertFalse(matcher.matches(method4));
}

27. AsyncLoadMethodMatchTest#testMatch_includeOveride()

View license
@Test
public void testMatch_includeOveride() {
    AsyncLoadPerl5RegexpMethodMatcher matcher = new AsyncLoadPerl5RegexpMethodMatcher();
    matcher.setExcludedPatterns(new String[] { METHOD3, METHOD4 });
    matcher.setExcludeOveride(true);
    Method method1 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD1);
    Assert.assertTrue(matcher.matches(method1));
    Method method2 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD2);
    Assert.assertTrue(matcher.matches(method2));
    Method method3 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD3);
    Assert.assertFalse(matcher.matches(method3));
    Method method4 = ReflectionUtils.findMethod(MethodMatchMock.class, METHOD4);
    Assert.assertFalse(matcher.matches(method4));
}

28. TestBoneCP#testWatchConnection()

Project: bonecp
Source File: TestBoneCP.java
View license
/** Tests for watch connection.
	 * @throws SecurityException
	 * @throws NoSuchMethodException
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchFieldException
	 */
@Test
public void testWatchConnection() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchFieldException {
    Field field = testClass.getClass().getDeclaredField("closeConnectionExecutor");
    field.setAccessible(true);
    ExecutorService mockExecutor = EasyMock.createNiceMock(ExecutorService.class);
    field.set(testClass, mockExecutor);
    Method method = testClass.getClass().getDeclaredMethod("watchConnection", ConnectionHandle.class);
    method.setAccessible(true);
    expect(mockExecutor.submit((CloseThreadMonitor) anyObject())).andReturn(null).once();
    replay(mockExecutor);
    method.invoke(testClass, mockConnection);
    verify(mockExecutor);
    // Test #2: Code coverage
    method.invoke(testClass, new Object[] { null });
}

29. PushToRemotePresenterTest#testShowErrorNotificationWhenUpstreanBranchFailedToLoad()

Project: che
Source File: PushToRemotePresenterTest.java
View license
@Test
public void testShowErrorNotificationWhenUpstreanBranchFailedToLoad() throws Exception {
    presenter.updateRemoteBranches();
    verify(service).branchList(eq(devMachine), anyObject(), eq("r"), asyncRequestCallbackArrayBranchCaptor.capture());
    AsyncRequestCallback<List<Branch>> remoteBranches = asyncRequestCallbackArrayBranchCaptor.getValue();
    Method onSuccess = GwtReflectionUtils.getMethod(remoteBranches.getClass(), "onSuccess");
    onSuccess.invoke(remoteBranches, new ArrayList<>());
    verify(service).config(eq(devMachine), anyObject(), anyListOf(String.class), anyBoolean(), asyncRequestCallbackMapCaptor.capture());
    AsyncRequestCallback<Map<String, String>> mapCallback = asyncRequestCallbackMapCaptor.getValue();
    Method onFailureConfig = GwtReflectionUtils.getMethod(mapCallback.getClass(), "onFailure");
    onFailureConfig.invoke(mapCallback, mock(Throwable.class));
    verify(constant, times(2)).failedGettingConfig();
    verify(gitOutputConsoleFactory).create(anyString());
    verify(console).printError(anyString());
    verify(consolesPanelPresenter).addCommandOutput(anyString(), eq(console));
    verify(notificationManager).notify(anyString(), rootProjectConfig);
}

30. MethodValInferenceTest#testGetMethodMultiClassAndMethodNames()

View license
public void testGetMethodMultiClassAndMethodNames(@ClassVal({ "java.lang.Object", "java.lang.String" }) Class<?> twoClasses, @ClassVal({ "java.lang.Object" }) Class<?> oneClass, @StringVal({ "method1" }) String oneName, @StringVal({ "method1", "method2" }) String twoNames, Class<?> @ArrayLen(2)[] classArray2, Class<?>[] classArrayUnknown) throws Exception {
    @MethodVal(className = { "java.lang.Object" }, methodName = { "method1" }, params = -1) Method m1 = oneClass.getMethod(oneName, classArrayUnknown);
    @MethodVal(className = { "java.lang.Object", "java.lang.Object" }, methodName = { "method1", "method2" }, params = { -1, -1 }) Method m2 = oneClass.getMethod(twoNames, classArrayUnknown);
    @MethodVal(className = { "java.lang.Object", "java.lang.String" }, methodName = { "method1", "method1" }, params = { -1, -1 }) Method m3 = twoClasses.getMethod(oneName, classArrayUnknown);
    @MethodVal(className = { "java.lang.Object", "java.lang.String", "java.lang.Object", "java.lang.String" }, methodName = { "method1", "method2", "method2", "method1" }, params = { -1, -1, -1, -1 }) Method m4 = twoClasses.getMethod(twoNames, classArrayUnknown);
}

31. DetailASTTest#testInsertSiblingBetween()

Project: checkstyle
Source File: DetailASTTest.java
View license
@Test
public void testInsertSiblingBetween() throws Exception {
    final DetailAST root = new DetailAST();
    final DetailAST firstLevelA = new DetailAST();
    final DetailAST firstLevelB = new DetailAST();
    final DetailAST firstLevelC = new DetailAST();
    assertEquals(0, root.getChildCount());
    root.setFirstChild(firstLevelA);
    final Method setParentMethod = getSetParentMethod();
    setParentMethod.invoke(firstLevelA, root);
    assertEquals(1, root.getChildCount());
    firstLevelA.addNextSibling(firstLevelB);
    setParentMethod.invoke(firstLevelB, root);
    assertEquals(firstLevelB, firstLevelA.getNextSibling());
    firstLevelA.addNextSibling(firstLevelC);
    setParentMethod.invoke(firstLevelC, root);
    assertEquals(firstLevelC, firstLevelA.getNextSibling());
}

32. DexMakerTest#testCastIntegerToFloatingPoint()

Project: dexmaker
Source File: DexMakerTest.java
View license
public void testCastIntegerToFloatingPoint() throws Exception {
    Method intToFloat = numericCastingMethod(int.class, float.class);
    assertEquals(0.0f, intToFloat.invoke(null, 0));
    assertEquals(-1.0f, intToFloat.invoke(null, -1));
    assertEquals(16777216f, intToFloat.invoke(null, 16777216));
    // precision
    assertEquals(16777216f, intToFloat.invoke(null, 16777217));
    Method intToDouble = numericCastingMethod(int.class, double.class);
    assertEquals(0.0, intToDouble.invoke(null, 0));
    assertEquals(-1.0, intToDouble.invoke(null, -1));
    assertEquals(16777216.0, intToDouble.invoke(null, 16777216));
    assertEquals(16777217.0, intToDouble.invoke(null, 16777217));
    Method longToFloat = numericCastingMethod(long.class, float.class);
    assertEquals(0.0f, longToFloat.invoke(null, 0L));
    assertEquals(-1.0f, longToFloat.invoke(null, -1L));
    assertEquals(16777216f, longToFloat.invoke(null, 16777216L));
    assertEquals(16777216f, longToFloat.invoke(null, 16777217L));
    Method longToDouble = numericCastingMethod(long.class, double.class);
    assertEquals(0.0, longToDouble.invoke(null, 0L));
    assertEquals(-1.0, longToDouble.invoke(null, -1L));
    assertEquals(9007199254740992.0, longToDouble.invoke(null, 9007199254740992L));
    // precision
    assertEquals(9007199254740992.0, longToDouble.invoke(null, 9007199254740993L));
}

33. DexMakerTest#testNegate()

Project: dexmaker
Source File: DexMakerTest.java
View license
public void testNegate() throws Exception {
    Method negateInteger = negateMethod(int.class);
    assertEquals(0, negateInteger.invoke(null, 0));
    assertEquals(-1, negateInteger.invoke(null, 1));
    assertEquals(Integer.MIN_VALUE, negateInteger.invoke(null, Integer.MIN_VALUE));
    Method negateLong = negateMethod(long.class);
    assertEquals(0L, negateLong.invoke(null, 0));
    assertEquals(-1L, negateLong.invoke(null, 1));
    assertEquals(Long.MIN_VALUE, negateLong.invoke(null, Long.MIN_VALUE));
    Method negateFloat = negateMethod(float.class);
    assertEquals(-0.0f, negateFloat.invoke(null, 0.0f));
    assertEquals(-1.0f, negateFloat.invoke(null, 1.0f));
    assertEquals(Float.NaN, negateFloat.invoke(null, Float.NaN));
    assertEquals(Float.POSITIVE_INFINITY, negateFloat.invoke(null, Float.NEGATIVE_INFINITY));
    Method negateDouble = negateMethod(double.class);
    assertEquals(-0.0, negateDouble.invoke(null, 0.0));
    assertEquals(-1.0, negateDouble.invoke(null, 1.0));
    assertEquals(Double.NaN, negateDouble.invoke(null, Double.NaN));
    assertEquals(Double.POSITIVE_INFINITY, negateDouble.invoke(null, Double.NEGATIVE_INFINITY));
}

34. NoteStoreClientTest#testWrappedMethods()

View license
@Test
public void testWrappedMethods() {
    Method[] originalMethods = NoteStoreIface.class.getDeclaredMethods();
    Method[] wrappedMethods = NoteStoreClient.class.getDeclaredMethods();
    Set<String> originalMethodNames = new HashSet<String>();
    for (Method m : originalMethods) {
        originalMethodNames.add(m.getName());
    }
    for (Method m : wrappedMethods) {
        if (originalMethodNames.contains(m.getName())) {
            originalMethodNames.remove(m.getName());
        }
    }
    if (!originalMethodNames.isEmpty()) {
        fail("Following methods are not implemented: " + originalMethodNames.toString());
    }
}

35. UserStoreClientTest#testWrappedMethods()

View license
@Test
public void testWrappedMethods() {
    Method[] originalMethods = UserStoreIface.class.getDeclaredMethods();
    Method[] wrappedMethods = UserStoreClient.class.getDeclaredMethods();
    Set<String> originalMethodNames = new HashSet<String>();
    for (Method m : originalMethods) {
        originalMethodNames.add(m.getName());
    }
    for (Method m : wrappedMethods) {
        if (originalMethodNames.contains(m.getName())) {
            originalMethodNames.remove(m.getName());
        }
    }
    if (!originalMethodNames.isEmpty()) {
        fail("Following methods are not implemented: " + originalMethodNames.toString());
    }
}

36. CompileAndRunTest#test_loopings()

Project: golo-lang
Source File: CompileAndRunTest.java
View license
@Test
public void test_loopings() throws Throwable {
    Class<?> moduleClass = compileAndLoadGoloModule(SRC, "loopings.golo");
    Method times = moduleClass.getMethod("times", Object.class);
    assertThat((Integer) times.invoke(null, 0), is(0));
    assertThat((Integer) times.invoke(null, 1), is(1));
    assertThat((Integer) times.invoke(null, 5), is(5));
    Method fact = moduleClass.getMethod("fact", Object.class, Object.class);
    assertThat(fact.invoke(null, 10, -1), nullValue());
    assertThat((Integer) fact.invoke(null, 10, 0), is(1));
    assertThat((Integer) fact.invoke(null, 10, 1), is(10));
    assertThat((Integer) fact.invoke(null, 10, 2), is(100));
    Method concat_to_string = moduleClass.getMethod("concat_to_string", Object.class);
    assertThat((String) concat_to_string.invoke(null, asList("a", "b", "c")), is("abc"));
    Method foreach_guarded = moduleClass.getMethod("foreach_guarded", Object.class);
    assertThat(foreach_guarded.invoke(null, asList(666, 2, 3, 4, 5, 10, 999)), is("66610999"));
}

37. MetricsDynamicBinding#configure()

View license
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
    final Method resourceMethod = resourceInfo.getResourceMethod();
    if (resourceMethod.isAnnotationPresent(Timed.class)) {
        LOG.debug("Setting up filter for Timed resource method: {}#{}", resourceInfo.getResourceClass().getCanonicalName(), resourceMethod.getName());
        context.register(new TimedMetricsFilter(metricRegistry, resourceInfo));
    }
    if (resourceMethod.isAnnotationPresent(Metered.class)) {
        LOG.debug("Setting up filter for Metered resource method: {}#{}", resourceInfo.getResourceClass().getCanonicalName(), resourceMethod.getName());
        context.register(new MeteredMetricsFilter(metricRegistry, resourceInfo));
    }
    if (resourceMethod.isAnnotationPresent(ExceptionMetered.class)) {
        LOG.debug("Setting up filter for ExceptionMetered resource method: {}#{}", resourceInfo.getResourceClass().getCanonicalName(), resourceMethod.getName());
        context.register(new ExceptionMeteredMetricsFilter(metricRegistry, resourceInfo));
    }
}

38. Jersey2Plugin#getContainerClasses()

Project: HotswapAgent
Source File: Jersey2Plugin.java
View license
/**
     * Gets a list of classes used in configure the Jersey Application
     */
private Set<Class<?>> getContainerClasses(Class<?> resourceConfigClass, Object resourceConfig) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Method scanClassesMethod = resourceConfigClass.getDeclaredMethod("scanClasses");
    scanClassesMethod.setAccessible(true);
    @SuppressWarnings("unchecked") Set<Class<?>> scannedClasses = (Set<Class<?>>) scanClassesMethod.invoke(resourceConfig);
    Method getRegisteredClassesMethod = resourceConfigClass.getDeclaredMethod("getRegisteredClasses");
    getRegisteredClassesMethod.setAccessible(true);
    @SuppressWarnings("unchecked") Set<Class<?>> registeredClasses = (Set<Class<?>>) getRegisteredClassesMethod.invoke(resourceConfig);
    Set<Class<?>> containerClasses = Collections.newSetFromMap(new WeakHashMap<Class<?>, Boolean>());
    containerClasses.addAll(scannedClasses);
    containerClasses.addAll(registeredClasses);
    return containerClasses;
}

39. EventSetDescriptorTest#testEventSetDescriptorStringClassMethodArrayMethodMethodMethod()

Project: j2objc
Source File: EventSetDescriptorTest.java
View license
/*
     * Class under test for void EventSetDescriptor(String, Class, Method[],
     * Method, Method, Method)
     */
public void testEventSetDescriptorStringClassMethodArrayMethodMethodMethod() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String eventSetName = "MockPropertyChange";
    Class<?> listenerType = MockPropertyChangeListener.class;
    Method[] listenerMethods = new Method[] { listenerType.getMethod("mockPropertyChange", new Class[] { MockPropertyChangeEvent.class }), listenerType.getMethod("mockPropertyChange2", new Class[] { MockPropertyChangeEvent.class }) };
    Class<MockSourceClass> sourceClass = MockSourceClass.class;
    Method addMethod = sourceClass.getMethod("addMockPropertyChangeListener", new Class[] { listenerType });
    Method removeMethod = sourceClass.getMethod("removeMockPropertyChangeListener", new Class[] { listenerType });
    Method getMethod = sourceClass.getMethod("getMockPropertyChangeListener", new Class[] { listenerType });
    EventSetDescriptor esd = new EventSetDescriptor(eventSetName, listenerType, listenerMethods, addMethod, removeMethod, getMethod);
    assertEquals(getMethod, esd.getGetListenerMethod());
}

40. EventSetDescriptorTest#testEventSetDescriptorStringClassMethodArrayMethodMethodMethod_getListenerMethodInvalid()

Project: j2objc
Source File: EventSetDescriptorTest.java
View license
/*
     * getListenerMethod is invalid
     */
public void testEventSetDescriptorStringClassMethodArrayMethodMethodMethod_getListenerMethodInvalid() throws IntrospectionException, NoSuchMethodException {
    String eventSetName = "MockPropertyChange";
    Class<?> listenerType = MockPropertyChangeListener.class;
    Method[] listenerMethods = new Method[] { listenerType.getMethod("mockPropertyChange", new Class[] { MockPropertyChangeEvent.class }), listenerType.getMethod("mockPropertyChange2", new Class[] { MockPropertyChangeEvent.class }) };
    Class<MockSourceClass> sourceClass = MockSourceClass.class;
    Method addMethod = sourceClass.getMethod("addMockPropertyChangeListener", new Class[] { listenerType });
    Method removeMethod = sourceClass.getMethod("removeMockPropertyChangeListener", new Class[] { listenerType });
    Method getMethod = sourceClass.getMethod("addMockPropertyChangeListener_Invalid", (Class[]) null);
    EventSetDescriptor esd = new EventSetDescriptor(eventSetName, listenerType, listenerMethods, addMethod, removeMethod, getMethod);
    assertEquals(getMethod, esd.getGetListenerMethod());
}

41. IndexedPropertyDescriptorTest#testEquals_ReadMethod()

View license
/*
     * Read method
     */
public void testEquals_ReadMethod() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("getPropertyFive", (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(propertyName, beanClass);
    assertFalse(ipd.equals(ipd2));
}

42. IndexedPropertyDescriptorTest#testEquals_ReadMethodNull()

View license
/*
     * read method null.
     */
public void testEquals_ReadMethodNull() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = null;
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(propertyName, beanClass);
    assertFalse(ipd.equals(ipd2));
}

43. IndexedPropertyDescriptorTest#testEquals_WriteMethod()

View license
public void testEquals_WriteMethod() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("setPropertyFive", new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(propertyName, beanClass);
    assertFalse(ipd.equals(ipd2));
}

44. IndexedPropertyDescriptorTest#testEquals_WriteMethodNull()

View license
/*
     * write method null.
     */
public void testEquals_WriteMethodNull() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = null;
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(propertyName, beanClass);
    assertFalse(ipd.equals(ipd2));
}

45. IndexedPropertyDescriptorTest#testEquals_IndexedR()

View license
/*
     * Indexed read method.
     */
public void testEquals_IndexedR() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("getPropertyFive", new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(propertyName, beanClass);
    assertFalse(ipd.equals(ipd2));
}

46. IndexedPropertyDescriptorTest#testEquals_IndexedRNull()

View license
/*
     * Indexed read method null.
     */
public void testEquals_IndexedRNull() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = null;
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(propertyName, beanClass);
    assertFalse(ipd.equals(ipd2));
}

47. IndexedPropertyDescriptorTest#testEquals_IndexedW()

View license
/*
     * indexed write method.
     */
public void testEquals_IndexedW() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("setPropertyFive", new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(propertyName, beanClass);
    assertFalse(ipd.equals(ipd2));
}

48. IndexedPropertyDescriptorTest#testEquals_IndexWNull()

View license
/*
     * Indexed write method null.
     */
public void testEquals_IndexWNull() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = null;
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(propertyName, beanClass);
    assertFalse(ipd.equals(ipd2));
}

49. IndexedPropertyDescriptorTest#testEquals_PropertyType()

View license
/*
     * Property Type.
     */
public void testEquals_PropertyType() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor("PropertySix", beanClass);
    assertFalse(ipd.getPropertyType().equals(ipd2.getPropertyType()));
    assertFalse(ipd.equals(ipd2));
}

50. IndexedPropertyDescriptorTest#testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propNull()

View license
/*
     * propertyName=null
     */
public void testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propNull() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    try {
        new IndexedPropertyDescriptor(null, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
        fail("Should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    }
}

51. IndexedPropertyDescriptorTest#testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propEmpty()

View license
/*
     * propertyname="";
     */
public void testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propEmpty() throws SecurityException, NoSuchMethodException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    try {
        new IndexedPropertyDescriptor("", readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
        fail("Should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    }
}

52. IndexedPropertyDescriptorTest#testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propInvalid()

View license
public void testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propInvalid() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    String invalidName = "An Invalid Property name";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(invalidName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    assertEquals(invalidName, ipd.getName());
    assertEquals(String.class, ipd.getIndexedPropertyType());
}

53. IndexedPropertyDescriptorTest#testIndexedPropertyDescriptorStringMethodMethodMethodMethod_RWIncompatible()

View license
/*
     * read/write incompatible
     */
public void testIndexedPropertyDescriptorStringMethodMethodMethodMethod_RWIncompatible() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    String anotherProp = "PropertyFive";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + anotherProp, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    assertEquals(propertyName, ipd.getName());
    assertEquals(String[].class, ipd.getPropertyType());
    assertEquals(String.class, ipd.getIndexedPropertyType());
}

54. IndexedPropertyDescriptorTest#testSetIndexedReadMethod()

View license
public void testSetIndexedReadMethod() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, null, indexedWriteMethod);
    assertNull(ipd.getIndexedReadMethod());
    ipd.setIndexedReadMethod(indexedReadMethod);
    assertSame(indexedReadMethod, ipd.getIndexedReadMethod());
}

55. IndexedPropertyDescriptorTest#testSetIndexedReadMethod_null()

View license
public void testSetIndexedReadMethod_null() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    assertSame(indexedReadMethod, ipd.getIndexedReadMethod());
    ipd.setIndexedReadMethod(null);
    assertNull(ipd.getIndexedReadMethod());
}

56. IndexedPropertyDescriptorTest#testSetIndexedReadMethod_RInvalidArgs()

View license
/*
     * indexed read method without args
     */
public void testSetIndexedReadMethod_RInvalidArgs() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    assertSame(indexedReadMethod, ipd.getIndexedReadMethod());
    try {
        ipd.setIndexedReadMethod(readMethod);
        fail("Should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    }
}

57. IndexedPropertyDescriptorTest#testSetIndexedReadMethod_RInvalidArgType()

View license
/*
     * indexed read method with invalid arg type (!Integer.TYPE)
     */
public void testSetIndexedReadMethod_RInvalidArgType() throws SecurityException, NoSuchMethodException, IntrospectionException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    assertSame(indexedReadMethod, ipd.getIndexedReadMethod());
    try {
        ipd.setIndexedReadMethod(writeMethod);
        fail("Should throw IntrospectionException.");
    } catch (IntrospectionException e) {
    }
}

58. IndexedPropertyDescriptorTest#testSetIndexedWriteMethod_null()

View license
public void testSetIndexedWriteMethod_null() throws IntrospectionException, NoSuchMethodException, NoSuchMethodException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    assertSame(indexedWriteMethod, ipd.getIndexedWriteMethod());
    ipd.setIndexedWriteMethod(null);
    assertNull(ipd.getIndexedWriteMethod());
}

59. IndexedPropertyDescriptorTest#testSetIndexedWriteMethod()

View license
public void testSetIndexedWriteMethod() throws IntrospectionException, NoSuchMethodException, NoSuchMethodException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, null);
    assertNull(ipd.getIndexedWriteMethod());
    ipd.setIndexedWriteMethod(indexedWriteMethod);
    assertSame(indexedWriteMethod, ipd.getIndexedWriteMethod());
}

60. IndexedPropertyDescriptorTest#testSetIndexedWriteMethod_badargtype()

View license
/*
     * bad arg type
     */
public void testSetIndexedWriteMethod_badargtype() throws IntrospectionException, NoSuchMethodException, NoSuchMethodException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, null);
    assertNull(ipd.getIndexedWriteMethod());
    Method badArgType = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, Integer.TYPE });
    try {
        ipd.setIndexedWriteMethod(badArgType);
        fail("Should throw IntrospectionException");
    } catch (IntrospectionException e) {
    }
}

61. IndexedPropertyDescriptorTest#testSetIndexedWriteMethod_return()

View license
public void testSetIndexedWriteMethod_return() throws IntrospectionException, NoSuchMethodException, NoSuchMethodException {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, null);
    assertNull(ipd.getIndexedWriteMethod());
    Method badArgType = beanClass.getMethod("setPropertyFourInvalid", new Class[] { Integer.TYPE, String.class });
    ipd.setIndexedWriteMethod(badArgType);
    assertEquals(String.class, ipd.getIndexedPropertyType());
    assertEquals(String[].class, ipd.getPropertyType());
    assertEquals(Integer.TYPE, ipd.getIndexedWriteMethod().getReturnType());
}

62. IndexedPropertyDescriptorTest#testHashCode()

View license
public void testHashCode() throws Exception {
    String propertyName = "PropertyFour";
    Class<MockJavaBean> beanClass = MockJavaBean.class;
    Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null);
    Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String[].class });
    Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE });
    Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class });
    IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(propertyName, readMethod, writeMethod, indexedReadMethod, indexedWriteMethod);
    IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(propertyName, beanClass);
    assertEquals(ipd, ipd2);
    assertEquals(ipd.hashCode(), ipd2.hashCode());
}

63. bug7143614#validate()

Project: openjdk
Source File: bug7143614.java
View license
private static void validate() throws Exception {
    Method getSelectedUIMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUI");
    getSelectedUIMethod.setAccessible(true);
    Method getSelectedUIStateMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUIState");
    getSelectedUIStateMethod.setAccessible(true);
    if (getSelectedUIMethod.invoke(null) != componentUI) {
        throw new RuntimeException("getSelectedUI returns invalid value");
    }
    if (((Integer) getSelectedUIStateMethod.invoke(null)).intValue() != (SynthConstants.SELECTED | SynthConstants.FOCUSED)) {
        throw new RuntimeException("getSelectedUIState returns invalid value");
    }
}

64. OServerPluginManager#startPluginClass()

Project: orientdb
Source File: OServerPluginManager.java
View license
@SuppressWarnings("unchecked")
protected OServerPlugin startPluginClass(final URLClassLoader pluginClassLoader, final String iClassName, final OServerParameterConfiguration[] params) throws Exception {
    final Class<? extends OServerPlugin> classToLoad = (Class<? extends OServerPlugin>) Class.forName(iClassName, true, pluginClassLoader);
    final OServerPlugin instance = classToLoad.newInstance();
    // CONFIG()
    final Method configMethod = classToLoad.getDeclaredMethod("config", OServer.class, OServerParameterConfiguration[].class);
    configMethod.invoke(instance, server, params);
    // STARTUP()
    final Method startupMethod = classToLoad.getDeclaredMethod("startup");
    startupMethod.invoke(instance);
    return instance;
}

65. SqlMapClientTemplateIT#queryForListShouldBeTraced()

View license
@Test
public void queryForListShouldBeTraced() throws Exception {
    // Given
    final String queryForListId = "queryForListId";
    SqlMapClientTemplate clientTemplate = new SqlMapClientTemplate(this.mockDataSource, this.sqlMapClient);
    // When
    clientTemplate.queryForList(queryForListId);
    clientTemplate.queryForList(queryForListId, new Object());
    clientTemplate.queryForList(queryForListId, 0, 1);
    clientTemplate.queryForList(queryForListId, new Object(), 0, 1);
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method queryForList1 = SqlMapClientTemplate.class.getDeclaredMethod("queryForList", String.class);
    Method queryForList2 = SqlMapClientTemplate.class.getDeclaredMethod("queryForList", String.class, Object.class);
    Method queryForList3 = SqlMapClientTemplate.class.getDeclaredMethod("queryForList", String.class, int.class, int.class);
    Method queryForList4 = SqlMapClientTemplate.class.getDeclaredMethod("queryForList", String.class, Object.class, int.class, int.class);
    verifier.verifyTrace(event("IBATIS_SPRING", queryForList1, Expectations.cachedArgs(queryForListId)));
    verifier.verifyTrace(event("IBATIS_SPRING", queryForList2, Expectations.cachedArgs(queryForListId)));
    verifier.verifyTrace(event("IBATIS_SPRING", queryForList3, Expectations.cachedArgs(queryForListId)));
    verifier.verifyTrace(event("IBATIS_SPRING", queryForList4, Expectations.cachedArgs(queryForListId)));
}

66. SqlMapExecutorTestBase#testAndVerifyQueryForList()

View license
protected final void testAndVerifyQueryForList(SqlMapExecutor executor) throws Exception {
    final String queryForListId = "queryForListId";
    executor.queryForList(queryForListId);
    executor.queryForList(queryForListId, new Object());
    executor.queryForList(queryForListId, 0, 1);
    executor.queryForList(queryForListId, new Object(), 0, 1);
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method queryForList1 = executor.getClass().getDeclaredMethod("queryForList", String.class);
    Method queryForList2 = executor.getClass().getDeclaredMethod("queryForList", String.class, Object.class);
    Method queryForList3 = executor.getClass().getDeclaredMethod("queryForList", String.class, int.class, int.class);
    Method queryForList4 = executor.getClass().getDeclaredMethod("queryForList", String.class, Object.class, int.class, int.class);
    verifier.verifyTrace(event("IBATIS", queryForList1, Expectations.cachedArgs(queryForListId)));
    verifier.verifyTrace(event("IBATIS", queryForList2, Expectations.cachedArgs(queryForListId)));
    verifier.verifyTrace(event("IBATIS", queryForList3, Expectations.cachedArgs(queryForListId)));
    verifier.verifyTrace(event("IBATIS", queryForList4, Expectations.cachedArgs(queryForListId)));
}

67. MethodTypeTest#get()

Project: querydsl
Source File: MethodTypeTest.java
View license
@Test
public void get() throws SecurityException, NoSuchMethodException {
    Method getVal = MethodTypeTest.class.getMethod("getVal");
    Method hashCode = Object.class.getMethod("hashCode");
    Method size = Collection.class.getMethod("size");
    Method toString = Object.class.getMethod("toString");
    assertEquals(MethodType.GET_MAPPED_PATH, MethodType.get(ManagedObject.class.getMethod("__mappedPath")));
    assertEquals(MethodType.GETTER, MethodType.get(getVal));
    assertEquals(MethodType.HASH_CODE, MethodType.get(hashCode));
    assertEquals(MethodType.LIST_ACCESS, MethodType.get(List.class.getMethod("get", int.class)));
    assertEquals(MethodType.MAP_ACCESS, MethodType.get(Map.class.getMethod("get", Object.class)));
    assertEquals(MethodType.SIZE, MethodType.get(size));
    assertEquals(MethodType.TO_STRING, MethodType.get(toString));
}

68. ClassLoaderTest#testMultipleLoaders()

Project: santuario-java
Source File: ClassLoaderTest.java
View license
@SuppressWarnings("resource")
@org.junit.Test
public void testMultipleLoaders() throws Exception {
    String baseDir = System.getProperty("basedir");
    String fs = System.getProperty("file.separator");
    File file0 = new File(baseDir + fs + "build" + fs + "classes" + fs);
    File file1 = new File(baseDir + fs + "build" + fs + "test" + fs);
    URL[] urls = new URL[2];
    urls[0] = file0.toURI().toURL();
    urls[1] = file1.toURI().toURL();
    URLClassLoader uc1 = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
    URLClassLoader uc2 = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
    Class<?> c1 = uc1.loadClass("javax.xml.crypto.test.dsig.Driver");
    Class<?> c2 = uc2.loadClass("javax.xml.crypto.test.dsig.Driver");
    Object o1 = c1.newInstance();
    Object o2 = c2.newInstance();
    Method m1 = c1.getMethod("dsig", (Class[]) null);
    Method m2 = c2.getMethod("dsig", (Class[]) null);
    m1.invoke(o1, (Object[]) null);
    m2.invoke(o2, (Object[]) null);
}

69. ClassLoaderTest#testProviderMultipleLoadersTwo()

Project: santuario-java
Source File: ClassLoaderTest.java
View license
@SuppressWarnings("resource")
@org.junit.Test
public void testProviderMultipleLoadersTwo() throws Exception {
    String baseDir = System.getProperty("basedir");
    String fs = System.getProperty("file.separator");
    File file0 = new File(baseDir + fs + "build" + fs + "classes" + fs);
    File file1 = new File(baseDir + fs + "build" + fs + "test" + fs);
    URL[] urls = new URL[2];
    urls[0] = file0.toURI().toURL();
    urls[1] = file1.toURI().toURL();
    URLClassLoader uc1 = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
    URLClassLoader uc2 = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
    Class<?> c1 = uc1.loadClass("javax.xml.crypto.test.dsig.AppA");
    Class<?> c2 = uc2.loadClass("javax.xml.crypto.test.dsig.AppB");
    Object o1 = c1.newInstance();
    Object o2 = c2.newInstance();
    Method m1 = c1.getMethod("dsig", (Class[]) null);
    Method m2 = c2.getMethod("dsig", (Class[]) null);
    m1.invoke(o1, (Object[]) null);
    m2.invoke(o2, (Object[]) null);
}

70. BridgeMethodResolverTests#testWithGenericParameter()

View license
public void testWithGenericParameter() throws Exception {
    Method[] methods = StringGenericParameter.class.getMethods();
    Method bridgeMethod = null;
    Method bridgedMethod = null;
    for (Method method : methods) {
        if ("getFor".equals(method.getName()) && !method.getParameterTypes()[0].equals(Integer.class)) {
            if (method.getReturnType().equals(Object.class)) {
                bridgeMethod = method;
            } else {
                bridgedMethod = method;
            }
        }
    }
    assertTrue(bridgeMethod != null && bridgeMethod.isBridge());
    // see https://code.google.com/p/android/issues/detail?id=6636
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
        assertTrue(bridgedMethod != null && !bridgedMethod.isBridge());
        assertEquals(bridgedMethod, BridgeMethodResolver.findBridgedMethod(bridgeMethod));
    }
}

71. InjectionUtilTest#verifyMethodNames()

Project: transfuse
Source File: InjectionUtilTest.java
View license
@Test
public void verifyMethodNames() throws NoSuchMethodException {
    Method callConstructorMethod = InjectionUtil.class.getMethod(InjectionUtil.CALL_CONSTRUCTOR_METHOD, Class.class, Class[].class, Object[].class);
    assertNotNull(callConstructorMethod);
    Method callMethodMethod = InjectionUtil.class.getMethod(InjectionUtil.CALL_METHOD_METHOD, Class.class, Class.class, Object.class, String.class, Class[].class, Object[].class);
    assertNotNull(callMethodMethod);
    Method getFieldMethod = InjectionUtil.class.getMethod(InjectionUtil.GET_FIELD_METHOD, Class.class, Class.class, Object.class, String.class);
    assertNotNull(getFieldMethod);
    Method setFieldMethod = InjectionUtil.class.getMethod(InjectionUtil.SET_FIELD_METHOD, Class.class, Object.class, String.class, Object.class);
    assertNotNull(setFieldMethod);
}

72. NoStackParamValidationRule#validate()

View license
@Override
public void validate(Class<?> originalType, List<Method> methods) {
    Method aroundCall = invoker.findMethod(methods, AroundCall.class, originalType);
    Method afterCall = invoker.findMethod(methods, AfterCall.class, originalType);
    Method beforeCall = invoker.findMethod(methods, BeforeCall.class, originalType);
    Method accepts = invoker.findMethod(methods, Accepts.class, originalType);
    String interceptorStack = InterceptorStack.class.getName();
    String simpleInterceptorStack = SimpleInterceptorStack.class.getName();
    checkState(aroundCall == null || containsStack(aroundCall), "@AroundCall method must receive %s or %s", interceptorStack, simpleInterceptorStack);
    checkState(!containsStack(beforeCall) && !containsStack(afterCall) && !containsStack(accepts), "Non @AroundCall method must not receive %s or %s", interceptorStack, simpleInterceptorStack);
}

73. MapEntriesTest#test_getVanityPaths_1()

Project: sling
Source File: MapEntriesTest.java
View license
@Test
public //SLING-4891
void test_getVanityPaths_1() throws Exception {
    Field field1 = MapEntries.class.getDeclaredField("maxCachedVanityPathEntries");
    field1.setAccessible(true);
    field1.set(mapEntries, 0);
    Method method = MapEntries.class.getDeclaredMethod("getVanityPaths", String.class);
    method.setAccessible(true);
    method.invoke(mapEntries, "/notExisting");
    Field vanityCounter = MapEntries.class.getDeclaredField("vanityCounter");
    vanityCounter.setAccessible(true);
    AtomicLong counter = (AtomicLong) vanityCounter.get(mapEntries);
    assertEquals(0, counter.longValue());
}

74. BridgeMethodResolverTests#testSPR2583()

View license
public void testSPR2583() throws Exception {
    Method bridgedMethod = MessageBroadcasterImpl.class.getMethod("receive", MessageEvent.class);
    assertFalse(bridgedMethod.isBridge());
    Method bridgeMethod = MessageBroadcasterImpl.class.getMethod("receive", Event.class);
    assertTrue(bridgeMethod.isBridge());
    Method otherMethod = MessageBroadcasterImpl.class.getMethod("receive", NewMessageEvent.class);
    assertFalse(otherMethod.isBridge());
    Map<TypeVariable, Type> typeVariableMap = GenericTypeResolver.getTypeVariableMap(MessageBroadcasterImpl.class);
    assertFalse("Match identified incorrectly", BridgeMethodResolver.isBridgeMethodFor(bridgeMethod, otherMethod, typeVariableMap));
    assertTrue("Match not found correctly", BridgeMethodResolver.isBridgeMethodFor(bridgeMethod, bridgedMethod, typeVariableMap));
    assertEquals(bridgedMethod, BridgeMethodResolver.findBridgedMethod(bridgeMethod));
}

75. GenericTypeResolverTests#testResolveType()

View license
public void testResolveType() {
    Method intMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerInputMessage", MyInterfaceType.class);
    MethodParameter intMessageMethodParam = new MethodParameter(intMessageMethod, 0);
    assertEquals(MyInterfaceType.class, resolveType(intMessageMethodParam.getGenericParameterType(), new HashMap<TypeVariable, Type>()));
    Method intArrMessageMethod = findMethod(MyTypeWithMethods.class, "readIntegerArrayInputMessage", MyInterfaceType[].class);
    MethodParameter intArrMessageMethodParam = new MethodParameter(intArrMessageMethod, 0);
    assertEquals(MyInterfaceType[].class, resolveType(intArrMessageMethodParam.getGenericParameterType(), new HashMap<TypeVariable, Type>()));
    Method genericArrMessageMethod = findMethod(MySimpleTypeWithMethods.class, "readGenericArrayInputMessage", Object[].class);
    MethodParameter genericArrMessageMethodParam = new MethodParameter(genericArrMessageMethod, 0);
    Map<TypeVariable, Type> varMap = getTypeVariableMap(MySimpleTypeWithMethods.class);
    assertEquals(Integer[].class, resolveType(genericArrMessageMethodParam.getGenericParameterType(), varMap));
}

76. UtilsTests#toMethodDescriptor()

Project: spring-loaded
Source File: UtilsTests.java
View license
@Test
public void toMethodDescriptor() throws Exception {
    Method toStringMethod = Object.class.getDeclaredMethod("toString");
    assertEquals("()Ljava/lang/String;", Utils.toMethodDescriptor(toStringMethod, false));
    try {
        assertEquals("()Ljava/lang/String;", Utils.toMethodDescriptor(toStringMethod, true));
        fail();
    } catch (IllegalStateException ise) {
    }
    Method numberOfLeadingZerosMethod = Integer.class.getDeclaredMethod("numberOfLeadingZeros", Integer.TYPE);
    assertEquals("(I)I", Utils.toMethodDescriptor(numberOfLeadingZerosMethod, false));
    // First ( is skipped, caller is expected to build the first part
    assertEquals(")I", Utils.toMethodDescriptor(numberOfLeadingZerosMethod, true));
    Method valueOfMethod = Integer.class.getDeclaredMethod("valueOf", String.class, Integer.TYPE);
    assertEquals("(Ljava/lang/String;I)Ljava/lang/Integer;", Utils.toMethodDescriptor(valueOfMethod, false));
    assertEquals("(Ljava/lang/String;I)Ljava/lang/Integer;", Utils.toMethodDescriptor(valueOfMethod));
    assertEquals("I)Ljava/lang/Integer;", Utils.toMethodDescriptor(valueOfMethod, true));
}

77. StatementTest#closeOnCompletionTest()

Project: sqlite-jdbc
Source File: StatementTest.java
View license
@Test
public void closeOnCompletionTest() throws Exception {
    if (!(stat instanceof JDBC4Statement))
        return;
    // Run the following code only for JDK7 or higher
    Method mIsCloseOnCompletion = JDBC4Statement.class.getDeclaredMethod("isCloseOnCompletion");
    Method mCloseOnCompletion = JDBC4Statement.class.getDeclaredMethod("closeOnCompletion");
    assertFalse((Boolean) mIsCloseOnCompletion.invoke(stat));
    mCloseOnCompletion.invoke(stat);
    assertTrue((Boolean) mIsCloseOnCompletion.invoke(stat));
    ResultSet rs = stat.executeQuery("select 1");
    rs.close();
    assertTrue(stat.isClosed());
}

78. ConfigurationOptionTest#before()

View license
@Before
public void before() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    corePlugin = configuration.getConfig(CorePlugin.class);
    configuration.addConfigurationSource(configSource);
    configuration.reloadDynamicConfigurationOptions();
    Method registerPluginConfiguration = Configuration.class.getDeclaredMethod("registerOptionProvider", ConfigurationOptionProvider.class);
    registerPluginConfiguration.setAccessible(true);
    registerPluginConfiguration.invoke(configuration, new StagemonitorPlugin() {

        public List<ConfigurationOption<?>> getConfigurationOptions() {
            return Arrays.asList(invalidPatternMap, invalidPatternSyntax, aLong, invalidLong, string, lowerStrings, strings, booleanTrue, booleanFalse, booleanInvalid, testCaching, testUpdate);
        }
    });
}

79. CallCheckerTest#doCallChecker()

Project: thread-weaver
Source File: CallCheckerTest.java
View license
private void doCallChecker(Class<?> callingClass, boolean expectMethod3) throws Exception {
    CallChecker checker = new CallChecker();
    Map<Method, Set<Method>> calls = checker.getCallers(callingClass, SimpleClass.class, SimpleClass2.class);
    // We should record the first method in SimpleClass or SimpleClass2 called
    // by each of the methods in CallCheckerClass. We shouldn't record any calls
    // to SimpleClass3.
    assertEquals(expectMethod3 ? 4 : 3, calls.size());
    Method called1 = getSingleElem(CallCheckerClass.class.getDeclaredMethod("method1", int.class), calls);
    assertEquals(SimpleClass.class.getDeclaredMethod("add", int.class, int.class), called1);
    Method called2 = getSingleElem(CallCheckerClass.class.getDeclaredMethod("method1"), calls);
    assertEquals(SimpleClass.class.getDeclaredMethod("add", int.class, int.class), called2);
    Method called3 = getSingleElem(CallCheckerClass.class.getDeclaredMethod("method2"), calls);
    assertEquals(SimpleClass2.class.getDeclaredMethod("getValue"), called3);
    if (expectMethod3) {
        Method called4 = getSingleElem(CallCheckerClass.class.getDeclaredMethod("method3"), calls);
        assertEquals(SimpleClass2.class.getDeclaredMethod("getValue"), called4);
    }
}

80. Utils#callMethod()

Project: ThriftyPaxos
Source File: Utils.java
View license
private static Object callMethod(Object instance, Class<?> clazz, String methodName, Object... params) throws Exception {
    Method best = null;
    int bestMatch = 0;
    boolean isStatic = instance == null;
    for (Method m : clazz.getMethods()) {
        if (Modifier.isStatic(m.getModifiers()) == isStatic && m.getName().equals(methodName)) {
            int p = match(m.getParameterTypes(), params);
            if (p > bestMatch) {
                bestMatch = p;
                best = m;
            }
        }
    }
    if (best == null) {
        throw new NoSuchMethodException(methodName);
    }
    return best.invoke(instance, params);
}

81. TestOldVersion#testOldClientNewServer()

Project: ThriftyPaxos
Source File: TestOldVersion.java
View license
private void testOldClientNewServer() throws Exception {
    Server server = org.h2.tools.Server.createTcpServer("-tcpPort", "9001");
    server.start();
    assertThrows(ErrorCode.DRIVER_VERSION_ERROR_2, driver).connect("jdbc:h2:tcp://localhost:9001/mem:test", null);
    server.stop();
    Class<?> serverClass = cl.loadClass("org.h2.tools.Server");
    Method m;
    m = serverClass.getMethod("createTcpServer", String[].class);
    Object serverOld = m.invoke(null, new Object[] { new String[] { "-tcpPort", "9001" } });
    m = serverOld.getClass().getMethod("start");
    m.invoke(serverOld);
    Connection conn;
    conn = org.h2.Driver.load().connect("jdbc:h2:mem:", null);
    Statement stat = conn.createStatement();
    ResultSet rs = stat.executeQuery("call 1");
    rs.next();
    assertEquals(1, rs.getInt(1));
    conn.close();
    m = serverOld.getClass().getMethod("stop");
    m.invoke(serverOld);
}

82. XMemcachedMBeanServerUnitTest#testMBeanServer()

View license
public void testMBeanServer() throws Exception {
    Method method = XMemcachedMbeanServer.getInstance().getClass().getDeclaredMethod("initialize", new Class[] {});
    method.setAccessible(true);
    method.invoke(XMemcachedMbeanServer.getInstance());
    assertTrue(XMemcachedMbeanServer.getInstance().isActive());
    int oldCount = XMemcachedMbeanServer.getInstance().getMBeanCount();
    String name = mock.getClass().getPackage().getName() + ":type=" + mock.getClass().getSimpleName();
    XMemcachedMbeanServer.getInstance().registMBean(mock, name);
    assertEquals(oldCount + 1, XMemcachedMbeanServer.getInstance().getMBeanCount());
    assertTrue(XMemcachedMbeanServer.getInstance().isRegistered(name));
    XMemcachedMbeanServer.getInstance().shutdown();
    assertFalse(XMemcachedMbeanServer.getInstance().isActive());
}

83. ClientThreadPoolsTest#testThreadPoolInjection()

View license
@Test
public void testThreadPoolInjection() throws Exception {
    ServerLocator serverLocator = new ServerLocatorImpl(false);
    ThreadPoolExecutor threadPool = new ThreadPoolExecutor(1, 1, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
    ScheduledThreadPoolExecutor scheduledThreadPool = new ScheduledThreadPoolExecutor(1);
    serverLocator.setThreadPools(threadPool, scheduledThreadPool);
    Field threadPoolField = ServerLocatorImpl.class.getDeclaredField("threadPool");
    Field scheduledThreadPoolField = ServerLocatorImpl.class.getDeclaredField("scheduledThreadPool");
    Method initialise = ServerLocatorImpl.class.getDeclaredMethod("initialise");
    initialise.setAccessible(true);
    initialise.invoke(serverLocator);
    threadPoolField.setAccessible(true);
    scheduledThreadPoolField.setAccessible(true);
    ThreadPoolExecutor tpe = (ThreadPoolExecutor) threadPoolField.get(serverLocator);
    ScheduledThreadPoolExecutor stpe = (ScheduledThreadPoolExecutor) scheduledThreadPoolField.get(serverLocator);
    assertEquals(threadPool, tpe);
    assertEquals(scheduledThreadPool, stpe);
}

84. RemotingServiceImplTest#testSetInterceptorsAddsBothInterceptorsFromConfigAndServiceRegistry()

View license
/**
    * Tests ensures that setInterceptors methods adds both interceptors from the service registry and also interceptors
    * defined in the configuration.
    */
@Test
public void testSetInterceptorsAddsBothInterceptorsFromConfigAndServiceRegistry() throws Exception {
    Method method = RemotingServiceImpl.class.getDeclaredMethod("setInterceptors", Configuration.class);
    Field incomingInterceptors = RemotingServiceImpl.class.getDeclaredField("incomingInterceptors");
    Field outgoingInterceptors = RemotingServiceImpl.class.getDeclaredField("outgoingInterceptors");
    method.setAccessible(true);
    incomingInterceptors.setAccessible(true);
    outgoingInterceptors.setAccessible(true);
    serviceRegistry.addIncomingInterceptor(new FakeInterceptor());
    serviceRegistry.addOutgoingInterceptor(new FakeInterceptor());
    List<String> interceptorClassNames = new ArrayList<>();
    interceptorClassNames.add(FakeInterceptor.class.getCanonicalName());
    configuration.setIncomingInterceptorClassNames(interceptorClassNames);
    configuration.setOutgoingInterceptorClassNames(interceptorClassNames);
    method.invoke(remotingService, configuration);
    assertTrue(((List) incomingInterceptors.get(remotingService)).size() == 2);
    assertTrue(((List) outgoingInterceptors.get(remotingService)).size() == 2);
    assertTrue(((List) incomingInterceptors.get(remotingService)).contains(serviceRegistry.getIncomingInterceptors(null).get(0)));
    assertTrue(((List) outgoingInterceptors.get(remotingService)).contains(serviceRegistry.getOutgoingInterceptors(null).get(0)));
}

85. RunMojo#createForward()

Project: android-maven-plugin
Source File: RunMojo.java
View license
private static void createForward(IDevice device, int debugPort, int pid) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Method m = Class.forName("com.android.ddmlib.AdbHelper").getDeclaredMethod("createForward", InetSocketAddress.class, device.getClass(), String.class, String.class);
    m.setAccessible(true);
    m.invoke(null, AndroidDebugBridge.getSocketAddress(), device, String.format("tcp:%d", debugPort), String.format("jdwp:%d", pid));
}

86. AbstractProxyTest#testProtectedHierarchyMethod()

Project: apache-aries
Source File: AbstractProxyTest.java
View license
/**
   * Test a protected method declared higher up the superclass hierarchy
   */
@Test
public void testProtectedHierarchyMethod() throws Exception {
    Method m = null;
    try {
        m = getDeclaredMethod(getTestClass(), "bProMethod");
    } catch (NoSuchMethodException nsme) {
        m = getProxyClass(getTestClass()).getSuperclass().getDeclaredMethod("bProMethod");
    }
    //for these weaving tests we are loading the woven test classes on a different classloader
    //to this class so we need to set the method accessible
    m.setAccessible(true);
    m.invoke(getProxyInstance(getProxyClass(getTestClass())));
}

87. AbstractProxyTest#testDefaultHierarchyMethod()

Project: apache-aries
Source File: AbstractProxyTest.java
View license
/**
   * Test a default method declared higher up the superclass hierarchy
   */
@Test
public void testDefaultHierarchyMethod() throws Exception {
    Method m = null;
    try {
        m = getDeclaredMethod(getTestClass(), "bDefMethod");
    } catch (NoSuchMethodException nsme) {
        m = getProxyClass(getTestClass()).getSuperclass().getDeclaredMethod("bDefMethod", new Class[] {});
    }
    //for these weaving tests we are loading the woven test classes on a different classloader
    //to this class so we need to set the method accessible
    m.setAccessible(true);
    m.invoke(getProxyInstance(getProxyClass(getTestClass())));
}

88. AbstractProxyTest#testProtectedHierarchyMethod()

Project: aries
Source File: AbstractProxyTest.java
View license
/**
   * Test a protected method declared higher up the superclass hierarchy
   */
@Test
public void testProtectedHierarchyMethod() throws Exception {
    Method m = null;
    try {
        m = getDeclaredMethod(getTestClass(), "bProMethod");
    } catch (NoSuchMethodException nsme) {
        m = getProxyClass(getTestClass()).getSuperclass().getDeclaredMethod("bProMethod");
    }
    //for these weaving tests we are loading the woven test classes on a different classloader
    //to this class so we need to set the method accessible
    m.setAccessible(true);
    m.invoke(getProxyInstance(getProxyClass(getTestClass())));
}

89. AbstractProxyTest#testDefaultHierarchyMethod()

Project: aries
Source File: AbstractProxyTest.java
View license
/**
   * Test a default method declared higher up the superclass hierarchy
   */
@Test
public void testDefaultHierarchyMethod() throws Exception {
    Method m = null;
    try {
        m = getDeclaredMethod(getTestClass(), "bDefMethod");
    } catch (NoSuchMethodException nsme) {
        m = getProxyClass(getTestClass()).getSuperclass().getDeclaredMethod("bDefMethod", new Class[] {});
    }
    //for these weaving tests we are loading the woven test classes on a different classloader
    //to this class so we need to set the method accessible
    m.setAccessible(true);
    m.invoke(getProxyInstance(getProxyClass(getTestClass())));
}

90. PooledAllFieldsTest#pooled_class_transformation()

View license
@Test
@SuppressWarnings("static-method")
public void pooled_class_transformation() throws Exception {
    World world = new World();
    Entity e = world.createEntity();
    PooledAllFields pooled = e.edit().create(PooledAllFields.class);
    assertEquals(PooledComponent.class, pooled.getClass().getSuperclass());
    Method reset = pooled.getClass().getMethod("reset");
    reset.setAccessible(true);
    reset.invoke(pooled);
    for (Field f : pooled.getClass().getFields()) {
        if (boolean.class == f.getType())
            assertTrue(f.getBoolean(pooled));
        else if (f.getType().isPrimitive())
            assertEquals(0l, f.getLong(pooled));
        else
            assertEquals(null, f.get(pooled));
    }
}

91. OptimalCECPMainTest#testPermuteOptAlnUnpermuted()

Project: biojava
Source File: OptimalCECPMainTest.java
View license
/**
	 * Very basic test of [email protected] OptimalCECPMain#permuteOptAln(AFPChain, int)}
	 *
	 * It should do nothing on unpermuted alignments.
	 * @throws NoSuchMethodException
	 * @throws SecurityException
	 * @throws StructureException
	 * @throws IOException
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 * @throws IllegalArgumentException
	 */
public void testPermuteOptAlnUnpermuted() throws SecurityException, NoSuchMethodException, StructureException, IOException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    //test private member using reflection
    Method permuteOptAln = OptimalCECPMain.class.getDeclaredMethod("permuteOptAln", AFPChain.class, int.class);
    permuteOptAln.setAccessible(true);
    String name1, name2;
    name1 = "d1qdmA1";
    name2 = "d1nklA_";
    CeCPMain ce = (CeCPMain) StructureAlignmentFactory.getAlgorithm(CeCPMain.algorithmName);
    CECPParameters param = (CECPParameters) ce.getParameters();
    param.setDuplicationHint(DuplicationHint.RIGHT);
    Atom[] ca1 = cache.getAtoms(name1);
    Atom[] ca2 = cache.getAtoms(name2);
    AFPChain afpChain = ce.align(ca1, ca2);
    AFPChain afpChain2 = (AFPChain) afpChain.clone();
    permuteOptAln.invoke(null, afpChain2, 0);
    assertEquals("Permuting by 0 changed the alignment!", afpChain, afpChain2);
}

92. TestBoneCP#testMaybeSignalForMoreConnections()

Project: bonecp
Source File: TestBoneCP.java
View license
/**
	 * Test method for maybeSignalForMoreConnections(com.jolbox.bonecp.ConnectionPartition)}.
	 * @throws SecurityException 
	 * @throws NoSuchMethodException 
	 * @throws IllegalArgumentException 
	 * @throws IllegalAccessException 
	 * @throws InvocationTargetException 
	 */
@Test
public void testMaybeSignalForMoreConnections() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    expect(mockPartition.isUnableToCreateMoreTransactions()).andReturn(false).once();
    expect(mockPartition.getFreeConnections()).andReturn(mockConnectionHandles).anyTimes();
    //		expect(mockConnectionHandles.size()).andReturn(1).anyTimes();
    expect(mockPartition.getAvailableConnections()).andReturn(1).anyTimes();
    expect(mockPartition.getMaxConnections()).andReturn(10).anyTimes();
    BlockingQueue<Object> bq = new ArrayBlockingQueue<Object>(1);
    expect(mockPartition.getPoolWatchThreadSignalQueue()).andReturn(bq).anyTimes();
    //		mockPartition.lockAlmostFullLock();
    //		expectLastCall().once();
    //		mockPartition.almostFullSignal();
    //		expectLastCall().once();
    //		mockPartition.unlockAlmostFullLock();
    //		expectLastCall().once();
    replay(mockPartition, mockConnectionHandles);
    Method method = testClass.getClass().getDeclaredMethod("maybeSignalForMoreConnections", ConnectionPartition.class);
    method.setAccessible(true);
    method.invoke(testClass, new Object[] { mockPartition });
    verify(mockPartition, mockConnectionHandles);
}

93. TestConnectionHandle#testCheckClosed()

Project: bonecp
Source File: TestConnectionHandle.java
View license
/** Test for check closed routine.
	 * @throws SecurityException
	 * @throws NoSuchFieldException
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 */
@Test
public void testCheckClosed() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    this.testClass.renewConnection();
    // call the method (should not throw an exception)
    Method method = this.testClass.getClass().getDeclaredMethod("checkClosed");
    method.setAccessible(true);
    method.invoke(this.testClass);
    // logically mark the connection as closed
    this.testClass.logicallyClosed.set(true);
    try {
        method.invoke(this.testClass);
        fail("Should have thrown an exception");
    } catch (Throwable t) {
    }
}

94. CRuntime#getSingleAbstractMethodMethod()

Project: BridJ
Source File: CRuntime.java
View license
private Method getSingleAbstractMethodMethod(Class<?> type) {
    assert Modifier.isAbstract(type.getModifiers());
    Method method = null;
    Method[] declaredMethods = type.getDeclaredMethods();
    for (Method dm : declaredMethods) {
        int modifiers = dm.getModifiers();
        if (!Modifier.isAbstract(modifiers)) {
            continue;
        }
        if (method == null) {
            method = dm;
        } else {
            throw new RuntimeException("Callback " + type.getName() + " has more than one abstract method (" + dm + " and " + method + ")");
        }
    //break;
    }
    return method;
}

95. IntrospectionSupportTest#testIsSetterBuilderPatternSupport()

Project: camel
Source File: IntrospectionSupportTest.java
View license
public void testIsSetterBuilderPatternSupport() throws Exception {
    Method setter = MyBuilderBean.class.getMethod("setName", String.class);
    Method setter2 = MyOtherBuilderBean.class.getMethod("setName", String.class);
    Method setter3 = MyOtherOtherBuilderBean.class.getMethod("setName", String.class);
    assertFalse(IntrospectionSupport.isSetter(setter, false));
    assertTrue(IntrospectionSupport.isSetter(setter, true));
    assertFalse(IntrospectionSupport.isSetter(setter2, false));
    assertTrue(IntrospectionSupport.isSetter(setter2, true));
    assertFalse(IntrospectionSupport.isSetter(setter3, false));
    assertTrue(IntrospectionSupport.isSetter(setter3, true));
}

96. JPAEntityScanner#getIdMethod()

View license
private Method getIdMethod(Class<?> clazz) {
    Method idMethod = null;
    // Get all public declared methods on the class. According to spec, @Id should only be 
    // applied to fields and property get methods
    Method[] methods = clazz.getMethods();
    Id idAnnotation = null;
    for (Method method : methods) {
        idAnnotation = method.getAnnotation(Id.class);
        if (idAnnotation != null) {
            idMethod = method;
            break;
        }
    }
    return idMethod;
}

97. T6410653#main()

Project: ceylon
Source File: T6410653.java
View license
public static void main(String... args) throws Exception {
    File testSrc = new File(System.getProperty("test.src"));
    String source = new File(testSrc, "T6410653.java").getPath();
    ClassLoader cl = ToolProvider.getSystemToolClassLoader();
    Tool compiler = ToolProvider.getSystemJavaCompiler();
    Class<?> main = Class.forName("com.sun.tools.javac.main.Main", true, cl);
    Method useRawMessages = main.getMethod("useRawMessages", boolean.class);
    useRawMessages.invoke(null, true);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    compiler.run(null, null, out, "-d", source, source);
    useRawMessages.invoke(null, false);
    if (!out.toString().equals(String.format("%s%n%s%n", "javac: javac.err.file.not.directory", "javac.msg.usage"))) {
        throw new AssertionError(out);
    }
    System.out.println("Test PASSED.  Running javac again to see localized output:");
    compiler.run(null, null, System.out, "-d", source, source);
}

98. ValueTypeTests#findVTMethodOverloads()

Project: ceylon
Source File: ValueTypeTests.java
View license
// Tries to find overloads of the given method
private Method[] findVTMethodOverloads(Class<?> clazz, Method classMethod) {
    ArrayList<Method> overrides = new ArrayList<Method>();
    Method[] methods = clazz.getMethods();
    for (Method m : methods) {
        if (!m.equals(classMethod) && m.getName().equals(classMethod.getName()) && (m.getModifiers() & Modifier.STATIC) == 0) {
            overrides.add(m);
        }
    }
    Method[] result = new Method[overrides.size()];
    return overrides.toArray(result);
}

99. T6410653#main()

Project: ceylon-compiler
Source File: T6410653.java
View license
public static void main(String... args) throws Exception {
    File testSrc = new File(System.getProperty("test.src"));
    String source = new File(testSrc, "T6410653.java").getPath();
    ClassLoader cl = ToolProvider.getSystemToolClassLoader();
    Tool compiler = ToolProvider.getSystemJavaCompiler();
    Class<?> main = Class.forName("com.sun.tools.javac.main.Main", true, cl);
    Method useRawMessages = main.getMethod("useRawMessages", boolean.class);
    useRawMessages.invoke(null, true);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    compiler.run(null, null, out, "-d", source, source);
    useRawMessages.invoke(null, false);
    if (!out.toString().equals(String.format("%s%n%s%n", "javac: javac.err.file.not.directory", "javac.msg.usage"))) {
        throw new AssertionError(out);
    }
    System.out.println("Test PASSED.  Running javac again to see localized output:");
    compiler.run(null, null, System.out, "-d", source, source);
}

100. ValueTypeTests#findVTMethodOverloads()

Project: ceylon-compiler
Source File: ValueTypeTests.java
View license
// Tries to find overloads of the given method
private Method[] findVTMethodOverloads(Class<?> clazz, Method classMethod) {
    ArrayList<Method> overrides = new ArrayList<Method>();
    Method[] methods = clazz.getMethods();
    for (Method m : methods) {
        if (!m.equals(classMethod) && m.getName().equals(classMethod.getName()) && (m.getModifiers() & Modifier.STATIC) == 0) {
            overrides.add(m);
        }
    }
    Method[] result = new Method[overrides.size()];
    return overrides.toArray(result);
}