Skip to main content

All Questions

Tagged with
1 vote
2 answers
83 views

Why ExceptionHandler does not work with junit?

I am having trouble to test a controller class with @ExceptionHandler annotation. At first, my controller was like this : @RestController @RequestMapping("/api/user") @Tag(name = "User&...
Enialix's user avatar
  • 21
0 votes
0 answers
45 views

Exception not getting translated

I have a method that makes a HTTP call like so: public String executeRequest(HttpRequest request) { try { return httpResourceProvider.getHttpClient() .send(request, HttpResponse....
ritratt's user avatar
  • 1,868
0 votes
1 answer
182 views

Why can't I catch ElementClickInterceptedException exception in Selenide, but can catch it with Throwable?

I have a section of code that looks like this in my Java + Selenide + JUnit project: for (int retries = 3; !menuItem.is(visible); --retries) { if (retries < 1) { ...
afar's user avatar
  • 1
2 votes
2 answers
3k views

How to verify that exception was thrown by a mock when it was caught within the code under test?

In Java/Junit/Mockito, it is fairly easy to simulate an exception (doThrow() etc.), and fairly easy to verify when an exception is thrown and not caught (assertThrows() etc.). But what if exception ...
Alexander's user avatar
  • 803
0 votes
1 answer
53 views

How to properly test a compareTo() method with custom exceptions in Java?

Having problems testing a compareTo() method with custom exception. How do I throw a custom exception without compilation error? Code of the Junit test @Test public void compareTo() { // ...
Future Hendrixxx's user avatar
0 votes
1 answer
81 views

JUnit checking if the message thrown by an exception is either `stringA` or `stringB`

In my code I have some pattern like (I tried to simplified as much as possible): import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import java.util.Set; public void ...
mahb's user avatar
  • 59
1 vote
0 answers
108 views

How to mock IOException for CharSource.read()?

here is the code for which I want to write a test case for catch block public class X { protected String getInputString(final String inputPath) { try { return Resources....
Neha Bhoi's user avatar
  • 161
-1 votes
1 answer
292 views

Junit-Expected MalformedURLException but got UndeclaredThrowableException

I have a class ServerConnection.java which have below methods private String getUrl() throws MalformedURLException { // some operations and condition URL url = getDNSBasedUrl(); } public ...
Sumit Kumar's user avatar
1 vote
0 answers
307 views

Exception is thrown with Mockito but it is not caught in JUnit

I have a problem with a test case and cannot pass through it, tried to change some things but in any case the result is the same. I am pretty new to Mockito and to this kind of tests - so cannot ...
seened's user avatar
  • 43
0 votes
2 answers
326 views

Use a non-mandatory Exception to cause succeed on a junit test in java

I'm looking for a way to cause a succeed through an custom exception without expecting it all the time in junit4. Is this possible with a testrule or something, without touching every single testcase? ...
Akreter's user avatar
  • 35
1 vote
0 answers
107 views

ExceptionInInitializerError while JUnit testing

Hello I am testing method createReservation from the model @org.junit.jupiter.api.Test void createReservation() { modelManager.createReservation(new Reservation(new Item(1232,"title",&...
Babovnik's user avatar
0 votes
2 answers
4k views

JUnit 5 assertThrows() ignores thrown exception

My assertThrows fails, reading some other stackoverflows, it seems to be that my try catches within the methods handle the thrown exception, so I do understand that's why it does not assertThrows=true....
Ryan Reddy's user avatar
1 vote
1 answer
140 views

Junit is not getting custom exception

I am trying to test a custom exception in junit test but it is not getting it. Here is the method that I created public String Validate(Student obj) throws NullStudentObjectException, ...
the_razz03's user avatar
-1 votes
2 answers
1k views

How to avoid adding empty username and password to my database?

When i try testing my add user method with an empty username and password. It still adds the users to my database without username and password. How can i check if my username || password is empty? I ...
Sycan's user avatar
  • 47
-1 votes
1 answer
876 views

Check if an exception was thrown and continue after the exception was thrown

I want to make a test that reads from a file some data and passes that data to a function. That function calls other methods and some of them throw some exceptions. I'm interested in how can I check ...
ggtr's user avatar
  • 1

15 30 50 per page
1
2 3 4 5
17