executeAction(new VoidAction() { @Override public void executeInternal() { //code here } });
@Test public void worksAroundBugInCglibWhenAskedToImposteriseObject() { imposteriser.imposterise(new VoidAction(), Object.class); imposteriser.imposterise(new VoidAction(), Object.class, EmptyInterface.class); imposteriser.imposterise(new VoidAction(), Object.class, AnInterface2.class); }
public void testCanImposteriseAClassInASignedJarFile() throws Exception { File signedJarFile = new File("../testjar/target/signed.jar"); assertTrue("Signed JAR file does not exist (use Ant to build it)", signedJarFile.exists()); URL jarURL = signedJarFile.toURI().toURL(); // ignore closable loader as we might be in java 6 @SuppressWarnings("resource") URLClassLoader loader = new URLClassLoader(new URL[] { jarURL }); Class<?> typeInSignedJar = loader .loadClass("org.jmock.testjar.TypeInSignedJar"); Object o = imposteriser.imposterise(new VoidAction(), typeInSignedJar); assertTrue(typeInSignedJar.isInstance(o)); } }
public void testReturnsNullWhenInvoked() throws Throwable { assertNull("Should return null", new VoidAction().invoke(invocation)); }
@Test public void happyCaseWhenClassInASignedJarFile() throws Exception { File jarFile = new File("src/test/resources/signed.jar"); assertTrue(jarFile.exists()); URL jarURL = jarFile.toURI().toURL(); ClassLoader loader = new URLClassLoader(new URL[]{jarURL}); Class<?> typeInSignedJar = loader.loadClass("TypeInSignedJar"); assertTrue(imposteriser.canImposterise(typeInSignedJar)); Object o = imposteriser.imposterise(new VoidAction(), typeInSignedJar); assertTrue(typeInSignedJar.isInstance(o)); }
@Override public void setUp() { MethodFactory methodFactory = new MethodFactory(); invocation = new Invocation("INVOKED-OBJECT", methodFactory.newMethodReturning(void.class), new Object[0]); voidAction = new VoidAction(); }
@Test public void cannotImposteriseAClassWithAFinalToStringMethod() { assertFalse(imposteriser.canImposterise(ClassWithFinalToStringMethod.class)); try { imposteriser.imposterise(new VoidAction(), ClassWithFinalToStringMethod.class); fail("should have thrown IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }