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 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. "\"byteObject\": 24," +
  15. "\"char\": \"h\"," +
  16. "\"charObject\": \"w\"," +
  17. "\"short\": 4200," +
  18. "\"shortObject\": 2400," +
  19. "\"int\": 420042," +
  20. "\"intObject\": 240024," +
  21. "\"long\": 42004200," +
  22. "\"longObject\": 24002400," +
  23. "\"float\": 42.24," +
  24. "\"floatObject\": 24.42," +
  25. "\"double\": 4200.0024," +
  26. "\"doubleObject\": 2400.0042," +
  27. "\"boolean\": true," +
  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. "}");
  57. assertEquals(42, test.getByte());
  58. assertEquals(24, test.getByteObject().byteValue());
  59. assertEquals('h', test.getChar());
  60. assertEquals('w', test.getCharObject().charValue());
  61. assertEquals(4200, test.getShort());
  62. assertEquals(2400, test.getShortObject().shortValue());
  63. assertEquals(420042, test.getInt());
  64. assertEquals(240024, test.getIntObject().intValue());
  65. assertEquals(42004200, test.getLong());
  66. assertEquals(24002400, test.getLongObject().longValue());
  67. assertEquals(42.24, test.getFloat(), 0.1);
  68. assertEquals(24.42, test.getFloatObject(), 0.1);
  69. assertEquals(4200.0024, test.getDouble(), 0.1);
  70. assertEquals(2400.0042, test.getDoubleObject(), 0.1);
  71. assertEquals(true, test.isBoolean());
  72. assertEquals(false, test.getBooleanObject());
  73. assertEquals("Hello World!", test.getString());
  74. assertNotNull(test.getTest2Dbo());
  75. assertEquals("a string", test.getTest2Dbo().getaString());
  76. assertEquals(4242, test.getTest2Dbo().getaInt());
  77. assertNull(test.getTest2Dbo2());
  78. assertNotNull(test.getIntegers());
  79. assertEquals(3, test.getIntegers().size());
  80. assertEquals(0, test.getIntegers().get(0).intValue());
  81. assertEquals(42, test.getIntegers().get(1).intValue());
  82. assertEquals(24, test.getIntegers().get(2).intValue());
  83. assertNotNull(test.getInts());
  84. assertEquals(3, test.getInts().length);
  85. assertEquals(24, test.getInts()[0]);
  86. assertEquals(42, test.getInts()[1]);
  87. assertEquals(0, test.getInts()[2]);
  88. assertNotNull(test.getTest2Dbos());
  89. assertEquals(1, test.getTest2Dbos().size());
  90. assertNotNull(test.getTest2Dbos().get(0));
  91. assertEquals("42 42", test.getTest2Dbos().get(0).getaString());
  92. assertEquals(4242, test.getTest2Dbos().get(0).getaInt());
  93. assertNotNull(test.getDbos());
  94. assertEquals(1, test.getDbos().length);
  95. assertNotNull(test.getDbos()[0]);
  96. assertEquals("24 24", test.getDbos()[0].getaString());
  97. assertEquals(2424, test.getDbos()[0].getaInt());
  98. }
  99. }