@Override public long millis() { return org.evosuite.runtime.System.currentTimeMillis(); } @Override
protected long getCurrentTimeMillis(){ if(RuntimeSettings.mockJVMNonDeterminism){ return org.evosuite.runtime.System.getCurrentTimeMillisForVFS(); } else { return java.lang.System.currentTimeMillis(); } }
public static void registerObjectForIdentityHashCode(Object o) { identityHashCode(o); }
@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(); } }
protected boolean checkPropertyPermission(PropertyPermission perm) { /* * TODO: this will need to be removed once REPLACE_CALLS * will be on by default */ if (perm.getName().equals("sun.font.fontmanager")) { return true; } if(perm.getActions().contains("write") && !executingTestCase) { if(org.evosuite.runtime.System.isSystemProperty(perm.getName())) { return false; } else { return true; } } return org.evosuite.runtime.System.handlePropertyPermission(perm); }
result.setExecutedStatements(num.get()); result.setThrownExceptions(exceptionsThrown); result.setReadProperties(org.evosuite.runtime.System.getAllPropertiesReadSoFar()); result.setWasAnyPropertyWritten(org.evosuite.runtime.System.wasAnyPropertyWritten());
/** * Reset runtime to initial state */ public static void resetRuntime() { currentTime = 1392409281320L; // 2014-02-14, 20:21 wasTimeAccessed = false; hashKeys.clear(); restoreProperties(); needToRestoreProperties = false; //readProperties.clear(); //we cannot reset read properties here }
/** * Fully reset the state, not only the one related to * latest test case execution */ public static void fullReset(){ resetRuntime(); /* * System properties have to be treated very specially because * we want to keep track of them when they are accessed in * static blocks, and also from non-instrumented classes */ synchronized (readProperties) { readProperties.clear(); } }
if(isSystemProperty(perm.getName())) { String var = perm.getName(); if(!isSystemProperty(var)) { synchronized (readProperties) { readProperties.add(var);
@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(); } }
public void goingToEndTestCase() throws IllegalStateException { if (!executingTestCase) { throw new IllegalStateException("Trying to disable sandbox when not test case was run"); } /* * it is important to call this method here as soon as the test case * has finished executing, because properties could be used by * EvoSuite as well */ org.evosuite.runtime.System.restoreProperties(); for(File file : filesToDelete) { file.deleteOnExit(); } executingTestCase = false; }
System.resetRuntime(); MockThread.reset(); ThreadCounter.getInstance().resetSingleton();
public MockDate() { super(org.evosuite.runtime.System.currentTimeMillis()); }
@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(); } }
public static String toString(Object o) { if(o == null) throw new NullPointerException(); return o.getClass().getName() + "@" + String.format("%010d", identityHashCode(o)); }
public MockGregorianCalendar(Locale aLocale) { super(aLocale); this.setTimeInMillis(org.evosuite.runtime.System.currentTimeMillis()); }
@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(); } }
public MockGregorianCalendar(TimeZone zone) { super(zone); this.setTimeInMillis(org.evosuite.runtime.System.currentTimeMillis()); }
@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(); } }
public MockGregorianCalendar(TimeZone zone, Locale aLocale) { super(zone, aLocale); this.setTimeInMillis(org.evosuite.runtime.System.currentTimeMillis()); }