@@ -14,32 +14,41 @@ public class EntrySerializationTest {
1414 void serialize () {
1515 String json = String .format (TEST_JSON , "test" , "1" );
1616 Config config = Utils .gson .fromJson (json , Config .class );
17- String fetchTimeRaw = DateTimeUtils . format ( System .currentTimeMillis () );
18- Entry entry = new Entry (config , "fakeTag" , json , fetchTimeRaw );
17+ long fetchTime = System .currentTimeMillis ();
18+ Entry entry = new Entry (config , "fakeTag" , json , fetchTime );
1919
2020 String serializedString = entry .serialize ();
2121
22- assertEquals (String .format (SERIALIZED_DATA , fetchTimeRaw , "fakeTag" , json ), serializedString );
22+ assertEquals (String .format (SERIALIZED_DATA , fetchTime , "fakeTag" , json ), serializedString );
2323 }
2424
2525 @ Test
26- void deserialize () throws Exception {
26+ void payloadSerializationPlatformIndependent () {
27+ String payloadTestConfigJson = "{\" p\" :{\" u\" :\" https://cdn-global.configcat.com\" ,\" r\" :0},\" f\" :{\" testKey\" :{\" v\" :\" testValue\" ,\" t\" :1,\" p\" :[],\" r\" :[]}}}" ;
28+
29+ Config config = Utils .gson .fromJson (payloadTestConfigJson , Config .class );
30+ Entry entry = new Entry (config , "test-etag" , payloadTestConfigJson , 1686756435844L );
31+ String serializedString = entry .serialize ();
32+
33+ assertEquals ("1686756435844\n test-etag\n " + payloadTestConfigJson , serializedString );
34+ }
35+
36+ @ Test
37+ void deserialize () {
2738 String json = String .format (TEST_JSON , "test" , "1" );
2839 long currentTimeMillis = System .currentTimeMillis ();
29- String fetchTimeRaw = DateTimeUtils .format (currentTimeMillis );
3040
31- Entry entry = Entry .fromString (String .format (SERIALIZED_DATA , fetchTimeRaw , "fakeTag" , json ));
41+ Entry entry = Entry .fromString (String .format (SERIALIZED_DATA , currentTimeMillis , "fakeTag" , json ));
3242
3343 assertNotNull (entry );
34- assertEquals (fetchTimeRaw , entry .getFetchTimeRaw ());
3544 assertEquals ("fakeTag" , entry .getETag ());
3645 assertEquals (json , entry .getConfigJson ());
3746 assertEquals (1 , entry .getConfig ().getEntries ().size ());
38- assertEquals (Math . ceil ( currentTimeMillis / 1000 ) * 1000 , entry .getFetchTime ());
47+ assertEquals (currentTimeMillis , entry .getFetchTime ());
3948 }
4049
4150 @ Test
42- void deserializeMissingValue () throws Exception {
51+ void deserializeMissingValue () {
4352 Entry deserializeNull = Entry .fromString (null );
4453 assertTrue (deserializeNull .isEmpty ());
4554 Entry deserializeEmpty = Entry .fromString ("" );
@@ -65,21 +74,19 @@ void deserializeInvalidDate() {
6574 @ Test
6675 void deserializeInvalidETag () {
6776 long currentTimeMillis = System .currentTimeMillis ();
68- String fetchTimeRaw = DateTimeUtils .format (currentTimeMillis );
69- Exception assertThrows = assertThrows (Exception .class , () -> Entry .fromString (String .format (SERIALIZED_DATA , fetchTimeRaw , "" , "json" )));
77+ Exception assertThrows = assertThrows (Exception .class , () -> Entry .fromString (String .format (SERIALIZED_DATA , currentTimeMillis / 1000 , "" , "json" )));
7078
7179 assertEquals ("Empty eTag value." , assertThrows .getMessage ());
7280 }
7381
7482 @ Test
7583 void deserializeInvalidJson () {
7684 long currentTimeMillis = System .currentTimeMillis ();
77- String fetchTimeRaw = DateTimeUtils .format (currentTimeMillis );
78- Exception assertThrows = assertThrows (Exception .class , () -> Entry .fromString (String .format (SERIALIZED_DATA , fetchTimeRaw , "fakeTag" , "" )));
85+ Exception assertThrows = assertThrows (Exception .class , () -> Entry .fromString (String .format (SERIALIZED_DATA , currentTimeMillis / 1000 , "fakeTag" , "" )));
7986
8087 assertEquals ("Empty config jsom value." , assertThrows .getMessage ());
8188
82- assertThrows = assertThrows (Exception .class , () -> Entry .fromString (String .format (SERIALIZED_DATA , fetchTimeRaw , "fakeTag" , "wrongjson" )));
89+ assertThrows = assertThrows (Exception .class , () -> Entry .fromString (String .format (SERIALIZED_DATA , currentTimeMillis / 1000 , "fakeTag" , "wrongjson" )));
8390
8491 assertEquals ("Invalid config JSON content: wrongjson" , assertThrows .getMessage ());
8592
0 commit comments