title: Code Coverage with JUnit
body: <p>I am writing a JUnit test case to for a method and I am also trying to get the code coverage. My existing test should cover the scenario but for some reason it still shows as red in the cobertura report. </p>
  
  <p>Method to be tested. </p>
  
  <pre><code>public &lt;T extends BaseServiceResponse&gt; T postProcess(T response,
          ClientResponse clientResponse) throws EISClientException {  
  
      List&lt;Message&gt; messages = response.getMessages();
      if(messages==null || messages.size()==0) {
          return response;
      }
  
      Map&lt;String, Message&gt; messagesMap = populateMessages(response.getMessages());
      ConditionOperator condition = getCondition();
  
      switch(condition) {
          case OR:
              checkORCondition( messagesMap );
              break;
          case AND:
              checkANDCondition( messagesMap );
              break;
      }       
      return response;
  }   
  </code></pre>
  
  <p>JUnit test case:</p>
  
  <pre><code>@Test
  public void testPostProcess() throws Exception {
      clientResponse = mock(ClientResponse.class);
      RetrieveBillingServiceResponse response = new RetrieveBillingServiceResponse();
  
      // Testing OR condition (200 status code)
      MessageToExceptionPostProcessFilter postProcessFilter = new MessageToExceptionPostProcessFilter();
      postProcessFilter.setCondition(ConditionOperator.OR);
  
      Message message = new Message();
      message.setMessageCode("200");
      message.setMessageType(MessageTypeEnum.MESSAGE_TYPE_INFO);
      message.setMessageText("Service completed successfully");
  
      response.setMessages(Arrays.asList(message));
  
      RetrieveBillingServiceResponse serviceResponse = postProcessFilter.postProcess(response, clientResponse);
  
      assertNotNull(serviceResponse.getMessages());
      assertEquals(1, serviceResponse.getMessages().size());
      assertTrue(serviceResponse instanceof RetrieveBillingServiceResponse);
      assertFalse(serviceResponse.getMessages().isEmpty());
      assertEquals("200", serviceResponse.getMessages().get(0).getMessageCode());
      assertEquals("Service completed successfully", serviceResponse.getMessages().get(0).getMessageText());
      assertEquals(MessageTypeEnum.MESSAGE_TYPE_INFO, serviceResponse.getMessages().get(0).getMessageType());     
  
      // Testing OR condition (404 status code)
      message.setMessageCode("404");
      message.setMessageText("request not found");
      message.setMessageType(MessageTypeEnum.MESSAGE_TYPE_INFO);
  
      response.setMessages(Arrays.asList(message));
      serviceResponse = postProcessFilter.postProcess(response, clientResponse);
  
      assertNotNull(serviceResponse.getMessages());
      assertFalse(serviceResponse.getMessages().isEmpty());
      assertEquals(1, serviceResponse.getMessages().size());
      assertEquals("404", serviceResponse.getMessages().get(0).getMessageCode());
      assertEquals("request not found", serviceResponse.getMessages().get(0).getMessageText());
      assertEquals(MessageTypeEnum.MESSAGE_TYPE_INFO, serviceResponse.getMessages().get(0).getMessageType());     
  
      /**
       * Testing AND condition
       * Catching EISClientException
       */
      boolean caughtException = false;
      try {
          postProcessFilter.setCondition(ConditionOperator.AND);
  
          List&lt;String&gt; myMessages = new ArrayList&lt;String&gt;();
          myMessages.add("200");
          myMessages.add("400");
  
          serviceResponse = postProcessFilter.postProcess(response, clientResponse);
  
          assertNotNull(serviceResponse.getMessages());
          assertEquals("400", postProcessFilter.getMessageCodes());
  
      } catch (EISClientException ex) {
          caughtException = true;
          assertEquals("All of the specified message codes matched returned errors.", ex.getMessage());
      }
      assertTrue(caughtException);
  
      // Null messages
      postProcessFilter.setCondition(ConditionOperator.OR);
  
      List&lt;Message&gt; myList = new ArrayList&lt;Message&gt;();
      message.setMessageCode(null);
  
      serviceResponse = postProcessFilter.postProcess(response, clientResponse);
  
      assertEquals(0, myList.size());
      assertEquals(null, serviceResponse.getMessages().get(0).getMessageCode());
  }   
  </code></pre>
  
  <p>I am unable to cover the if statement for message == null || message.size ==0</p>
  
  <p>Any help would highly be appreciated. This should be simple for message not to be null and my existing code should have covered it but I am not sure what I am doing wrong?</p>
  
  <p>Thanks</p>