title: How to cover catch block in Junit testing?
body: <p>I'm trying to cover a test class to 100%. However, I'm able to do it up to 90% only as I'm not able to test catch block. Can anyone tell me how can I cover the catch block.</p>
  
  <p>Below is my class to be tested:</p>
  
  <pre><code>public class UnsubscribeXmlTransformer {
  
      public Map&lt;String, Object&gt; process(Map&lt;String, Object&gt; 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;
      }
  </code></pre>
  
  <p>}</p>
  
  <p>And here is my Test class:</p>
  
  <pre><code>public class UnsubscribeXmlTransformerTest {
      Map&lt;String, Object&gt; requestMap = null;  
  
      @Before
      public void prepareRequestMap() {
          requestMap = new HashMap&lt;&gt;();
          String inputStream = "some xml tags";
  
          requestMap.put(NeoConstants.INPUTSTREAM, inputStream);      
      }
  
  
      @Test
      public void processTest() throws Exception {
          UnsubscribeXmlTransformer ref = new UnsubscribeXmlTransformer();
          Map&lt;String, Object&gt; 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                 
      }
  }
  </code></pre>