@Test(timeout=3000) public void testDoubleExecution(){ RuntimeSettings.mockSystemIn = true; String data = "Hello World!"; SystemInUtil.getInstance().initForTestCase(); SystemInUtil.addInputLine(data); Scanner scanner = new Scanner(System.in); String first = scanner.nextLine(); scanner.close(); Assert.assertEquals(data, first); //now add the same again SystemInUtil.addInputLine(data); scanner = new Scanner(System.in); String second = scanner.nextLine(); scanner.close(); Assert.assertEquals(data, second); }
@After public void tearDown(){ SystemInUtil.resetSingleton(); }
/** * If System.in was used, add methods to handle/simulate it */ private void handleSystemIn() { if (!hasAddedSystemIn && SystemInUtil.getInstance().hasBeenUsed()) { hasAddedSystemIn = true; try { TestCluster.getInstance() .addEnvironmentTestCall(new GenericMethod( SystemInUtil.class.getMethod("addInputLine", new Class<?>[] { String.class }), new GenericClass(SystemInUtil.class))); } catch (SecurityException e) { logger.error("Error while handling Random: " + e.getMessage(), e); } catch (NoSuchMethodException e) { logger.error("Error while handling Random: " + e.getMessage(), e); } } }
SystemInUtil.getInstance().initForTestCase(); JOptionPaneInputs.getInstance().initForTestCase();
if (TestSuiteWriterUtils.needToUseAgent() || wasSecurityException || SystemInUtil.getInstance().hasBeenUsed() || JOptionPaneInputs.getInstance().hasAnyDialog() || !Properties.NO_RUNTIME_DEPENDENCY || TestSuiteWriterUtils.doesUseMocks(results)) {
SystemInUtil.resetSingleton(); JOptionPaneInputs.resetSingleton(); Runtime.resetSingleton();
if (SystemInUtil.getInstance().hasBeenUsed()) { bd.append(BLOCK_SPACE); bd.append(SystemInUtil.class.getName() + ".getInstance().initForTestCase(); \n");