mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/validator/TestValidatorImpl.java
@Test
    public void testObjectXMLOutputOnError() throws SAXException, IOException, MarshalException
    {
        TestClass data = new TestClass();
        doThrow(new SAXException("blah")).when(m_Validator).validate(Matchers.any(Source.class));
        
        XmlMarshalService xmlMarshallService = mock(XmlMarshalService.class);
        m_SUT.setXMLMarshaller(xmlMarshallService);
        when(xmlMarshallService.createXmlByteArray(anyObject(), eq(true))).thenReturn("<blah>".getBytes());
        
        //try to validate this invalid data and catch exception
        //verify that exception method contains object's representation in
        //XML
        try
        {
            m_SUT.validate(data);
            fail("Expecting exception");
        }
        catch (ValidationFailedException exception)
        {
            assertThat(exception.getMessage(), is("Problem validating XML:\n<blah>"));
        }
        
        // verify able to handle situation if XML cannot be created
        when(xmlMarshallService.createXmlByteArray(anyObject(), eq(true)))
            .thenThrow(new MarshalException("marshall exception"));
        
        try
        {
            m_SUT.validate(data);
            fail("Expecting exception");
        }
        catch (ValidationFailedException exception)
        {
            assertThat(exception.getMessage(), 
                     is("Problem validating XML (and unable to marshall to XML: marshall exception)"));
        }
    }
/**
     * Verify the ValidationFailedException contains object xml. 
     */
Verify the ValidationFailedException contains object xml.
Verify the ValidationFailedException contains object xml .
@Test
    public void testObjectXMLOutputOnError() throws SAXException, IOException, MarshalException
    {
        TestClass data = new TestClass();
        doThrow(new SAXException("blah")).when(m_Validator).validate(Matchers.any(Source.class));
        XmlMarshalService xmlMarshallService = mock(XmlMarshalService.class);
        m_SUT.setXMLMarshaller(xmlMarshallService);
        when(xmlMarshallService.createXmlByteArray(anyObject(), eq(true))).thenReturn("<blah>".getBytes());
        try
        {
            m_SUT.validate(data);
            fail("Expecting exception");
        }
        catch (ValidationFailedException exception)
        {
            assertThat(exception.getMessage(), is("Problem validating XML:\n<blah>"));
        }
        when(xmlMarshallService.createXmlByteArray(anyObject(), eq(true)))
            .thenThrow(new MarshalException("marshall exception"));
        try
        {
            m_SUT.validate(data);
            fail("Expecting exception");
        }
        catch (ValidationFailedException exception)
        {
            assertThat(exception.getMessage(), 
                     is("Problem validating XML (and unable to marshall to XML: marshall exception)"));
        }
    }
@ Test public void testObjectXMLOutputOnError ( ) throws SAXException , IOException , MarshalException { TestClass data = new TestClass ( ) ; doThrow ( new SAXException ( "blah" ) ) . when ( m_Validator ) . validate ( Matchers . any ( Source . class ) ) ; XmlMarshalService xmlMarshallService = mock ( XmlMarshalService . class ) ; m_SUT . setXMLMarshaller ( xmlMarshallService ) ; when ( xmlMarshallService . createXmlByteArray ( anyObject ( ) , eq ( true ) ) ) . thenReturn ( "<blah>" . getBytes ( ) ) ; try { m_SUT . validate ( data ) ; fail ( "Expecting exception" ) ; } catch ( ValidationFailedException exception ) { assertThat ( exception . getMessage ( ) , is ( "Problem validating XML:\n<blah>" ) ) ; } when ( xmlMarshallService . createXmlByteArray ( anyObject ( ) , eq ( true ) ) ) . thenThrow ( new MarshalException ( "marshall exception" ) ) ; try { m_SUT . validate ( data ) ; fail ( "Expecting exception" ) ; } catch ( ValidationFailedException exception ) { assertThat ( exception . getMessage ( ) , is ( "Problem validating XML (and unable to marshall to XML: marshall exception)" ) ) ; } }
Verify the ValidationFailedException contains object xml.
Verify the ValidationFailedException contains object xml .
//try to validate this invalid data and catch exception //verify that exception method contains object's representation in //XML // verify able to handle situation if XML cannot be created