Created
October 11, 2017 15:12
-
-
Save cschneider/5bb61baa032e16c4492e5c6235648de7 to your computer and use it in GitHub Desktop.
return Process and exit code for exam TestContainer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void assertExitCode(TestContainer container, int expectedExitCode, int timeout, TimeUnit timeUnit) throws Exception { | |
Process process = getProcess(container); | |
Assert.assertTrue(process.waitFor(timeout, timeUnit)); | |
Assert.assertEquals(expectedExitCode, process.exitValue()); | |
} | |
protected Process getProcess(TestContainer container) { | |
try { | |
ForkedFrameworkFactory factory = getField(container, "frameworkFactory"); | |
DefaultJavaRunner runner = getField(factory, "javaRunner"); | |
return getField(runner,"m_frameworkProcess"); | |
} catch (Exception e) { | |
throw new RuntimeException(e.getMessage(), e); | |
} | |
} | |
@SuppressWarnings("unchecked") | |
private <T> T getField(Object obj, String name) throws NoSuchFieldException, IllegalAccessException { | |
Field factoryField = obj.getClass().getDeclaredField(name); | |
factoryField.setAccessible(true); | |
return (T) factoryField.get(obj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment