Search in sources :

Example 1 with ReflectException

use of org.joor.ReflectException in project adb-idea by pbreault.

the class BackwardCompatibleGetterTest method callPreviousImplementationWhenCurrentThrowsErrors.

@Test
public void callPreviousImplementationWhenCurrentThrowsErrors() throws Exception {
    expectPreviousImplementationIsCalledFor(new ClassNotFoundException());
    expectPreviousImplementationIsCalledFor(new NoSuchMethodException());
    expectPreviousImplementationIsCalledFor(new NoSuchFieldException());
    expectPreviousImplementationIsCalledFor(new LinkageError());
    expectPreviousImplementationIsCalledFor(new ReflectException());
}
Also used : ReflectException(org.joor.ReflectException) Test(org.junit.Test)

Example 2 with ReflectException

use of org.joor.ReflectException in project jOOR by jOOQ.

the class ReflectTest method testFinalFields.

@Test
public void testFinalFields() {
    try {
        // Instance methods
        // ----------------
        Test11 test11 = new Test11();
        assertEquals(1, (int) (Integer) on(test11).set("F_INT1", 1).get("F_INT1"));
        assertEquals(1, (int) (Integer) on(test11).field("F_INT1").get());
        assertEquals(1, (int) (Integer) on(test11).set("F_INT2", 1).get("F_INT1"));
        assertEquals(1, (int) (Integer) on(test11).field("F_INT2").get());
        assertNull(on(test11).set("F_INT2", null).get("F_INT2"));
        assertNull(on(test11).field("F_INT2").get());
        // Static methods
        // ----------------
        assertEquals(1, (int) (Integer) onClass(Test11.class).set("SF_INT1", 1).get("SF_INT1"));
        assertEquals(1, (int) (Integer) onClass(Test11.class).field("SF_INT1").get());
        assertEquals(1, (int) (Integer) onClass(Test11.class).set("SF_INT2", 1).get("SF_INT2"));
        assertEquals(1, (int) (Integer) onClass(Test11.class).field("SF_INT2").get());
        onClass(Test11.class).set("SF_INT2", 1).field("SF_INT2").get();
        assertNull(onClass(Test11.class).set("SF_INT2", null).get("SF_INT2"));
        assertNull(onClass(Test11.class).field("SF_INT2").get());
    } catch (ReflectException e) {
        // [#50] This may no longer work on JDK 9
        if (!JDK9)
            throw e;
    }
}
Also used : ReflectException(org.joor.ReflectException) Test11(org.joor.test.interfaces.Test11) Test(org.junit.Test)

Example 3 with ReflectException

use of org.joor.ReflectException in project jOOR by jOOQ.

the class B method testCompileWithExtraOptions.

@Test
public void testCompileWithExtraOptions() {
    assertEquals("org.joor.test.Source7OK", Reflect.compile("org.joor.test.Source7OK", "package org.joor.test; " + "public class Source7OK {" + "}", new CompileOptions().options("-source", "7")).type().getName());
    try {
        Reflect.compile("org.joor.test.Source7NOK", "package org.joor.test; " + "public interface Source7NOK {" + "    default void m() {}" + "}", new CompileOptions().options("-source", "7")).type();
        fail("Class should not compile with source level 7");
    } catch (ReflectException expected) {
    }
    assertEquals("org.joor.test.Source8OK", Reflect.compile("org.joor.test.Source8OK", "package org.joor.test; " + "public interface Source8OK {" + "    default void m() {}" + "}", new CompileOptions().options("-source", "8")).type().getName());
    try {
        Reflect.compile("org.joor.test.Source8NOK", "package org.joor.test; " + "public interface Source8NOK {" + "    private void m() {}" + "}", new CompileOptions().options("-source", "8")).create().get();
        fail("Class should not compile with source level 8");
    } catch (ReflectException expected) {
    }
    try {
        Reflect.compile("org.joor.test.Invalid", "package org.joor.test; " + "public class Invalid {" + "}", new CompileOptions().options("-invalidflag"));
        fail("Expected ReflectException for -invalidflag");
    } catch (ReflectException expected) {
        assertTrue(expected.getCause() instanceof IllegalArgumentException);
    }
}
Also used : CompileOptions(org.joor.CompileOptions) ReflectException(org.joor.ReflectException) Test(org.junit.Test)

Aggregations

ReflectException (org.joor.ReflectException)3 Test (org.junit.Test)3 CompileOptions (org.joor.CompileOptions)1 Test11 (org.joor.test.interfaces.Test11)1