--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/9e6198c4-65f5-4c51-8eab-47680228a271%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Do you mean that in your code under test, you have the described line, and you want your test to result in the InputStream being passed to be a mock object under your control?
This is one of those things that Mockito can’t do. You’d have to use PowerMock(ito) for this.
--
public synchronized void setInputStream(InputStream is) {br = new BufferedReader(new InputStreamReader(is));notify();}
public synchronized void setInputStream(InputStream is) {
br = createBufferedReaderFromInputStream(is);notify();}BufferedReader createBufferedReaderFromInputStream(InputStream is) {return new BufferedReader(new InputStreamReader(is));}
@Mock InputStream mockStream;
@Mock BufferedStreamReader mockReader;...StreamReaderThread thread = spy(new StreamReaderThread(...));
doReturn(mockReader).when(thread).createBufferedReaderFromInputStream(mockStream);
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/a49b336d-4b25-4a99-a2f5-9926527ca30b%40googlegroups.com.
Why would you like to mock InputStream and not some real implementation?
There is a rule said by wise guys: "do not mock types you don't own". It works for me. Those wise guys wrote a book you should probably read: Growing Object Oriented Software, Guided By Tests. It can be a life changer for you, it was for me... and I used to write code like you just showed.
Remember this: the code can be testable or not. In the second case your tests will look like a monster and they won't pay off. I can see it very often: bad code followed be even worse tests. Most of the time it's better to rip those tests than to maintain them. But, again, everything starts from bad and not testable code.
If you have such a code and you can't change it, skip the unit/integration tests and go straight to e2e.
Regards,
Witold Szczerba
Regards,
Witold Szczerba
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/9e6198c4-65f5-4c51-8eab-47680228a271%40googlegroups.com.