-
Notifications
You must be signed in to change notification settings - Fork 1k
/
ExpectedExceptionsTest.java
58 lines (51 loc) · 1.97 KB
/
ExpectedExceptionsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package test.expectedexceptions;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collection;
import java.util.List;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.TestNG;
import org.testng.annotations.Test;
import org.testng.internal.ExitCode;
import test.BaseTest;
import test.expectedexceptions.issue2788.TestClassSample;
import test.expectedexceptions.issue2788.TestClassSample.Local;
public class ExpectedExceptionsTest extends BaseTest {
@Test
public void expectedExceptionsDeprecatedSyntax() {
runTest(
"test.expectedexceptions.SampleExceptions",
new String[] {"shouldPass"},
new String[] {"shouldFail1", "shouldFail2", "shouldFail3"},
new String[] {});
}
@Test(description = "GITHUB-2788")
public void expectedExceptionsWithProperStatusPassedToListener() {
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] {TestClassSample.class});
testng.run();
assertThat(testng.getStatus()).isEqualTo(ExitCode.FAILED);
assertThat(Local.getInstance().isPass()).isFalse();
}
@Test
public void expectedExceptions() {
runTest(
"test.expectedexceptions.SampleExceptions2",
new String[] {"shouldPass", "shouldPass2", "shouldPass3", "shouldPass4"},
new String[] {"shouldFail1", "shouldFail2", "shouldFail3", "shouldFail4"},
new String[] {});
}
@Test
public void expectedExceptionsMessage() {
getFailedTests().clear();
addClass(test.expectedexceptions.github1409.TestClassSample.class);
run();
Collection<List<ITestResult>> failedTests = getFailedTests().values();
Assert.assertFalse(failedTests.isEmpty());
ITestResult result = failedTests.iterator().next().get(0);
String actual = result.getThrowable().getMessage().replaceAll("\\n", "");
String expected =
"The exception was thrown with the wrong message: expected \"expected\" but got \"actual\"";
Assert.assertEquals(actual, expected);
}
}