@Test public void testTransformationInAbstractClass(){ long expected = 42; org.evosuite.runtime.System.setCurrentTimeMillis(expected); try{ /* * Note: this does not work, but we found a work around * by forcing loading before JUnit test execution * with a customized Runner */ InstrumentingAgent.activate(); //com.examples.with.different.packagename.agent.AbstractTime time = new com.examples.with.different.packagename.agent.ConcreteTime(); //Assert.assertEquals(expected, time.getTime()); } finally { InstrumentingAgent.deactivate(); } }
@Test public void testTime(){ long now = System.currentTimeMillis(); Assert.assertTrue("",TimeB.getTime() >= now); long expected = 42; org.evosuite.runtime.System.setCurrentTimeMillis(expected); try{ InstrumentingAgent.activate(); Assert.assertEquals(expected, TimeA.getTime()); } finally { InstrumentingAgent.deactivate(); } }
@Test public void testTransformation(){ long expected = 42; org.evosuite.runtime.System.setCurrentTimeMillis(expected); try{ InstrumentingAgent.activate(); TimeC time = new TimeC(); Assert.assertEquals(expected, time.getTime()); } finally { InstrumentingAgent.deactivate(); } }
@Test public void testTransformationInExtendingClass(){ long expected = 42; org.evosuite.runtime.System.setCurrentTimeMillis(expected); try{ InstrumentingAgent.activate(); ExtendingTimeC time = new ExtendingTimeC(); Assert.assertEquals(expected, time.getTime()); } finally { InstrumentingAgent.deactivate(); } }
@Test public void testTransformationInClassExtendingAbstract() throws Exception{ long expected = 42; org.evosuite.runtime.System.setCurrentTimeMillis(expected); try{ InstrumentingAgent.activate(); //even if re-instrument, they should be fine InstrumentingAgent.getInstrumentation().retransformClasses(AbstractTime.class,ConcreteTime.class); ConcreteTime time = new ConcreteTime(); /* * Using abstract class here would fail without retransformClasses, as it would be loaded * by JUnit before any method (static, BeforeClass) of this test * suite is executed, and so it would not get instrumented */ //AbstractTime time = new ConcreteTime(); Assert.assertEquals(expected, time.getTime()); } finally { InstrumentingAgent.deactivate(); } }
@Test public void testFailingTransformation() throws UnmodifiableClassException{ long expected = 42; org.evosuite.runtime.System.setCurrentTimeMillis(expected);