You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestDboTest.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package com.luticate.utils;
  2. import org.json.JSONException;
  3. import org.junit.Test;
  4. import static org.junit.Assert.*;
  5. /**
  6. * Created by robin on 10/20/16.
  7. */
  8. public class TestDboTest {
  9. @Test
  10. public void deserializeTest() throws Exception {
  11. TestDbo test = new TestDbo();
  12. test.fromString("{" +
  13. "\"byte\": 42," +
  14. "\"char\": \"h\"," +
  15. "\"short\": 4200," +
  16. "\"int\": 420042," +
  17. "\"long\": 42004200," +
  18. "\"float\": 42.24," +
  19. "\"double\": 4200.0024," +
  20. "\"boolean\": true," +
  21. "\"byteObject\": 24," +
  22. "\"charObject\": \"w\"," +
  23. "\"shortObject\": 2400," +
  24. "\"intObject\": 240024," +
  25. "\"longObject\": 24002400," +
  26. "\"floatObject\": 24.42," +
  27. "\"doubleObject\": 2400.0042," +
  28. "\"booleanObject\": false," +
  29. "\"string\": \"Hello World!\"," +
  30. "\"test2Dbo\": {" +
  31. "\"aString\": \"a string\"," +
  32. "\"aInt\": 4242" +
  33. "}," +
  34. "\"integers\": [" +
  35. "0," +
  36. "42," +
  37. "24" +
  38. "]," +
  39. "ints: [" +
  40. "24," +
  41. "42," +
  42. "0" +
  43. "]," +
  44. "test2Dbos: [" +
  45. "{" +
  46. "\"aString\": \"42 42\"," +
  47. "\"aInt\": 4242" +
  48. "}" +
  49. "]," +
  50. "dbos: [" +
  51. "{" +
  52. "\"aString\": \"24 24\"," +
  53. "\"aInt\": 2424" +
  54. "}" +
  55. "]," +
  56. "\"hashMap\": {" +
  57. "\"forty-two\": 42," +
  58. "\"twenty-four\": 24" +
  59. "}," +
  60. "\"hashMap2\": {" +
  61. "\"an object\": {" +
  62. "\"aString\": \"42 24\"," +
  63. "\"aInt\": 4224" +
  64. "}" +
  65. "}" +
  66. "}");
  67. assertEquals(42, test.getByte());
  68. assertEquals(24, test.getByteObject().byteValue());
  69. assertEquals('h', test.getChar());
  70. assertEquals('w', test.getCharObject().charValue());
  71. assertEquals(4200, test.getShort());
  72. assertEquals(2400, test.getShortObject().shortValue());
  73. assertEquals(420042, test.getInt());
  74. assertEquals(240024, test.getIntObject().intValue());
  75. assertEquals(42004200, test.getLong());
  76. assertEquals(24002400, test.getLongObject().longValue());
  77. assertEquals(42.24, test.getFloat(), 0.1);
  78. assertEquals(24.42, test.getFloatObject(), 0.1);
  79. assertEquals(4200.0024, test.getDouble(), 0.1);
  80. assertEquals(2400.0042, test.getDoubleObject(), 0.1);
  81. assertEquals(true, test.isBoolean());
  82. assertEquals(false, test.getBooleanObject());
  83. assertEquals("Hello World!", test.getString());
  84. assertNotNull(test.getTest2Dbo());
  85. assertEquals("a string", test.getTest2Dbo().getaString());
  86. assertEquals(4242, test.getTest2Dbo().getaInt());
  87. assertNull(test.getTest2Dbo2());
  88. assertNotNull(test.getIntegers());
  89. assertEquals(3, test.getIntegers().size());
  90. assertEquals(0, test.getIntegers().get(0).intValue());
  91. assertEquals(42, test.getIntegers().get(1).intValue());
  92. assertEquals(24, test.getIntegers().get(2).intValue());
  93. assertNotNull(test.getInts());
  94. assertEquals(3, test.getInts().length);
  95. assertEquals(24, test.getInts()[0]);
  96. assertEquals(42, test.getInts()[1]);
  97. assertEquals(0, test.getInts()[2]);
  98. assertNotNull(test.getTest2Dbos());
  99. assertEquals(1, test.getTest2Dbos().size());
  100. assertNotNull(test.getTest2Dbos().get(0));
  101. assertEquals("42 42", test.getTest2Dbos().get(0).getaString());
  102. assertEquals(4242, test.getTest2Dbos().get(0).getaInt());
  103. assertNotNull(test.getDbos());
  104. assertEquals(1, test.getDbos().length);
  105. assertNotNull(test.getDbos()[0]);
  106. assertEquals("24 24", test.getDbos()[0].getaString());
  107. assertEquals(2424, test.getDbos()[0].getaInt());
  108. assertNotNull(test.getHashMap());
  109. assertEquals(2, test.getHashMap().size());
  110. assertTrue(test.getHashMap().containsKey("forty-two"));
  111. assertEquals(42, (int)test.getHashMap().get("forty-two"));
  112. assertTrue(test.getHashMap().containsKey("twenty-four"));
  113. assertEquals(24, (int)test.getHashMap().get("twenty-four"));
  114. assertNotNull(test.getHashMap2());
  115. assertEquals(1, test.getHashMap2().size());
  116. assertTrue(test.getHashMap2().containsKey("an object"));
  117. assertNotNull(test.getHashMap2().get("an object"));
  118. assertEquals("42 24", test.getHashMap2().get("an object").getaString());
  119. assertEquals(4224, test.getHashMap2().get("an object").getaInt());
  120. }
  121. @Test
  122. public void serializeTest()
  123. {
  124. Test2Dbo dbo = new Test2Dbo();
  125. dbo.setaInt(2442);
  126. dbo.setaString("24 42");
  127. }
  128. }