1
1
package dev .openfeature .javasdk ;
2
2
3
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
4
5
import static org .junit .jupiter .api .Assertions .assertTrue ;
6
+ import static org .junit .jupiter .api .Assertions .fail ;
5
7
6
8
import java .time .Instant ;
7
9
import java .util .ArrayList ;
@@ -16,9 +18,44 @@ public class ValueTest {
16
18
}
17
19
18
20
@ Test public void objectArgShouldContainObject () {
19
- Object innerValue = new Object ();
20
- Value value = new Value (innerValue );
21
- assertEquals (innerValue , value .asObject ());
21
+ try {
22
+ // int is a special case, see intObjectArgShouldConvertToInt()
23
+ List <Object > list = new ArrayList <>();
24
+ list .add (true );
25
+ list .add ("val" );
26
+ list .add (.5 );
27
+ list .add (new Structure ());
28
+ list .add (new ArrayList <Value >());
29
+ list .add (Instant .now ());
30
+
31
+ int i = 0 ;
32
+ for (Object l : list ) {
33
+ Value value = new Value (l );
34
+ assertEquals (list .get (i ), value .asObject ());
35
+ i ++;
36
+ }
37
+ } catch (Exception e ) {
38
+ fail ("No exception expected." );
39
+ }
40
+ }
41
+
42
+ @ Test public void intObjectArgShouldConvertToInt () {
43
+ try {
44
+ Object innerValue = 1 ;
45
+ Value value = new Value (innerValue );
46
+ assertEquals (innerValue , value .asInteger ());
47
+ } catch (Exception e ) {
48
+ fail ("No exception expected." );
49
+ }
50
+ }
51
+
52
+ @ Test public void invalidObjectArgShouldThrow () {
53
+
54
+ class Something {}
55
+
56
+ assertThrows (InstantiationException .class , () -> {
57
+ new Value (new Something ());
58
+ });
22
59
}
23
60
24
61
@ Test public void boolArgShouldContainBool () {
0 commit comments