OptionsHelper { public static String applyRule(String ruleName, String serverOptStr, boolean value) throws OptionsException { throwOptionsExceptionIfConditionFails(isNotBlank(serverOptStr), "Null or Empty server options spec"); if (isBlank(ruleName)) { if (value) { return OPTPFX + serverOptStr; } } else { throwOptionsException("Unrecognized option rule name in options parser: '%s'", ruleName); } return EMPTY; } private  OptionsHelper(); static String applyRule(String ruleName, String serverOptStr, boolean value); static String applyRule(String ruleName, String serverOptStr, int value); static String applyRule(String ruleName, String serverOptStr, long value); static String applyRule(String ruleName, String serverOptStr, String value); static boolean objectToBoolean(Object optValue); static final String OPTPFX; }
@Test public void applyRule_boolean() throws Exception { assertThrows(OptionsException.class, () -> OptionsHelper.applyRule("nonnull", "e", true)); assertThrows(OptionsException.class, () -> OptionsHelper.applyRule(null, null, true)); String optionsField = OptionsHelper.applyRule(null, "f", true); assertThat(optionsField, is("-f")); optionsField = OptionsHelper.applyRule(null, "f", false); assertThat(optionsField, is(EMPTY)); }
@Test public void applyRule_integer() throws Exception { assertThrows(OptionsException.class, () -> OptionsHelper.applyRule(null, null, 1)); assertThrows(OptionsException.class, () -> OptionsHelper.applyRule("nonnull", "not-exist", 1)); String optionsField = OptionsHelper.applyRule(null, "d", 12); assertThat(optionsField, is("-d12")); optionsField = OptionsHelper.applyRule("gtz", "d", 12); assertThat(optionsField, is("-d12")); optionsField = OptionsHelper.applyRule("gtz", "d", 0); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule("cl", "d", 0); assertThat(optionsField, is("-ddefault")); optionsField = OptionsHelper.applyRule("cl", "d", 12); assertThat(optionsField, is("-d12")); optionsField = OptionsHelper.applyRule("cl", "d", -1); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule("clz", "d", 12); assertThat(optionsField, is("-d12")); optionsField = OptionsHelper.applyRule("clz", "d", 0); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule("dcn", "d", 12); assertThat(optionsField, is("-d12")); optionsField = OptionsHelper.applyRule("dcn", "d", 0); assertThat(optionsField, is("-d")); optionsField = OptionsHelper.applyRule("dcn", "d", -1); assertThat(optionsField, is(EMPTY)); }
@Test public void applyRule_long() throws Exception { assertThrows(OptionsException.class, () -> OptionsHelper.applyRule(null, null, 1L)); assertThrows(OptionsException.class, () -> OptionsHelper.applyRule("nonnull", "not-exist", 1L)); String optionsField = OptionsHelper.applyRule(null, "d", 2L); assertThat(optionsField, is("-d2")); optionsField = OptionsHelper.applyRule("gtz", "d", 2L); assertThat(optionsField, is("-d2")); optionsField = OptionsHelper.applyRule("gtz", "d", 0L); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule("gez", "d", 0L); assertThat(optionsField, is("-d0")); optionsField = OptionsHelper.applyRule("gez", "d", 2L); assertThat(optionsField, is("-d2")); optionsField = OptionsHelper.applyRule("gez", "d", -2L); assertThat(optionsField, is(EMPTY)); }
@Test public void applyRule_String() throws Exception { assertThrows(OptionsException.class, () -> OptionsHelper.applyRule(null, null, "string")); assertThrows(OptionsException.class, () -> OptionsHelper.applyRule("notnull", null, "string")); String optionsField = OptionsHelper.applyRule(null, "d", null); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule(null, "d", EMPTY); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule(null, "d", SPACE); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule(null, "o", "myClient"); assertThat(optionsField, is("-omyClient")); }
@Test public void applyRule_boolean() throws Exception { try { OptionsHelper.applyRule("nonnull", "e", true); fail("Expected Exception!"); } catch (Throwable e) { assertEquals(OptionsException.class, e.getClass()); } try { OptionsHelper.applyRule(null, null, true); fail("Expected Exception!"); } catch (Throwable e) { assertEquals(OptionsException.class, e.getClass()); } String optionsField = OptionsHelper.applyRule(null, "f", true); assertEquals("-f", optionsField); optionsField = OptionsHelper.applyRule(null, "f", false); assertEquals("", optionsField); }
@Test public void applyRule_integer() throws Exception { try { OptionsHelper.applyRule(null, null, 1); fail("Expected Exception!"); } catch (Throwable e) { assertEquals(OptionsException.class, e.getClass()); } try { OptionsHelper.applyRule("nonnull", "not-exist", 1); fail("Expected Exception!"); } catch (Throwable e) { assertEquals(OptionsException.class, e.getClass()); } String optionsField = OptionsHelper.applyRule(null, "d", 12); assertEquals("-d12", optionsField); optionsField = OptionsHelper.applyRule("gtz", "d", 12); assertEquals("-d12", optionsField); optionsField = OptionsHelper.applyRule("gtz", "d", 0); assertEquals("", optionsField); optionsField = OptionsHelper.applyRule("cl", "d", 0); assertEquals("-ddefault", optionsField); optionsField = OptionsHelper.applyRule("cl", "d", 12); assertEquals("-d12", optionsField); optionsField = OptionsHelper.applyRule("cl", "d", -1); assertEquals("", optionsField); optionsField = OptionsHelper.applyRule("clz", "d", 12); assertEquals("-d12", optionsField); optionsField = OptionsHelper.applyRule("clz", "d", 0); assertEquals("", optionsField); optionsField = OptionsHelper.applyRule("dcn", "d", 12); assertEquals("-d12", optionsField); optionsField = OptionsHelper.applyRule("dcn", "d", 0); assertEquals("-d", optionsField); optionsField = OptionsHelper.applyRule("dcn", "d", -1); assertEquals("", optionsField); }
@Test public void applyRule_long() throws Exception { try { OptionsHelper.applyRule(null, null, 1L); fail("Expected Exception!"); } catch (Throwable e) { assertEquals(OptionsException.class, e.getClass()); } try { OptionsHelper.applyRule("nonnull", "not-exist", 1L); fail("Expected Exception!"); } catch (Throwable e) { assertEquals(OptionsException.class, e.getClass()); } String optionsField = OptionsHelper.applyRule(null, "d", 2L); assertEquals("-d2", optionsField); optionsField = OptionsHelper.applyRule("gtz", "d", 2L); assertEquals("-d2", optionsField); optionsField = OptionsHelper.applyRule("gtz", "d", 0L); assertEquals("", optionsField); optionsField = OptionsHelper.applyRule("gez", "d", 0L); assertEquals("-d0", optionsField); optionsField = OptionsHelper.applyRule("gez", "d", 2L); assertEquals("-d2", optionsField); optionsField = OptionsHelper.applyRule("gez", "d", -2L); assertEquals("", optionsField); }
@Test public void applyRule_String() throws Exception { try { OptionsHelper.applyRule(null, null, "string"); fail("Expected Exception!"); } catch (Throwable e) { assertEquals(OptionsException.class, e.getClass()); } try { OptionsHelper.applyRule("notnull", null, "string"); fail("Expected Exception!"); } catch (Throwable e) { assertEquals(OptionsException.class, e.getClass()); } String optionsField = OptionsHelper.applyRule(null, "d", null); assertEquals("", optionsField); optionsField = OptionsHelper.applyRule(null, "d", " "); assertEquals("", optionsField); optionsField = OptionsHelper.applyRule(null, "d", " "); assertEquals("", optionsField); optionsField = OptionsHelper.applyRule(null, "o", "myClient"); assertEquals("-omyClient", optionsField); }
@Test public void applyRule_boolean() throws Exception { expectThrows(OptionsException.class, () -> OptionsHelper.applyRule("nonnull", "e", true)); expectThrows(OptionsException.class, () -> OptionsHelper.applyRule(null, null, true)); String optionsField = OptionsHelper.applyRule(null, "f", true); assertThat(optionsField, is("-f")); optionsField = OptionsHelper.applyRule(null, "f", false); assertThat(optionsField, is(EMPTY)); }
@Test public void applyRule_integer() throws Exception { expectThrows(OptionsException.class, () -> OptionsHelper.applyRule(null, null, 1)); expectThrows(OptionsException.class, () -> OptionsHelper.applyRule("nonnull", "not-exist", 1)); String optionsField = OptionsHelper.applyRule(null, "d", 12); assertThat(optionsField, is("-d12")); optionsField = OptionsHelper.applyRule("gtz", "d", 12); assertThat(optionsField, is("-d12")); optionsField = OptionsHelper.applyRule("gtz", "d", 0); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule("cl", "d", 0); assertThat(optionsField, is("-ddefault")); optionsField = OptionsHelper.applyRule("cl", "d", 12); assertThat(optionsField, is("-d12")); optionsField = OptionsHelper.applyRule("cl", "d", -1); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule("clz", "d", 12); assertThat(optionsField, is("-d12")); optionsField = OptionsHelper.applyRule("clz", "d", 0); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule("dcn", "d", 12); assertThat(optionsField, is("-d12")); optionsField = OptionsHelper.applyRule("dcn", "d", 0); assertThat(optionsField, is("-d")); optionsField = OptionsHelper.applyRule("dcn", "d", -1); assertThat(optionsField, is(EMPTY)); }
@Test public void applyRule_long() throws Exception { expectThrows(OptionsException.class, () -> OptionsHelper.applyRule(null, null, 1L)); expectThrows(OptionsException.class, () -> OptionsHelper.applyRule("nonnull", "not-exist", 1L)); String optionsField = OptionsHelper.applyRule(null, "d", 2L); assertThat(optionsField, is("-d2")); optionsField = OptionsHelper.applyRule("gtz", "d", 2L); assertThat(optionsField, is("-d2")); optionsField = OptionsHelper.applyRule("gtz", "d", 0L); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule("gez", "d", 0L); assertThat(optionsField, is("-d0")); optionsField = OptionsHelper.applyRule("gez", "d", 2L); assertThat(optionsField, is("-d2")); optionsField = OptionsHelper.applyRule("gez", "d", -2L); assertThat(optionsField, is(EMPTY)); }
@Test public void applyRule_String() throws Exception { expectThrows(OptionsException.class, () -> OptionsHelper.applyRule(null, null, "string")); expectThrows(OptionsException.class, () -> OptionsHelper.applyRule("notnull", null, "string")); String optionsField = OptionsHelper.applyRule(null, "d", null); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule(null, "d", EMPTY); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule(null, "d", SPACE); assertThat(optionsField, is(EMPTY)); optionsField = OptionsHelper.applyRule(null, "o", "myClient"); assertThat(optionsField, is("-omyClient")); }