### Question:
LaunchRunner implements Runnable { @Override public void run() { Thread thread = Thread.currentThread(); ClassLoader classLoader = thread.getContextClassLoader(); try { Class<?> startClass = classLoader.loadClass(this.startClassName); Method entryMethod; try { entryMethod = startClass.getMethod(startMethodName, String[].class); } catch (NoSuchMethodException ex) { entryMethod = startClass.getDeclaredMethod(startMethodName, String[].class); } if (!entryMethod.isAccessible()) { entryMethod.setAccessible(true); } entryMethod.invoke(null, new Object[] { this.args }); } catch (NoSuchMethodException ex) { Exception wrappedEx = new Exception( String.format( "The specified entry class:%s doesn't contain an entry method:%s with appropriate signature.", this.startClassName, this.startMethodName), ex); thread.getThreadGroup().uncaughtException(thread, wrappedEx); } catch (Throwable ex) { thread.getThreadGroup().uncaughtException(thread, ex); } } LaunchRunner(String startClassName, String... args);  LaunchRunner(String startClassName, String startMethodName, String... args); @Override void run(); static void join(ThreadGroup threadGroup);  }### Answer:
@Test public void testMainWithNoParameters() { synchronized (lock) { LaunchRunner launchRunner = new LaunchRunner(MainClass.class.getName()); launchRunner.run(); Assert.assertTrue(LaunchRunnerTest.count == 0); } }
@Test public void testMainWithParameters() { synchronized (lock) { LaunchRunner launchRunner = new LaunchRunner(MainClass.class.getName(), new String[] { "10" }); launchRunner.run(); Assert.assertTrue(LaunchRunnerTest.count == 10); } }
@Test public void testNotMainMethodWithNoParameters() { synchronized (lock) { LaunchRunner launchRunner = new LaunchRunner(LaunchRunnerTest.class.getName(), "add", new String[] {}); launchRunner.run(); Assert.assertTrue(LaunchRunnerTest.count == 0); } }
@Test public void testNotMainMethodWithParameters() { synchronized (lock) { LaunchRunner launchRunner = new LaunchRunner(LaunchRunnerTest.class.getName(), "add", new String[] { "10" }); launchRunner.run(); Assert.assertTrue(LaunchRunnerTest.count == 10); } }