'PowerMock whenNew Alternative
I don't want to use powermock anymore. Because junit5 started mocking static classes. So i am trying to get rid of powermock methods.
As you know, you can create an instance of a class with whenNew keyword.
Is there any alternative in Junit5 for whenNew?
Here is a part of my code:
whenNew(PDFDocument.class).withNoArguments().thenReturn(pdfDocument);
whenNew(PSConverter.class).withNoArguments().thenReturn(converter);
doNothing().when(pdfDocument).load(ArgumentMatchers.any(ByteArrayInputStream.class));
doAnswer(invocationOnMock -> {
ByteArrayOutputStream outputStream = invocationOnMock.getArgument(1);
outputStream.write(content);
return outputStream;
}).when(converter).convert(ArgumentMatchers.any(), ArgumentMatchers.any(ByteArrayOutputStream.class));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
