Я пытаюсь покрыть тестовый класс до 100%.Тем не менее, я могу сделать это до 90% только потому, что не могу протестировать блок улова.Может кто-нибудь сказать мне, как я могу покрыть блок catch.
Ниже мой класс для тестирования:
public class UnsubscribeXmlTransformer {
public Map<String, Object> process(Map<String, Object> requestMap) {
String inputStream = requestMap.get(NeoConstants.INPUTSTREAM).toString();
Smooks smooks;
try {
smooks = new Smooks("Unsubscribe-smooks.xml");
JavaResult javaResult = new JavaResult();
smooks.filterSource(new StringSource(inputStream), javaResult);
UnsubscribeDetailsVO unsubscribeDetailsVO = (UnsubscribeDetailsVO) javaResult
.getBean("unsubscribeDetailsVO");
requestMap.put("unsubscribeDetailsVO", unsubscribeDetailsVO);
} catch (IOException | SAXException e) { }
return requestMap;
}
}
А вот мой класс Test:
public class UnsubscribeXmlTransformerTest {
Map<String, Object> requestMap = null;
@Before
public void prepareRequestMap() {
requestMap = new HashMap<>();
String inputStream = "some xml tags";
requestMap.put(NeoConstants.INPUTSTREAM, inputStream);
}
@Test
public void processTest() throws Exception {
UnsubscribeXmlTransformer ref = new UnsubscribeXmlTransformer();
Map<String, Object> result = ref.process(requestMap);
Assert.assertNotNull("Result is not null", result);
Assert.assertFalse("Result is not empty", result.isEmpty());
Assert.assertTrue("Result contains key named inputStream", result.containsKey(NeoConstants.INPUTSTREAM));
Assert.assertTrue("Result contains key named unsubscribeDetailsVO", result.containsKey("unsubscribeDetailsVO"));
Assert.assertTrue("Value with key unsubscribeDetailsVO is an instance of UnsubscribeDetailsVO", result.get("unsubscribeDetailsVO") instanceof UnsubscribeDetailsVO);
}
@Test(expected = IOException.class)
public void processTestForException() {
UnsubscribeXmlTransformer ref = new UnsubscribeXmlTransformer();
// how to cover
}
}