C32ParserImpl implements C32Parser { @Override public GreenCCD ParseC32(String c32xml) throws C32ParserException { Assert.hasText(c32xml); try { String greenCcdXml = c32ToGreenCcdTransformer .TransformC32ToGreenCcd(c32xml); GreenCCD greenCcdDto = greenCcdSerializer.Deserialize(greenCcdXml); return greenCcdDto; } catch (Exception ex) { String errorMessage = "Error occured when trying to parse C32"; logger.error(errorMessage, ex); throw new C32ParserException(errorMessage, ex); } } C32ParserImpl();  C32ParserImpl(C32ToGreenCcdTransformer c32ToGreenCcdTransformer,
			GreenCcdSerializer greenCcdSerializer); @Override GreenCCD ParseC32(String c32xml);  }
@Test(expected = IllegalArgumentException.class) public void testTransformC32ToGreenCcd_Given_Null_C32Xml_Throws_IllegalArgumentException() throws Throwable { C32ToGreenCcdTransformer c32ToGreenCcdTransformer = mock(C32ToGreenCcdTransformer.class); GreenCcdSerializer greenCcdSerializern = mock(GreenCcdSerializer.class); C32ParserImpl sut = new C32ParserImpl(c32ToGreenCcdTransformer, greenCcdSerializern); sut.ParseC32(null); }
@Test(expected = IllegalArgumentException.class) public void testTransformC32ToGreenCcd_Given_Empty_C32Xml_Throws_IllegalArgumentException() throws Throwable { C32ToGreenCcdTransformer c32ToGreenCcdTransformer = mock(C32ToGreenCcdTransformer.class); GreenCcdSerializer greenCcdSerializern = mock(GreenCcdSerializer.class); C32ParserImpl sut = new C32ParserImpl(c32ToGreenCcdTransformer, greenCcdSerializern); sut.ParseC32(""); }
@Test(expected = IllegalArgumentException.class) public void testTransformC32ToGreenCcd_Given_NoText_C32Xml_Throws_IllegalArgumentException() throws Throwable { C32ToGreenCcdTransformer c32ToGreenCcdTransformer = mock(C32ToGreenCcdTransformer.class); GreenCcdSerializer greenCcdSerializern = mock(GreenCcdSerializer.class); C32ParserImpl sut = new C32ParserImpl(c32ToGreenCcdTransformer, greenCcdSerializern); sut.ParseC32(" "); }
@Test public void testParseC32_Given_Valid_C32Xml_Succeeds() throws C32ToGreenCcdTransformerException, GreenCcdSerializerException, C32ParserException { String c32Xml = "Is this a valid c32?"; final String greenCcdXmlFileUri = "green_ccd.xml"; String greenCcdXml = ResourceFileReader .getStringFromResourceFile(greenCcdXmlFileUri); C32ToGreenCcdTransformer c32ToGreenCcdTransformer = mock(C32ToGreenCcdTransformer.class); GreenCcdSerializer greenCcdSerializern = mock(GreenCcdSerializer.class); GreenCCD greenCCD = mock(GreenCCD.class); when(c32ToGreenCcdTransformer.TransformC32ToGreenCcd(anyString())) .thenReturn(greenCcdXml); when(greenCcdSerializern.Deserialize(greenCcdXml)).thenReturn(greenCCD); C32ParserImpl sut = new C32ParserImpl(c32ToGreenCcdTransformer, greenCcdSerializern); GreenCCD result = sut.ParseC32(c32Xml); Assert.assertEquals(greenCCD, result); }
@Test(expected=C32ParserException.class) public void testParseC32_Given_C32ToGreenCcdTransformerException_Throws_C32ParserException() throws C32ToGreenCcdTransformerException, GreenCcdSerializerException, C32ParserException { String c32Xml = "Is this a valid c32?"; C32ToGreenCcdTransformer c32ToGreenCcdTransformer = mock(C32ToGreenCcdTransformer.class); GreenCcdSerializer greenCcdSerializern = mock(GreenCcdSerializer.class); GreenCCD greenCCD = mock(GreenCCD.class); when(c32ToGreenCcdTransformer.TransformC32ToGreenCcd(anyString())) .thenThrow(C32ParserException.class); C32ParserImpl sut = new C32ParserImpl(c32ToGreenCcdTransformer, greenCcdSerializern); GreenCCD result = sut.ParseC32(c32Xml); }