Checking for 2 exepcted values in Junit

Posted by Swift-Tuttle on Stack Overflow See other posts from Stack Overflow or by Swift-Tuttle
Published on 2011-01-12T10:51:10Z Indexed on 2011/01/12 10:53 UTC
Read the original article Hit count: 205

Filed under:
|

Hi,
I have a java program which throws an exception with 2 different messages for 2 different scenarios and I want the Junit test case to check for equality for both of these messages. As an example -

public void amethod() {
           // do some processing
        if(scenario1 == true) {
            throw new MySystemException("An error occured due to case 1 being incorrect.");
        }
        else if(scenario2 == true) {
            throw new MySystemException("An error occured as case 2 could not be found");
        }
    }  

Now the JUnit for this would be something like-

public void testAMethod() {
    // do something
    assertEquals("Expected", "Actual");
}

As I understand, in this above example, if I use the Scenario1 exception message the junit will fail when an exception is thrown for Scenario2 and vice versa.
I would like to know if there is any other way provided in Junit by which I can use this one test method and check for both the messages for the test to pass?
Something like an OR, if possible to provide the "Expected" value with both these expected message.
I hope my query is clear enough.

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about junit