All Questions
248 questions
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&...
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....
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) {
...
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 ...
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() {
// ...
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 ...
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....
-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 ...
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 ...
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?
...
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",&...
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....
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, ...
-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 ...
-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 ...