mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/utils/TestHexConverter.java
@Test
    public void testInvalidStringInput()
    {
        HexConverter hexConverter = new HexConverter();
        
        //invalid characters and no prepended 0x indicating it is a hex value
        try
        {
            hexConverter.getAsObject(null, null, "ssksksksaas");
            fail("Expected ConverterException for invalid input.");
        }
        catch(ConverterException exception)
        {
            //expecting exception
            assertThat(exception.getFacesMessage().getSummary(), is("Invalid hexadecimal value."));
        }
        
        //invalid characters for hex value
        try
        {
            hexConverter.getAsObject(null, null, "0x%&@");
            fail("Expected ConverterException for invalid input.");
        }
        catch(ConverterException exception)
        {
            //expecting exception
            assertThat(exception.getFacesMessage().getSummary(), is("Invalid hexadecimal value."));
        }
        
        //user doesn't input anything
        try
        {
            hexConverter.getAsObject(null, null, "0x");
            fail("Expected ConverterException for invalid input."); 
        }
        catch(ConverterException exception)
        {
            //expecting exception
            assertThat(exception.getFacesMessage().getDetail(),
                    is("The System ID field requires at least one character."));
        }
        
        //input field is completely blank (field was cleared using "x" button)
        try
        {
            hexConverter.getAsObject(null, null, "");
            fail("Expected ConverterException for invalid input."); 
        }
        catch(ConverterException exception)
        {
            //expecting exception
            assertThat(exception.getFacesMessage().getDetail(), 
                    is("The System ID field requires at least one character."));
        }
        
        //converted number will be greater than integer value can hold
        try
        {
            hexConverter.getAsObject(null, null, "0x100000000");
            fail("Expected ConverterException for invalid input.");
        }
        catch(ConverterException exception)
        {
            //expecting exception
            assertThat(exception.getFacesMessage().getDetail(), is("The hexadecimal value that was converted to a long"
                    + " data type is greater than a possible integer value."));
        }
    }
/**
     * Test that the converter correctly reports not supporting conversion of an invalid formated string
     */
Test that the converter correctly reports not supporting conversion of an invalid formated string
Test that the converter correctly reports not supporting conversion of an invalid formated string
@Test
    public void testInvalidStringInput()
    {
        HexConverter hexConverter = new HexConverter();
        try
        {
            hexConverter.getAsObject(null, null, "ssksksksaas");
            fail("Expected ConverterException for invalid input.");
        }
        catch(ConverterException exception)
        {
            assertThat(exception.getFacesMessage().getSummary(), is("Invalid hexadecimal value."));
        }
        try
        {
            hexConverter.getAsObject(null, null, "0x%&@");
            fail("Expected ConverterException for invalid input.");
        }
        catch(ConverterException exception)
        {
            assertThat(exception.getFacesMessage().getSummary(), is("Invalid hexadecimal value."));
        }
        try
        {
            hexConverter.getAsObject(null, null, "0x");
            fail("Expected ConverterException for invalid input."); 
        }
        catch(ConverterException exception)
        {
            assertThat(exception.getFacesMessage().getDetail(),
                    is("The System ID field requires at least one character."));
        }
        try
        {
            hexConverter.getAsObject(null, null, "");
            fail("Expected ConverterException for invalid input."); 
        }
        catch(ConverterException exception)
        {
            assertThat(exception.getFacesMessage().getDetail(), 
                    is("The System ID field requires at least one character."));
        }
        try
        {
            hexConverter.getAsObject(null, null, "0x100000000");
            fail("Expected ConverterException for invalid input.");
        }
        catch(ConverterException exception)
        {
            assertThat(exception.getFacesMessage().getDetail(), is("The hexadecimal value that was converted to a long"
                    + " data type is greater than a possible integer value."));
        }
    }
@ Test public void testInvalidStringInput ( ) { HexConverter hexConverter = new HexConverter ( ) ; try { hexConverter . getAsObject ( null , null , "ssksksksaas" ) ; fail ( "Expected ConverterException for invalid input." ) ; } catch ( ConverterException exception ) { assertThat ( exception . getFacesMessage ( ) . getSummary ( ) , is ( "Invalid hexadecimal value." ) ) ; } try { hexConverter . getAsObject ( null , null , "0x%&@" ) ; fail ( "Expected ConverterException for invalid input." ) ; } catch ( ConverterException exception ) { assertThat ( exception . getFacesMessage ( ) . getSummary ( ) , is ( "Invalid hexadecimal value." ) ) ; } try { hexConverter . getAsObject ( null , null , "0x" ) ; fail ( "Expected ConverterException for invalid input." ) ; } catch ( ConverterException exception ) { assertThat ( exception . getFacesMessage ( ) . getDetail ( ) , is ( "The System ID field requires at least one character." ) ) ; } try { hexConverter . getAsObject ( null , null , "" ) ; fail ( "Expected ConverterException for invalid input." ) ; } catch ( ConverterException exception ) { assertThat ( exception . getFacesMessage ( ) . getDetail ( ) , is ( "The System ID field requires at least one character." ) ) ; } try { hexConverter . getAsObject ( null , null , "0x100000000" ) ; fail ( "Expected ConverterException for invalid input." ) ; } catch ( ConverterException exception ) { assertThat ( exception . getFacesMessage ( ) . getDetail ( ) , is ( "The hexadecimal value that was converted to a long" + " data type is greater than a possible integer value." ) ) ; } }
Test that the converter correctly reports not supporting conversion of an invalid formated string
Test that the converter correctly reports not supporting conversion of an invalid formated string
//invalid characters and no prepended 0x indicating it is a hex value //expecting exception //invalid characters for hex value //expecting exception //user doesn't input anything //expecting exception //input field is completely blank (field was cleared using "x" button) //expecting exception //converted number will be greater than integer value can hold //expecting exception