title: Junit Testing JAXBContext to throw JAXBException - testing failure scenario using mockito
body: <p>I have a method to test for jaxbexception,There are initial validations before this method so i cannot send invalid request to occur JAXBException. Only way i see is to use MOCKITO, tried it but didn't work for me.</p>
  
  <p>Method to be tested:</p>
  
  <pre><code> private String methodtoBeTested(Object request, Class clazz)
  {
      try
      {
          StringWriter sw = new StringWriter();
          JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
          Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
          jaxbMarshaller.marshal(request, sw);
          return sw.toString();
      }
      catch(JAXBException e)
      {
          LOG.error("jaxbexception encountered" + e.getMessage());
      }
  }
  </code></pre>
  
  <p>So far i tried :</p>
  
  <pre><code>JAXBContext jaxbMock = mock(JAXBContext.class);
      Marshaller marshalmock = mock(Marshaller.class);
      when(jaxbMock.createMarshaller()).thenThrow(JAXBException.class);
  </code></pre>