/** * Test the void void static method by accidently giving parameters. */ @Test public void testStaticVoidVoidInvalidParams() { try { ReflectionUtil.invokeStaticMethod( DummyObject.class, "staticVoidNoParams", new Object[]{new Object()}, new Class[]{Object.class}); Assert.fail("Should have thrown a SystemException"); } catch (SystemException e) { Assert.assertEquals("Incorrect exception cause", NoSuchMethodException.class, e.getCause().getClass()); } }
/** * Test when an invalid name is provided. */ @Test public void testStaticInvalidMethodName() { try { ReflectionUtil.invokeStaticMethod(DummyObject.class, "doesntExist", null, null); Assert.fail("Should have thrown a SystemException"); } catch (SystemException e) { Assert.assertEquals("Incorrect exception cause", NoSuchMethodException.class, e.getCause().getClass()); } }
/** * Test when the static method invoked is private. */ @Test public void testStaticInvokePrivate() { try { ReflectionUtil.invokeStaticMethod(DummyObject.class, "staticPrivateMethod", null, null); Assert.fail("Should have thrown a SystemException"); } catch (SystemException e) { Assert.assertEquals("Incorrect exception cause", NoSuchMethodException.class, e.getCause().getClass()); } }
/** * Test when the static method invoked throws an exception. */ @Test public void testStaticInvokeExceptionThrower() { try { ReflectionUtil.invokeStaticMethod(DummyObject.class, "staticExceptionThrower", null, null); Assert.fail("Should have thrown a SystemException"); } catch (SystemException e) { Assert.assertEquals("Incorrect exception cause", InvocationTargetException.class, e.getCause().getClass()); } }
/** * Test the void void method by accidently giving parameters. */ @Test public void testVoidVoidInvalidParams() { DummyObject dummyObj = new DummyObject(); try { ReflectionUtil.invokeMethod(dummyObj, "voidNoParams", new Object[]{new Object()}, new Class[]{Object.class}); Assert.fail("Should have thrown a SystemException"); } catch (SystemException e) { Assert.assertEquals("Incorrect exception cause", NoSuchMethodException.class, e.getCause().getClass()); } }
/** * Test when an invalid name is provided. */ @Test public void testInvalidMethodName() { DummyObject dummyObj = new DummyObject(); try { ReflectionUtil.invokeMethod(dummyObj, "doesntExist", null, null); Assert.fail("Should have thrown a SystemException"); } catch (SystemException e) { Assert.assertEquals("Incorrect exception cause", NoSuchMethodException.class, e.getCause().getClass()); } }
/** * Test when the method invoked is private. */ @Test public void testInvokePrivate() { DummyObject dummyObj = new DummyObject(); try { ReflectionUtil.invokeMethod(dummyObj, "privateMethod", null, null); Assert.fail("Should have thrown a SystemException"); } catch (SystemException e) { Assert.assertEquals("Incorrect exception cause", NoSuchMethodException.class, e.getCause().getClass()); } }
/** * Test when the method invoked throws an exception. */ @Test public void testInvokeExceptionThrower() { DummyObject dummyObj = new DummyObject(); try { ReflectionUtil.invokeMethod(dummyObj, "exceptionThrower", null, null); Assert.fail("Should have thrown a SystemException"); } catch (SystemException e) { Assert.assertEquals("Incorrect exception cause", InvocationTargetException.class, e.getCause().getClass()); } }