Here are the examples of the java api class java.lang.reflect.Method taken from open source projects.
1. BignumTest#testCompare()
Project: openjdk
File: BignumTest.java
File: BignumTest.java
@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
File: BignumTest.java
File: BignumTest.java
@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
File: BignumTest.java
File: BignumTest.java
@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#testMultiplyUInt64()
Project: openjdk
File: BignumTest.java
File: BignumTest.java
@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"); }
5. BignumTest#testMultiplyUInt32()
Project: openjdk
File: BignumTest.java
File: BignumTest.java
@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"); }
6. BignumTest#testDivideModuloIntBignum()
Project: openjdk
File: BignumTest.java
File: BignumTest.java
@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
File: BignumTest.java
File: BignumTest.java
@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
File: BignumTest.java
File: BignumTest.java
@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()
Project: byte-buddy
File: MultipleParentClassLoaderTest.java
File: MultipleParentClassLoaderTest.java
@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
File: CompileAndRunTest.java
File: CompileAndRunTest.java
@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. RedefineClassTest#loadAgent()
Project: openjdk
File: RedefineClassTest.java
File: RedefineClassTest.java
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); }
12. Regression636Test#testGetImplementationReflection()
Project: Resteasy
File: Regression636Test.java
File: Regression636Test.java
@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); }
13. ClientAuthenticationManagerTest#testClientProvidersPropagation()
Project: mina-sshd
File: ClientAuthenticationManagerTest.java
File: ClientAuthenticationManagerTest.java
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)); }
14. IntrospectionSupportTest#testOtherIsSetter()
Project: camel
File: IntrospectionSupportTest.java
File: IntrospectionSupportTest.java
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)); }
15. IntrospectionSupportTest#testOtherIsGetter()
Project: camel
File: IntrospectionSupportTest.java
File: IntrospectionSupportTest.java
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)); }
16. CompileAndRunTest#test_BigInteger_operators()
Project: golo-lang
File: CompileAndRunTest.java
File: CompileAndRunTest.java
@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); } }
17. CompileAndRunTest#test_BigDecimal_operators()
Project: golo-lang
File: CompileAndRunTest.java
File: CompileAndRunTest.java
@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); } }
18. DirectMemoryUtils#destroyDirectByteBuffer()
Project: hindex
File: DirectMemoryUtils.java
File: DirectMemoryUtils.java
/** * 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); }
19. DirectByteBufferUtils#destroyDirectByteBuffer()
Project: directmemory
File: DirectByteBufferUtils.java
File: DirectByteBufferUtils.java
/** * Clear and release the internal content of a direct {@link 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); }
20. DexMakerTest#testNewArray()
Project: dexmaker
File: DexMakerTest.java
File: DexMakerTest.java
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))); }
21. DexMakerTest#testArrayLength()
Project: dexmaker
File: DexMakerTest.java
File: DexMakerTest.java
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] })); }
22. DexMakerTest#testDoubleBinaryOps()
Project: dexmaker
File: DexMakerTest.java
File: DexMakerTest.java
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)); }
23. DexMakerTest#testFloatBinaryOps()
Project: dexmaker
File: DexMakerTest.java
File: DexMakerTest.java
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)); }
24. CompileAndRunTest#module_state()
Project: golo-lang
File: CompileAndRunTest.java
File: CompileAndRunTest.java
@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!")); }
25. Jersey2Plugin#getContainerClasses()
Project: HotswapAgent
File: Jersey2Plugin.java
File: Jersey2Plugin.java
/** * 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; }
26. IndexedPropertyDescriptorTest#testHashCode()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
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()); }
27. IndexedPropertyDescriptorTest#testSetIndexedWriteMethod_return()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
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()); }
28. IndexedPropertyDescriptorTest#testSetIndexedWriteMethod_badargtype()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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) { } }
29. IndexedPropertyDescriptorTest#testSetIndexedWriteMethod()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
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()); }
30. IndexedPropertyDescriptorTest#testSetIndexedWriteMethod_null()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
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()); }
31. IndexedPropertyDescriptorTest#testSetIndexedReadMethod_RInvalidArgType()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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) { } }
32. IndexedPropertyDescriptorTest#testSetIndexedReadMethod_RInvalidArgs()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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) { } }
33. IndexedPropertyDescriptorTest#testSetIndexedReadMethod_null()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
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()); }
34. IndexedPropertyDescriptorTest#testSetIndexedReadMethod()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
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()); }
35. IndexedPropertyDescriptorTest#testIndexedPropertyDescriptorStringMethodMethodMethodMethod_RWIncompatible()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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()); }
36. IndexedPropertyDescriptorTest#testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propInvalid()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
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()); }
37. IndexedPropertyDescriptorTest#testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propEmpty()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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) { } }
38. IndexedPropertyDescriptorTest#testIndexedPropertyDescriptorStringMethodMethodMethodMethod_propNull()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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) { } }
39. IndexedPropertyDescriptorTest#testEquals_PropertyType()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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)); }
40. IndexedPropertyDescriptorTest#testEquals_IndexWNull()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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)); }
41. IndexedPropertyDescriptorTest#testEquals_IndexedW()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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)); }
42. IndexedPropertyDescriptorTest#testEquals_IndexedRNull()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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)); }
43. IndexedPropertyDescriptorTest#testEquals_IndexedR()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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)); }
44. IndexedPropertyDescriptorTest#testEquals_WriteMethodNull()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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_WriteMethod()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
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)); }
46. IndexedPropertyDescriptorTest#testEquals_ReadMethodNull()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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)); }
47. IndexedPropertyDescriptorTest#testEquals_ReadMethod()
Project: j2objc
File: IndexedPropertyDescriptorTest.java
File: IndexedPropertyDescriptorTest.java
/* * 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)); }
48. EventSetDescriptorTest#testEventSetDescriptorStringClassMethodArrayMethodMethodMethod_getListenerMethodInvalid()
Project: j2objc
File: EventSetDescriptorTest.java
File: EventSetDescriptorTest.java
/* * 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()); }
49. EventSetDescriptorTest#testEventSetDescriptorStringClassMethodArrayMethodMethodMethod()
Project: j2objc
File: EventSetDescriptorTest.java
File: EventSetDescriptorTest.java
/* * 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()); }
50. TestBoneCP#testWatchConnection()
Project: bonecp
File: TestBoneCP.java
File: TestBoneCP.java
/** 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 }); }
51. DetailASTTest#testInsertSiblingBetween()
Project: checkstyle
File: DetailASTTest.java
File: DetailASTTest.java
@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()); }
52. MethodValInferenceTest#testGetMethodMultiClassAndMethodNames()
Project: checker-framework
File: MethodValInferenceTest.java
File: MethodValInferenceTest.java
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); }
53. PushToRemotePresenterTest#testShowErrorNotificationWhenUpstreanBranchFailedToLoad()
Project: che
File: PushToRemotePresenterTest.java
File: PushToRemotePresenterTest.java
@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); }
54. AsyncLoadMethodMatchTest#testMatch_includeOveride()
Project: asyncload
File: AsyncLoadMethodMatchTest.java
File: AsyncLoadMethodMatchTest.java
@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)); }
55. AsyncLoadMethodMatchTest#testMatch_exclude()
Project: asyncload
File: AsyncLoadMethodMatchTest.java
File: AsyncLoadMethodMatchTest.java
@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)); }
56. AsyncLoadMethodMatchTest#testMatch_include()
Project: asyncload
File: AsyncLoadMethodMatchTest.java
File: AsyncLoadMethodMatchTest.java
@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)); }
57. BridgeMethodResolverTests#testWithGenericParameter()
Project: spring-android
File: BridgeMethodResolverTests.java
File: BridgeMethodResolverTests.java
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)); } }
58. NoStackParamValidationRule#validate()
Project: vraptor4
File: NoStackParamValidationRule.java
File: NoStackParamValidationRule.java
@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); }
59. InjectionUtilTest#verifyMethodNames()
Project: transfuse
File: InjectionUtilTest.java
File: InjectionUtilTest.java
@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); }
60. DexMakerTest#testNegate()
Project: dexmaker
File: DexMakerTest.java
File: DexMakerTest.java
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)); }
61. DexMakerTest#testCastIntegerToFloatingPoint()
Project: dexmaker
File: DexMakerTest.java
File: DexMakerTest.java
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)); }
62. UserStoreClientTest#testWrappedMethods()
Project: evernote-sdk-java
File: UserStoreClientTest.java
File: UserStoreClientTest.java
@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()); } }
63. NoteStoreClientTest#testWrappedMethods()
Project: evernote-sdk-java
File: NoteStoreClientTest.java
File: NoteStoreClientTest.java
@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()); } }
64. MetricsDynamicBinding#configure()
Project: graylog2-server
File: MetricsDynamicBinding.java
File: MetricsDynamicBinding.java
@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)); } }
65. CompileAndRunTest#test_loopings()
Project: golo-lang
File: CompileAndRunTest.java
File: CompileAndRunTest.java
@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")); }
66. ClassLoaderTest#testProviderMultipleLoadersTwo()
Project: santuario-java
File: ClassLoaderTest.java
File: ClassLoaderTest.java
@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); }
67. ClassLoaderTest#testMultipleLoaders()
Project: santuario-java
File: ClassLoaderTest.java
File: ClassLoaderTest.java
@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); }
68. MethodTypeTest#get()
Project: querydsl
File: MethodTypeTest.java
File: MethodTypeTest.java
@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)); }
69. SqlMapExecutorTestBase#testAndVerifyQueryForList()
Project: pinpoint
File: SqlMapExecutorTestBase.java
File: SqlMapExecutorTestBase.java
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))); }
70. SqlMapClientTemplateIT#queryForListShouldBeTraced()
Project: pinpoint
File: SqlMapClientTemplateIT.java
File: SqlMapClientTemplateIT.java
@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))); }
71. bug7143614#validate()
Project: openjdk
File: bug7143614.java
File: bug7143614.java
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"); } }
72. OServerPluginManager#startPluginClass()
Project: orientdb
File: OServerPluginManager.java
File: OServerPluginManager.java
@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; }
73. ClassUtilTest#getBeanMethods()
Project: cloudhopper-commons
File: ClassUtilTest.java
File: ClassUtilTest.java
@Test public void getBeanMethods() throws Exception { Method expectedGetMethod = Person.class.getMethod("getFirstName"); Method expectedSetMethod = Person.class.getMethod("setFirstName", String.class); // case insensitive Method[] methods = ClassUtil.getBeanMethods(InternetPerson.class, "firstname", String.class, false); Assert.assertEquals(expectedGetMethod, methods[0]); Assert.assertEquals(expectedSetMethod, methods[1]); // case sensitive methods = ClassUtil.getBeanMethods(InternetPerson.class, "FirstName", String.class, true); Assert.assertEquals(expectedGetMethod, methods[0]); Assert.assertEquals(expectedSetMethod, methods[1]); }
74. SuppressionsLoaderTest#testUnableToReadSuppressions()
Project: checkstyle
File: SuppressionsLoaderTest.java
File: SuppressionsLoaderTest.java
@Test public void testUnableToReadSuppressions() throws Exception { final Class<SuppressionsLoader> loaderClass = SuppressionsLoader.class; final Method loadSuppressions = loaderClass.getDeclaredMethod("loadSuppressions", InputSource.class, String.class); loadSuppressions.setAccessible(true); final InputSource inputSource = new InputSource(); thrown.expect(CheckstyleException.class); final String sourceName = "suppressions_none.xml"; thrown.expectMessage("Unable to read " + sourceName); loadSuppressions.invoke(loaderClass, inputSource, sourceName); }
75. SuppressionsLoaderTest#testUnableToFindSuppressions()
Project: checkstyle
File: SuppressionsLoaderTest.java
File: SuppressionsLoaderTest.java
@Test public void testUnableToFindSuppressions() throws Exception { final Class<SuppressionsLoader> loaderClass = SuppressionsLoader.class; final Method loadSuppressions = loaderClass.getDeclaredMethod("loadSuppressions", InputSource.class, String.class); loadSuppressions.setAccessible(true); final String sourceName = "suppressions_none.xml"; final InputSource inputSource = new InputSource(sourceName); thrown.expect(CheckstyleException.class); thrown.expectMessage("Unable to find: " + sourceName); loadSuppressions.invoke(loaderClass, inputSource, sourceName); }
76. TranslationCheckTest#testLogIoException()
Project: checkstyle
File: TranslationCheckTest.java
File: TranslationCheckTest.java
@Test public void testLogIoException() throws Exception { //I can't put wrong file here. Checkstyle fails before check started. //I saw some usage of file or handling of wrong file in Checker, or somewhere //in checks running part. So I had to do it with reflection to improve coverage. final TranslationCheck check = new TranslationCheck(); final DefaultConfiguration checkConfig = createCheckConfig(TranslationCheck.class); check.configure(checkConfig); check.setMessageDispatcher(createChecker(checkConfig)); final Method logIoException = check.getClass().getDeclaredMethod("logIoException", IOException.class, File.class); logIoException.setAccessible(true); logIoException.invoke(check, new IOException("test exception"), new File("")); }
77. TranslationCheckTest#testLogIoExceptionFileNotFound()
Project: checkstyle
File: TranslationCheckTest.java
File: TranslationCheckTest.java
@Test public void testLogIoExceptionFileNotFound() throws Exception { //I can't put wrong file here. Checkstyle fails before check started. //I saw some usage of file or handling of wrong file in Checker, or somewhere //in checks running part. So I had to do it with reflection to improve coverage. final TranslationCheck check = new TranslationCheck(); final DefaultConfiguration checkConfig = createCheckConfig(TranslationCheck.class); check.configure(checkConfig); final Checker checker = createChecker(checkConfig); check.setMessageDispatcher(checker); final Method loadKeys = check.getClass().getDeclaredMethod("getTranslationKeys", File.class); loadKeys.setAccessible(true); loadKeys.invoke(check, new File("")); }
78. JavadocTagInfoTest#testSerial()
Project: checkstyle
File: JavadocTagInfoTest.java
File: JavadocTagInfoTest.java
@Test public void testSerial() throws ReflectiveOperationException { final DetailAST ast = new DetailAST(); final DetailAST astParent = new DetailAST(); astParent.setType(TokenTypes.LITERAL_CATCH); final Method setParent = ast.getClass().getDeclaredMethod("setParent", DetailAST.class); setParent.setAccessible(true); setParent.invoke(ast, astParent); final int[] validTypes = { TokenTypes.VARIABLE_DEF }; for (int type : validTypes) { ast.setType(type); assertTrue(JavadocTagInfo.SERIAL.isValidOn(ast)); } astParent.setType(TokenTypes.SLIST); ast.setType(TokenTypes.VARIABLE_DEF); assertFalse(JavadocTagInfo.SERIAL.isValidOn(ast)); ast.setType(TokenTypes.PARAMETER_DEF); assertFalse(JavadocTagInfo.SERIAL.isValidOn(ast)); }
79. MachineInfoPresenterTest#ownerEmailShouldBeSetWhenThereAreNotFirstOrLastName()
Project: che
File: MachineInfoPresenterTest.java
File: MachineInfoPresenterTest.java
@Test public void ownerEmailShouldBeSetWhenThereAreNotFirstOrLastName() throws Exception { Map<String, String> attributes = new HashMap<>(); attributes.put(MachineInfoPresenter.FIRST_NAME_KEY, "undefined"); attributes.put(MachineInfoPresenter.LAST_NAME_KEY, "<none>"); attributes.put(MachineInfoPresenter.EMAIL_KEY, "email"); when(profileDescriptor.getAttributes()).thenReturn(attributes); when(wsService.getWorkspace(SOME_TEXT)).thenReturn(promise); presenter.update(machine); verify(userProfile).getCurrentProfile(profileCaptor.capture()); AsyncRequestCallback<ProfileDescriptor> callback = profileCaptor.getValue(); //noinspection NonJREEmulationClassesInClientCode Method method = callback.getClass().getDeclaredMethod("onSuccess", Object.class); method.setAccessible(true); method.invoke(callback, profileDescriptor); verify(view).setOwner("email"); }
80. MachineInfoPresenterTest#ownerNameShouldBeSetWhenThereAreFirstAndLastNames()
Project: che
File: MachineInfoPresenterTest.java
File: MachineInfoPresenterTest.java
@Test public void ownerNameShouldBeSetWhenThereAreFirstAndLastNames() throws Exception { Map<String, String> attributes = new HashMap<>(); attributes.put(MachineInfoPresenter.FIRST_NAME_KEY, "firstName"); attributes.put(MachineInfoPresenter.LAST_NAME_KEY, "lastName"); when(profileDescriptor.getAttributes()).thenReturn(attributes); when(wsService.getWorkspace(SOME_TEXT)).thenReturn(promise); presenter.update(machine); verify(userProfile).getCurrentProfile(profileCaptor.capture()); AsyncRequestCallback<ProfileDescriptor> callback = profileCaptor.getValue(); //noinspection NonJREEmulationClassesInClientCode Method method = callback.getClass().getDeclaredMethod("onSuccess", Object.class); method.setAccessible(true); method.invoke(callback, profileDescriptor); verify(view).setOwner("firstName lastName"); }
81. ValueTypeTests#findVTMethodOverloads()
Project: ceylon-compiler
File: ValueTypeTests.java
File: ValueTypeTests.java
// 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); }
82. T6410653#main()
Project: ceylon-compiler
File: T6410653.java
File: T6410653.java
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); }
83. ValueTypeTests#findVTMethodOverloads()
Project: ceylon
File: ValueTypeTests.java
File: ValueTypeTests.java
// 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); }
84. T6410653#main()
Project: ceylon
File: T6410653.java
File: T6410653.java
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); }
85. PooledAllFieldsTest#pooled_class_transformation()
Project: artemis-odb
File: PooledAllFieldsTest.java
File: PooledAllFieldsTest.java
@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)); } }
86. AbstractProxyTest#testDefaultHierarchyMethod()
Project: aries
File: AbstractProxyTest.java
File: AbstractProxyTest.java
/** * 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()))); }
87. AbstractProxyTest#testProtectedHierarchyMethod()
Project: aries
File: AbstractProxyTest.java
File: AbstractProxyTest.java
/** * 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()))); }
88. RunMojo#createForward()
Project: android-maven-plugin
File: RunMojo.java
File: RunMojo.java
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)); }
89. RemotingServiceImplTest#testSetInterceptorsAddsBothInterceptorsFromConfigAndServiceRegistry()
Project: activemq-artemis
File: RemotingServiceImplTest.java
File: RemotingServiceImplTest.java
/** * 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))); }
90. ClientThreadPoolsTest#testThreadPoolInjection()
Project: activemq-artemis
File: ClientThreadPoolsTest.java
File: ClientThreadPoolsTest.java
@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); }
91. AbstractProxyTest#testDefaultHierarchyMethod()
Project: apache-aries
File: AbstractProxyTest.java
File: AbstractProxyTest.java
/** * 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()))); }
92. AbstractProxyTest#testProtectedHierarchyMethod()
Project: apache-aries
File: AbstractProxyTest.java
File: AbstractProxyTest.java
/** * 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()))); }
93. JPAEntityScanner#getIdMethod()
Project: camunda-bpm-platform
File: JPAEntityScanner.java
File: JPAEntityScanner.java
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; }
94. IntrospectionSupportTest#testIsSetterBuilderPatternSupport()
Project: camel
File: IntrospectionSupportTest.java
File: IntrospectionSupportTest.java
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)); }
95. CRuntime#getSingleAbstractMethodMethod()
Project: BridJ
File: CRuntime.java
File: CRuntime.java
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; }
96. TestConnectionHandle#testCheckClosed()
Project: bonecp
File: TestConnectionHandle.java
File: TestConnectionHandle.java
/** 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) { } }
97. TestBoneCP#testMaybeSignalForMoreConnections()
Project: bonecp
File: TestBoneCP.java
File: TestBoneCP.java
/** * 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); }
98. OptimalCECPMainTest#testPermuteOptAlnUnpermuted()
Project: biojava
File: OptimalCECPMainTest.java
File: OptimalCECPMainTest.java
/** * Very basic test of {@link 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); }
99. CallCheckerTest#doCallChecker()
Project: thread-weaver
File: CallCheckerTest.java
File: CallCheckerTest.java
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); } }
100. XMemcachedMBeanServerUnitTest#testMBeanServer()
Project: xmemcached
File: XMemcachedMBeanServerUnitTest.java
File: XMemcachedMBeanServerUnitTest.java
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()); }