Search in sources :

Example 1 with InvokeProxetta

use of jodd.proxetta.impl.InvokeProxetta in project jodd by oblac.

the class InvReplTest method testReplacement.

@Test
public void testReplacement() throws IllegalAccessException, InstantiationException, NoSuchMethodException, IOException {
    InvokeProxetta proxetta = initProxetta();
    String className = One.class.getCanonicalName();
    byte[] klazz = proxetta.builder(One.class).create();
    //FileUtil.writeBytes("/Users/igor/OneClone.class", klazz);
    FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
    //		PrintStream out = System.out;
    System.setOut(new PrintStream(fbaos));
    One one = (One) ClassLoaderUtil.defineClass((new StringBuilder()).append(className).append(JoddProxetta.invokeProxyClassNameSuffix).toString(), klazz).newInstance();
    // clone ctor calls super ctor,
    assertEquals("one ctor!one ctor!", fbaos.toString());
    fbaos.reset();
    one.example1();
    assertEquals("REPLACED VIRTUAL! jodd.proxetta.inv.Two * one!173>overriden sub", fbaos.toString());
    fbaos.reset();
    one.example2();
    assertEquals("REPLACED STATIC! one * jodd/proxetta/inv/Two * example2 * void example2() * jodd.proxetta.inv.One * jodd.proxetta.inv.One$$Clonetou!15013static: 4", fbaos.toString());
    fbaos.reset();
    one.example3();
    assertEquals("state = REPLACED ctor!", fbaos.toString());
    fbaos.reset();
    assertEquals("jodd.proxetta.inv.One$$Clonetou", one.getClass().getName());
    assertTrue(one instanceof Serializable);
    Annotation[] anns = one.getClass().getAnnotations();
    assertEquals(3, anns.length);
    Method ms = one.getClass().getMethod("example1");
    anns = ms.getAnnotations();
    assertEquals(1, anns.length);
}
Also used : PrintStream(java.io.PrintStream) Serializable(java.io.Serializable) FastByteArrayOutputStream(jodd.io.FastByteArrayOutputStream) Method(java.lang.reflect.Method) InvokeProxetta(jodd.proxetta.impl.InvokeProxetta) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Example 2 with InvokeProxetta

use of jodd.proxetta.impl.InvokeProxetta in project jodd by oblac.

the class InvReplTest method testInterface.

@Test
public void testInterface() {
    InvokeProxetta proxetta = initProxetta();
    try {
        proxetta.builder(Inter.class).newInstance();
        fail();
    } catch (ProxettaException ignore) {
    }
}
Also used : InvokeProxetta(jodd.proxetta.impl.InvokeProxetta) Test(org.junit.Test)

Example 3 with InvokeProxetta

use of jodd.proxetta.impl.InvokeProxetta in project jodd by oblac.

the class InvReplTest method testSuper.

@Test
public void testSuper() {
    InvokeProxetta proxetta = initProxetta();
    try {
        proxetta.builder(OneWithSuper.class).define();
        fail();
    } catch (ProxettaException ignore) {
    }
}
Also used : InvokeProxetta(jodd.proxetta.impl.InvokeProxetta) Test(org.junit.Test)

Aggregations

InvokeProxetta (jodd.proxetta.impl.InvokeProxetta)3 Test (org.junit.Test)3 PrintStream (java.io.PrintStream)1 Serializable (java.io.Serializable)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 FastByteArrayOutputStream (jodd.io.FastByteArrayOutputStream)1