Skip to content

Commit 0489091

Browse files
author
Pankaj Kumar
committed
JUnit Assert Exception example
1 parent 4a028ba commit 0489091

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.journaldev.exceptions;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class JUnit5TestExceptions {
8+
9+
@Test
10+
void test() {
11+
String str = null;
12+
assertThrows(NullPointerException.class, () -> str.length());
13+
14+
Foo foo = new Foo();
15+
Exception exception = assertThrows(Exception.class, () -> foo.foo());
16+
assertEquals("Exception Message", exception.getMessage());
17+
}
18+
19+
}
20+
21+
class Foo {
22+
void foo() throws Exception {
23+
throw new Exception("Exception Message");
24+
}
25+
}

0 commit comments

Comments
 (0)