-1

I am trying to add a unit test case which involves this code:

try(InputStream zippedInputStream = attachmentReader.getPayloadStream(dP)){
  <some code>
 } catch(Exception t) {
            Throwables.propagate(t);
 }

Please help me in writing a mockito for this.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
Rammy
  • 1
  • Maybe meet your issue [https://stackoverflow.com/questions/31423643/try-catch-in-a-junit-test](https://stackoverflow.com/questions/31423643/try-catch-in-a-junit-test) – ThanhTranIT Jul 21 '17 at 07:27

1 Answers1

0

Your production code does:

  • fetch a stream from a reader
  • throw a runtime exception

So for your test, you will need

  • a mocked attachmentReader thing (which gets passed to your production code)
  • that mock is configured to return an InputStream
  • and in turn, that stream is configured so that the production code does certain things

From there: you write at least two tests, one for the good path; and one where you configure your stream to throw - so that you can put up @Test(expected=RuntimeException.class) .

GhostCat
  • 137,827
  • 25
  • 176
  • 248