1
1
package dev .latvian .apps .json .test ;
2
2
3
- import dev .latvian .apps .ansi .ObjectANSI ;
3
+ import dev .latvian .apps .ansi .JavaANSI ;
4
4
import dev .latvian .apps .ansi .log .Log ;
5
5
import dev .latvian .apps .json .JSON ;
6
6
import dev .latvian .apps .json .JSONObject ;
7
7
import org .junit .jupiter .api .Assertions ;
8
8
import org .junit .jupiter .api .Test ;
9
9
10
+ import java .util .Arrays ;
10
11
import java .util .List ;
11
12
import java .util .Optional ;
12
13
@@ -30,26 +31,28 @@ public void deserialize() {
30
31
@ Test
31
32
public void adapt () {
32
33
var config = JSON .DEFAULT .read ("""
33
- {"database":"https://lat:[email protected] :1234/","discord":[{"clientId":"7"}]}""" ).
adapt (
TestConfig .
class );
34
+ {"web":{"required":true,"ids":[1, 2, 3]}," database":"https://lat:[email protected] :1234/","discord":[{"clientId":"7"}]}""" ).
adapt (
TestConfig .
class );
34
35
35
36
Assertions .
assertEquals (
config .
database .
toString (),
"https://lat:[email protected] :1234/" );
36
37
Assertions .assertEquals (config .discord [0 ].clientId , "7" );
37
38
Assertions .assertEquals (config .discord [0 ].clientSecret , "shh" );
39
+ Assertions .assertTrue (config .web .required );
40
+ Assertions .assertEquals (Arrays .toString (config .web .ids ), Arrays .toString (new long []{1L , 2L , 3L }));
38
41
}
39
42
40
43
@ Test
41
44
public void readRemoteObject () {
42
45
// {"hours":672,"total_launches":7864423,"hourly":11700.028795489174,"ml":[{"ml":1,"fraction":0.9412095458242773,"launches":7402070},{"ml":2,"fraction":0.05879045417572275,"launches":462353}],"mc":[{"mc":2001,"fraction":0.6443314404629558,"launches":5067295},{"mc":1902,"fraction":0.3556624561013567,"launches":2797080},{"mc":2004,"fraction":6.103435687525964E-6,"launches":48}],"mlmc":[{"ml":1,"mc":2001,"fraction":0.6154869848684386,"launches":4840450},{"ml":1,"mc":1902,"fraction":0.3257164575201512,"launches":2561572},{"ml":2,"mc":1902,"fraction":0.029945998581205512,"launches":235508},{"ml":2,"mc":2001,"fraction":0.028844455594517232,"launches":226845},{"ml":1,"mc":2004,"fraction":6.103435687525964E-6,"launches":48}],"launches":[{"version":"2001.6.4-build.114","fraction":0.26559062247796184,"launches":2088717},{"version":"2001.6.4-build.120","fraction":0.21153312836809515,"launches":1663586},{"version":"1902.6.2-build.45","fraction":0.1828411315108559,"launches":1437940},{"version":"2001.6.4-build.127","fraction":0.0810527358459737,"launches":637433},{"version":"1902.6.2-build.3","fraction":0.038601560470488426,"launches":303579},{"version":"2001.6.4-build.95","fraction":0.03645264248883866,"launches":286679},{"version":"1902.6.2-build.15","fraction":0.02442060911525232,"launches":192054},{"version":"1902.6.2-build.50","fraction":0.018523800156731142,"launches":145679},{"version":"2001.6.3-build.83","fraction":0.018382658206457105,"launches":144569},{"version":"1902.6.2-build.27","fraction":0.01564005394928528,"launches":123000},{"version":"","fraction":1.3987040117246999E-6,"launches":11}]}
43
46
var content = "{\" hours\" :672,\" total_launches\" :7864423,\" hourly\" :11700.028795489174,\" ml\" :[{\" ml\" :1,\" fraction\" :0.9412095458242773,\" launches\" :7402070},{\" ml\" :2,\" fraction\" :0.05879045417572275,\" launches\" :462353}],\" mc\" :[{\" mc\" :2001,\" fraction\" :0.6443314404629558,\" launches\" :5067295},{\" mc\" :1902,\" fraction\" :0.3556624561013567,\" launches\" :2797080},{\" mc\" :2004,\" fraction\" :6.103435687525964E-6,\" launches\" :48}],\" mlmc\" :[{\" ml\" :1,\" mc\" :2001,\" fraction\" :0.6154869848684386,\" launches\" :4840450},{\" ml\" :1,\" mc\" :1902,\" fraction\" :0.3257164575201512,\" launches\" :2561572},{\" ml\" :2,\" mc\" :1902,\" fraction\" :0.029945998581205512,\" launches\" :235508},{\" ml\" :2,\" mc\" :2001,\" fraction\" :0.028844455594517232,\" launches\" :226845},{\" ml\" :1,\" mc\" :2004,\" fraction\" :6.103435687525964E-6,\" launches\" :48}],\" launches\" :[{\" version\" :\" 2001.6.4-build.114\" ,\" fraction\" :0.26559062247796184,\" launches\" :2088717},{\" version\" :\" 2001.6.4-build.120\" ,\" fraction\" :0.21153312836809515,\" launches\" :1663586},{\" version\" :\" 1902.6.2-build.45\" ,\" fraction\" :0.1828411315108559,\" launches\" :1437940},{\" version\" :\" 2001.6.4-build.127\" ,\" fraction\" :0.0810527358459737,\" launches\" :637433},{\" version\" :\" 1902.6.2-build.3\" ,\" fraction\" :0.038601560470488426,\" launches\" :303579},{\" version\" :\" 2001.6.4-build.95\" ,\" fraction\" :0.03645264248883866,\" launches\" :286679},{\" version\" :\" 1902.6.2-build.15\" ,\" fraction\" :0.02442060911525232,\" launches\" :192054},{\" version\" :\" 1902.6.2-build.50\" ,\" fraction\" :0.018523800156731142,\" launches\" :145679},{\" version\" :\" 2001.6.3-build.83\" ,\" fraction\" :0.018382658206457105,\" launches\" :144569},{\" version\" :\" 1902.6.2-build.27\" ,\" fraction\" :0.01564005394928528,\" launches\" :123000},{\" version\" :\" \" ,\" fraction\" :1.3987040117246999E-6,\" launches\" :11}]}" ;
44
- Log .OUT . info (content );
47
+ Log .info (content );
45
48
var json = JSON .DEFAULT .read (content ).readObject ();
46
49
json .removeDeep ((key , index , value ) -> key .equals ("fraction" ) && ((Number ) value ).doubleValue () < 0.5D , true );
47
50
48
- Log .OUT . info (ObjectANSI . ofObject (json ));
49
- Log .OUT . info (JSON .DEFAULT .writePretty (json ));
51
+ Log .info (JavaANSI . of (json ));
52
+ Log .info (JSON .DEFAULT .writePretty (json ));
50
53
51
- Log .OUT . info (json .asInt ("total_launches" ));
52
- Log .OUT . info (json .asDouble ("hourly" ));
54
+ Log .info (json .asInt ("total_launches" ));
55
+ Log .info (json .asDouble ("hourly" ));
53
56
}
54
57
55
58
@ Test
@@ -61,14 +64,14 @@ public void record() {
61
64
)));
62
65
63
66
var str = JSON .DEFAULT .write (r );
64
- Log .OUT . info (r );
65
- Log .OUT . info (str );
67
+ Log .info (r );
68
+ Log .info (str );
66
69
67
70
var r2 = JSON .DEFAULT .read (str ).adapt (RecordTest .class );
68
71
var str2 = JSON .DEFAULT .write (r2 );
69
72
70
- Log .OUT . info (r2 );
71
- Log .OUT . info (str2 );
73
+ Log .info (r2 );
74
+ Log .info (str2 );
72
75
73
76
Assertions .assertEquals (str , str2 );
74
77
}
0 commit comments