### Question:
Launcher { public static void main(String... args) throws Throwable { if (args.length != 1) { throw new LauncherException("Usage: java -jar <this.jar> /path/to/launch-script.properties"); } File script = new File(args[0]); Properties properties = new Properties(); try (InputStream input = new BufferedInputStream(new FileInputStream(script))) { properties.load(input); } catch (IOException e) { throw new LauncherException(MessageFormat.format( "exception occurred while loading launch script: {0}", script), e); } launch(properties); } private  Launcher(); static void main(String... args); static void launch(Properties properties); static void launch(List<File> classpath, String mainClass, List<String> arguments);  }### Answer:
@Test public void simple() throws Throwable { String main = java("com.example.Hello", new String[] { "public class Hello {", " public static void main(String[] args) {", " System.out.println(\"Hello, launcher!\");", " assertThat(Arrays.asList(args), empty());", " }", "}", }); File script = script(main); Launcher.main(script.getAbsolutePath()); }
@Test public void arguments() throws Throwable { String main = java("com.example.Hello", new String[] { "public class Hello {", " public static void main(String[] args) {", " assertThat(Arrays.asList(args), contains(\"A\", \"B\", \"C\"));", " }", "}", }); File script = script(main, "A", "B", "C"); Launcher.main(script.getAbsolutePath()); }
@Test(expected = UnsupportedOperationException.class) public void raise_exception() throws Throwable { String main = java("com.example.Hello", new String[] { "public class Hello {", " public static void main(String[] args) {", " throw new UnsupportedOperationException();", " }", "}", }); File script = script(main); Launcher.main(script.getAbsolutePath()); }
@Test public void check_class_loader() throws Throwable { String main = java("com.example.Check", new String[] { "public class Check {", " public static void main(String[] args) {", " assertThat(ClassLoader.getSystemClassLoader(),", " is(not(Thread.currentThread().getContextClassLoader())));", " }", "}", }); File script = script(main); try (ClassLoaderContext context = new ClassLoaderContext(ClassLoader.getSystemClassLoader())) { Launcher.main(script.getAbsolutePath()); assertThat(Thread.currentThread().getContextClassLoader(), is(context.active)); } }
@Test(expected = LauncherException.class) public void invalid_missing_script() throws Throwable { Launcher.main(new File(temporary.getRoot(), "MISSING.properties").getPath()); }
@Test(expected = LauncherException.class) public void invalid_empty_script() throws Throwable { Launcher.main(temporary.newFile().getPath()); }
@Test(expected = LauncherException.class) public void invalid_missing_class() throws Throwable { java("com.example.Hello", new String[] { "public class Hello {", " public static void main(String[] args) {}", "}", }); File script = script("com.example.MISSING"); Launcher.main(script.getAbsolutePath()); }
@Test(expected = LauncherException.class) public void invalid_missing_main() throws Throwable { String main = java("com.example.Hello", new String[] { "public class Hello {", "}", }); File script = script(main); Launcher.main(script.getAbsolutePath()); }