mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/advanced/configuration/TestConfigPropModelImpl.java
@Test
    public void testGetValue()
    {
        // single default value
        when(m_AttributeModel.getDefaultValues()).thenReturn(Arrays.asList(new String[]{"one default"}));
        m_SUT = new ConfigPropModelImpl(m_AttributeModel);
        assertThat(m_SUT.getValue(), is((Object)"one default"));
        
        when(m_AttributeModel.getDefaultValues()).thenReturn(Arrays.asList(new String[]{"default 1", "default 2"}));
        m_SUT = new ConfigPropModelImpl(m_AttributeModel);
        assertThat(m_SUT.getValue(), is((Object)Arrays.asList(new String[]{"default 1", "default 2"})));
        
        // set a value
        m_SUT.setValue("test non-default");
        assertThat(m_SUT.getValue(), is((Object)"test non-default"));
        
        //test empty default value array
        when(m_AttributeModel.getDefaultValues()).thenReturn(Arrays.asList(new String[]{}));
        m_SUT = new ConfigPropModelImpl(m_AttributeModel);
        assertThat(m_SUT.getValue(), is((Object)""));
        
        //ensure that returned type corresponds to given attribute definition type (boolean)
        when(m_AttributeModel.getDefaultValues()).thenReturn(Arrays.asList(new String[]{"true"}));
        when(m_AttributeModel.getType()).thenReturn(AttributeDefinition.BOOLEAN);
        m_SUT = new ConfigPropModelImpl(m_AttributeModel);
        Boolean myBool = (Boolean)m_SUT.getValue();
        assertThat(myBool, is(true));
        
        //for good measure, verify bad boolean type will result in exception
        when(m_AttributeModel.getDefaultValues()).thenReturn(Arrays.asList(new String[]{"not a bool"}));
        m_SUT = new ConfigPropModelImpl(m_AttributeModel);
        try
        {
            fail("illegal argument exception expected. Value is: "+ m_SUT.getValue());
        }
        catch (IllegalArgumentException e)
        {
            assertThat(e.getMessage(), containsString("cannot be parsed to a boolean"));
        }
    }
/**
     * Test the get value method.
     * Verify that if no value is set that the default is returned.
     * Verify that the correct value is returned if a value is a set.
     */
Test the get value method.
Verify that if no value is set that the default is returned.
Verify that the correct value is returned if a value is a set.
Test the get value method . Verify that if no value is set that the default is returned . Verify that the correct value is returned if a value is a set .
@Test
    public void testGetValue()
    {
        when(m_AttributeModel.getDefaultValues()).thenReturn(Arrays.asList(new String[]{"one default"}));
        m_SUT = new ConfigPropModelImpl(m_AttributeModel);
        assertThat(m_SUT.getValue(), is((Object)"one default"));
        when(m_AttributeModel.getDefaultValues()).thenReturn(Arrays.asList(new String[]{"default 1", "default 2"}));
        m_SUT = new ConfigPropModelImpl(m_AttributeModel);
        assertThat(m_SUT.getValue(), is((Object)Arrays.asList(new String[]{"default 1", "default 2"})));
        m_SUT.setValue("test non-default");
        assertThat(m_SUT.getValue(), is((Object)"test non-default"));
        when(m_AttributeModel.getDefaultValues()).thenReturn(Arrays.asList(new String[]{}));
        m_SUT = new ConfigPropModelImpl(m_AttributeModel);
        assertThat(m_SUT.getValue(), is((Object)""));
        when(m_AttributeModel.getDefaultValues()).thenReturn(Arrays.asList(new String[]{"true"}));
        when(m_AttributeModel.getType()).thenReturn(AttributeDefinition.BOOLEAN);
        m_SUT = new ConfigPropModelImpl(m_AttributeModel);
        Boolean myBool = (Boolean)m_SUT.getValue();
        assertThat(myBool, is(true));
        when(m_AttributeModel.getDefaultValues()).thenReturn(Arrays.asList(new String[]{"not a bool"}));
        m_SUT = new ConfigPropModelImpl(m_AttributeModel);
        try
        {
            fail("illegal argument exception expected. Value is: "+ m_SUT.getValue());
        }
        catch (IllegalArgumentException e)
        {
            assertThat(e.getMessage(), containsString("cannot be parsed to a boolean"));
        }
    }
@ Test public void testGetValue ( ) { when ( m_AttributeModel . getDefaultValues ( ) ) . thenReturn ( Arrays . asList ( new String [ ] { "one default" } ) ) ; m_SUT = new ConfigPropModelImpl ( m_AttributeModel ) ; assertThat ( m_SUT . getValue ( ) , is ( ( Object ) "one default" ) ) ; when ( m_AttributeModel . getDefaultValues ( ) ) . thenReturn ( Arrays . asList ( new String [ ] { "default 1" , "default 2" } ) ) ; m_SUT = new ConfigPropModelImpl ( m_AttributeModel ) ; assertThat ( m_SUT . getValue ( ) , is ( ( Object ) Arrays . asList ( new String [ ] { "default 1" , "default 2" } ) ) ) ; m_SUT . setValue ( "test non-default" ) ; assertThat ( m_SUT . getValue ( ) , is ( ( Object ) "test non-default" ) ) ; when ( m_AttributeModel . getDefaultValues ( ) ) . thenReturn ( Arrays . asList ( new String [ ] { } ) ) ; m_SUT = new ConfigPropModelImpl ( m_AttributeModel ) ; assertThat ( m_SUT . getValue ( ) , is ( ( Object ) "" ) ) ; when ( m_AttributeModel . getDefaultValues ( ) ) . thenReturn ( Arrays . asList ( new String [ ] { "true" } ) ) ; when ( m_AttributeModel . getType ( ) ) . thenReturn ( AttributeDefinition . BOOLEAN ) ; m_SUT = new ConfigPropModelImpl ( m_AttributeModel ) ; Boolean myBool = ( Boolean ) m_SUT . getValue ( ) ; assertThat ( myBool , is ( true ) ) ; when ( m_AttributeModel . getDefaultValues ( ) ) . thenReturn ( Arrays . asList ( new String [ ] { "not a bool" } ) ) ; m_SUT = new ConfigPropModelImpl ( m_AttributeModel ) ; try { fail ( "illegal argument exception expected. Value is: " + m_SUT . getValue ( ) ) ; } catch ( IllegalArgumentException e ) { assertThat ( e . getMessage ( ) , containsString ( "cannot be parsed to a boolean" ) ) ; } }
Test the get value method.
Test the get value method .
// single default value // set a value //test empty default value array //ensure that returned type corresponds to given attribute definition type (boolean) //for good measure, verify bad boolean type will result in exception