Latest Questions tagged Junit

Browse all latest questions tagged Junit

Published 07 Sep, 2022
Java - Mocking Logger and LoggerFactory with PowerMock and Mockito

I have the following Logger I want to mock out, but to validate log entries are getting called, not for the content. private static Logger logger = LoggerFactory.getLogger(GoodbyeController....

Published 16 Sep, 2022
Java - org.mockito.exceptions.base.MockitoException: Please ensure that the type 'UserRestService' has a no-arg constructor

I want to create JUnit5 tests for Rest API. @Test public void resetRequest_NAME_AND_EMAIL_MISMATCH() throws Exception { when(userRestService.resetRequest(anyString(), anyString())).thenReturn(Boo...

Published 06 Sep, 2022
Java - Mockito - NullpointerException when stubbing Method

So I started writing tests for our Java-Spring-project. What I use is JUnit and Mockito. It's said, that when I use the when()...thenReturn() option I can mock services, without simulating them or s...

Published 12 Oct, 2022
Java - How to test whether the object has been modified using Junit?

I have a method. void (Item item) { } I want to test in Junit whether item has been modified or not. Can some one tell me how do I do that ?

Published 15 Sep, 2022
Java - Run single test from a JUnit class using command-line

I am trying to find an approach that will allow me to run a single test from a JUnit class using only command-line and java. I can run the whole set of tests from the class using the following: java...

Published 02 Oct, 2022
Java - Mockito: multiple calls to mocked UriBuilder keep appending to original URI

I am currently writing some unit tests for legacy code in a rest api application. One particular api call generates a list of URIs using the UriInfo api from Jax-RS. When I mock this interface, I am a...

Published 17 Oct, 2022
Java - Unsupported major.minor version 52.0 for when running junit

I'm using eclipse to run my tests with: right click test method -> Run As -> JUnit Test. This results in the following error: java.lang.UnsupportedClassVersionError: com/bazaarvoice/jolt/JsonUtils :...

Published 06 Oct, 2022
Java - Mock JWT Utils to validate Token

I want to create JUnkt test for this endpoint: @Autowired private JwtTokenProvider jwtTokenProvider; @PostMapping("reset_token") public ResponseEntity<?> resetToken(@V...

Published 07 Sep, 2022
Java - Intellij test run history

What I miss the most in IntelliJ compared to Eclipse is the test run history window. Does anything like this exist in IntelliJ? I didn't find it anywhere so far and have looked a few times at least....

Published 03 Sep, 2022
Java - Skip execution of a line using Mockito

I am using mockito for unit testing and I want to skip a line. // method I am testing public String doSomeTask(String src, String dst) { // some code utils.createLink(src,dst); // some...

Published 30 Sep, 2022
Java - ResourceAccessException: I/O error on POST request

I have a service method. The method is accessing a third-party resource through a POST request. I am writing a test and I see an error in the logs. Service: @Override public void sendDoc(String id) t...

Published 29 Aug, 2022
Java - Selenium Close File Picker Dialog

We are using Selenium-Webdriver on Jenkins box (running linux), to drive Firefox for testing a fairly complex web app. The web app requires the uploading of a photo for testing, and we have achieved...

Published 20 Aug, 2022
Java - Meaning of delta or epsilon argument of assertEquals for double values

I have a question about JUnit assertEquals to test double values. Reading the API doc I can see: @Deprecated public static void assertEquals(double expected, double actual) Deprecated. Use assertEqu...

Published 05 Sep, 2022
Java - How do I test a class that has private methods, fields or inner classes?

How do I use JUnit to test a class that has internal private methods, fields or nested classes? It seems bad to change the access modifier for a method just to be able to run a test.

Published 02 Sep, 2022
Java - How to create a Bundle in a Unit test

I want to test a method that deals with Bundles. I'm unable to create a (non-null) Bundle object in the test environment, though. Given the following code: Bundle bundle = new Bundle(); bundle.putSt...