2
2
3
3
import org .junit .jupiter .api .Test ;
4
4
import static org .junit .jupiter .api .Assertions .assertEquals ;
5
+ import static org .junit .jupiter .api .Assertions .assertNull ;
5
6
import static org .junit .jupiter .api .Assertions .assertThrows ;
6
7
7
8
@@ -14,6 +15,7 @@ public class Main {
14
15
static native String concat (String a , String b );
15
16
static native String [] to_vec (String a , String b , String c );
16
17
static native boolean maybe (String optional );
18
+ static native String optional (boolean present );
17
19
static native String raw ();
18
20
19
21
@ Test
@@ -29,9 +31,9 @@ public void argumentsByReference() {
29
31
@ Test
30
32
public void checksForNull () {
31
33
// TODO maybe these should throw NullPtrException
32
- assertThrows (RuntimeException .class , () -> Main .concat ("a" , null ));
33
- assertThrows (RuntimeException .class , () -> Main .concat (null , "a" ));
34
- assertThrows (RuntimeException .class , () -> Main .concat (null , null ));
34
+ assertThrows (NullPointerException .class , () -> Main .concat ("a" , null ));
35
+ assertThrows (NullPointerException .class , () -> Main .concat (null , "a" ));
36
+ assertThrows (NullPointerException .class , () -> Main .concat (null , null ));
35
37
}
36
38
37
39
@ Test
@@ -53,5 +55,11 @@ public void optional() {
53
55
public void passEnv () {
54
56
assertEquals (Main .raw (), "hello world!" );
55
57
}
58
+
59
+ @ Test
60
+ public void nullableReturn () {
61
+ assertNull (Main .optional (false ));
62
+ assertEquals (Main .optional (true ), "hello world!" );
63
+ }
56
64
57
65
}
0 commit comments