Search in sources :

Example 1 with MockThrowable

use of org.evosuite.runtime.mock.java.lang.MockThrowable in project evosuite by EvoSuite.

the class InstrumentingAgent_exceptionsIntTest method testReplacementCallInSubClassOfException.

@Test
public void testReplacementCallInSubClassOfException() {
    Object obj = null;
    try {
        InstrumentingAgent.activate();
        obj = new ExceptionHolder();
    } finally {
        InstrumentingAgent.deactivate();
    }
    try {
        MockFramework.enable();
        StackTraceElement[] traces = new MockThrowable().getStackTrace();
        ExceptionHolder eh = (ExceptionHolder) obj;
        StackTraceElement[] b = eh.getTraces();
        Assert.assertEquals(traces[1], b[1]);
    } finally {
        MockFramework.disable();
    }
}
Also used : ExceptionHolder(com.examples.with.different.packagename.agent.ExceptionHolder) MockThrowable(org.evosuite.runtime.mock.java.lang.MockThrowable) Test(org.junit.Test)

Example 2 with MockThrowable

use of org.evosuite.runtime.mock.java.lang.MockThrowable in project evosuite by EvoSuite.

the class MockIOException method getDelegate.

/*
	 * This is needed for when super constructors call overridden methods,
	 * and proper delegate method (right inputs) is not instantiated yet  
	 */
private MockThrowable getDelegate() {
    if (delegate == null) {
        // placeholder
        delegate = new MockThrowable();
        delegate.setOriginForDelegate(super.getStackTrace()[0]);
    }
    return delegate;
}
Also used : MockThrowable(org.evosuite.runtime.mock.java.lang.MockThrowable)

Example 3 with MockThrowable

use of org.evosuite.runtime.mock.java.lang.MockThrowable in project evosuite by EvoSuite.

the class InstrumentingAgent_exceptionsIntTest method testExceptions.

@Test
public void testExceptions() {
    Object obj = null;
    try {
        InstrumentingAgent.activate();
        obj = new ExceptionHolder();
    } finally {
        InstrumentingAgent.deactivate();
    }
    try {
        MockFramework.enable();
        ExceptionHolder eh = (ExceptionHolder) obj;
        Assert.assertFalse(eh.getNonMockedNPE() instanceof EvoSuiteMock);
        Assert.assertTrue(eh.getMockedThrowable() instanceof EvoSuiteMock);
        StackTraceElement[] traces = new MockThrowable().getStackTrace();
        StackTraceElement[] a = eh.getTracesWhenCast();
        Assert.assertEquals(traces[1], a[1]);
    } finally {
        MockFramework.disable();
    }
}
Also used : ExceptionHolder(com.examples.with.different.packagename.agent.ExceptionHolder) EvoSuiteMock(org.evosuite.runtime.mock.EvoSuiteMock) MockThrowable(org.evosuite.runtime.mock.java.lang.MockThrowable) Test(org.junit.Test)

Aggregations

MockThrowable (org.evosuite.runtime.mock.java.lang.MockThrowable)3 ExceptionHolder (com.examples.with.different.packagename.agent.ExceptionHolder)2 Test (org.junit.Test)2 EvoSuiteMock (org.evosuite.runtime.mock.EvoSuiteMock)1