Example usage for org.springframework.beans.propertyeditors CustomBooleanEditor VALUE_1

List of usage examples for org.springframework.beans.propertyeditors CustomBooleanEditor VALUE_1

Introduction

In this page you can find the example usage for org.springframework.beans.propertyeditors CustomBooleanEditor VALUE_1.

Prototype

String VALUE_1

To view the source code for org.springframework.beans.propertyeditors CustomBooleanEditor VALUE_1.

Click Source Link

Document

Value of "1" .

Usage

From source file:org.finra.dm.core.ArgumentParserTest.java

@Test
public void testGetStringValueAsBoolean() throws ParseException {
    ArgumentParser argParser = new ArgumentParser("");
    Option strOpt = argParser.addArgument("s", "str", true,
            "Some string input parameter to have a boolean value", false);

    final String shortStrOpt = String.format("-%s", strOpt.getOpt());
    final String longStrOpt = String.format("--%s", strOpt.getLongOpt());

    // Validate the default value - no option is specified.
    argParser.parseArguments(new String[] {});
    assertFalse(argParser.getStringValueAsBoolean(strOpt, false));
    assertTrue(argParser.getStringValueAsBoolean(strOpt, true));

    // Validate all "true" boolean values using both short an long options.
    for (String inputValue : Arrays.asList(CustomBooleanEditor.VALUE_TRUE, CustomBooleanEditor.VALUE_YES,
            CustomBooleanEditor.VALUE_ON, CustomBooleanEditor.VALUE_1)) {
        argParser.parseArguments(new String[] { shortStrOpt, inputValue });
        assertTrue(argParser.getStringValueAsBoolean(strOpt, false));
        argParser.parseArguments(new String[] { longStrOpt, inputValue });
        assertTrue(argParser.getStringValueAsBoolean(strOpt, false));
    }//from w w  w. j  a  va  2s  .co m

    // Validate all "false" boolean values.
    for (String inputValue : Arrays.asList(CustomBooleanEditor.VALUE_FALSE, CustomBooleanEditor.VALUE_NO,
            CustomBooleanEditor.VALUE_OFF, CustomBooleanEditor.VALUE_0)) {
        argParser.parseArguments(new String[] { shortStrOpt, inputValue });
        assertFalse(argParser.getStringValueAsBoolean(strOpt, true));
    }

    // Try to parse an invalid boolean value.
    argParser.parseArguments(new String[] { shortStrOpt, INVALID_BOOLEAN_VALUE });
    try {
        argParser.getStringValueAsBoolean(strOpt, false);
        fail("Suppose to throw a ParseException when option has an invalid boolean value.");
    } catch (ParseException e) {
        assertEquals(String.format("Invalid boolean value [%s]", INVALID_BOOLEAN_VALUE), e.getMessage());
    }
}