@Test public void test() throws Exception { MyFactory factory = new MyFactory(); MyObject object; try { object = factory.buildObject(new String[]{}, 0, false, "usage"); Assert.fail(); } catch (IOException exc) { Assert.assertTrue(exc.getCause() instanceof ArrayIndexOutOfBoundsException); } object = factory.buildObject(new String[]{"required"}, 0, false, "usage"); Assert.assertEquals(object.required, "required"); Assert.assertNull(object.string1); Assert.assertNull(object.string2); object = factory.buildObject(new String[]{"-setString1", "str1", "required"}, 0, false, "usage"); Assert.assertEquals(object.required, "required"); Assert.assertEquals(object.string1, "str1"); Assert.assertNull(object.string2); object = factory.buildObject(new String[]{"-foo", "bar", "required"}, 0, false, "usage"); Assert.assertEquals(object.required, "required"); Assert.assertEquals(object.string2, "bar"); Assert.assertNull(object.string1); object = factory.buildObject(new String[]{"-foo", "bar", "-setString1", "str1", "required"}, 0, false, "usage"); Assert.assertEquals(object.required, "required"); Assert.assertEquals(object.string2, "bar"); Assert.assertEquals(object.string1, "str1"); }
@Override public T buildObject(CommandLine cli) { try { T obj = constructObject(cli); applyCommandLineOptions(cli, obj); return obj; } catch (IOException exc) { throw new RuntimeException("Could not instantiate " + this.klazz.getSimpleName(), exc); } }
PublicMethodsCliObjectFactory implements CliObjectFactory<T> { @Override public T buildObject(CommandLine cli) { try { T obj = constructObject(cli); applyCommandLineOptions(cli, obj); return obj; } catch (IOException exc) { throw new RuntimeException("Could not instantiate " + this.klazz.getSimpleName(), exc); } } }
PublicMethodsCliObjectFactory implements CliObjectFactory<T> { @Override public T buildObject(CommandLine cli) { try { T obj = constructObject(cli); applyCommandLineOptions(cli, obj); return obj; } catch (IOException exc) { throw new RuntimeException("Could not instantiate " + this.klazz.getSimpleName(), exc); } } PublicMethodsCliObjectFactory(Class<? extends T> klazz); }
PublicMethodsCliObjectFactory implements CliObjectFactory<T> { @Override public T buildObject(CommandLine cli) { try { T obj = constructObject(cli); applyCommandLineOptions(cli, obj); return obj; } catch (IOException exc) { throw new RuntimeException("Could not instantiate " + this.klazz.getSimpleName(), exc); } } PublicMethodsCliObjectFactory(Class<? extends T> klazz); @Override T buildObject(CommandLine cli); @Override T buildObject(String[] args, int offset, boolean printUsage, String usage); @Override String getUsageString(); void applyCommandLineOptions(CommandLine cli, T embeddedGobblin); }
PublicMethodsCliObjectFactory implements CliObjectFactory<T> { @Override public T buildObject(CommandLine cli) { try { T obj = constructObject(cli); applyCommandLineOptions(cli, obj); return obj; } catch (IOException exc) { throw new RuntimeException("Could not instantiate " + this.klazz.getSimpleName(), exc); } } PublicMethodsCliObjectFactory(Class<? extends T> klazz); @Override T buildObject(CommandLine cli); @Override T buildObject(String[] args, int offset, boolean printUsage, String usage); @Override String getUsageString(); void applyCommandLineOptions(CommandLine cli, T embeddedGobblin);  }