/src/test/java/com/alibaba/json/bvt/parser/deser/StackTraceElementDeserializerTest.java

https://github.com/alibaba/fastjson · Java · 145 lines · 124 code · 21 blank · 0 comment · 0 complexity · b27126ddc3875eb4e12b37fab2a6be4b MD5 · raw file

  1. package com.alibaba.json.bvt.parser.deser;
  2. import org.junit.Assert;
  3. import junit.framework.TestCase;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONException;
  6. public class StackTraceElementDeserializerTest extends TestCase {
  7. public void test_stack() throws Exception {
  8. Assert.assertNull(JSON.parseObject("null", StackTraceElement.class));
  9. Assert.assertNull(JSON.parseArray("null", StackTraceElement.class));
  10. Assert.assertNull(JSON.parseArray("[null]", StackTraceElement.class).get(0));
  11. Assert.assertNull(JSON.parseObject("{\"value\":null}", VO.class).getValue());
  12. Assert.assertNull(JSON.parseObject("{\"className\":\"int\",\"methodName\":\"parseInt\"}",
  13. StackTraceElement.class).getFileName());
  14. Assert.assertEquals(StackTraceElement.class, ((StackTraceElement) JSON.parse("{\"@type\":\"java.lang.StackTraceElement\",\"className\":\"int\",\"methodName\":\"parseInt\",\"nativeMethod\":null}")).getClass());
  15. }
  16. public void test_stack_error() throws Exception {
  17. Exception error = null;
  18. try {
  19. JSON.parseObject("{}", StackTraceElement.class);
  20. } catch (JSONException ex) {
  21. error = ex;
  22. }
  23. Assert.assertNotNull(error);
  24. }
  25. public void test_stack_error_1() throws Exception {
  26. Exception error = null;
  27. try {
  28. JSON.parseObject("[]", StackTraceElement.class);
  29. } catch (JSONException ex) {
  30. error = ex;
  31. }
  32. Assert.assertNotNull(error);
  33. }
  34. public void test_stack_error_2() throws Exception {
  35. Exception error = null;
  36. try {
  37. JSON.parseObject("{\"className\":null,\"methodName\":null,\"fileName\":null,\"lineNumber\":null,\"@type\":\"xxx\"}", StackTraceElement.class);
  38. } catch (JSONException ex) {
  39. error = ex;
  40. }
  41. Assert.assertNotNull(error);
  42. }
  43. public void test_stack_error_3() throws Exception {
  44. Exception error = null;
  45. try {
  46. JSON.parseObject("{\"@type\":int}", StackTraceElement.class);
  47. } catch (JSONException ex) {
  48. error = ex;
  49. }
  50. Assert.assertNotNull(error);
  51. }
  52. public void test_stack_error_4() throws Exception {
  53. Exception error = null;
  54. try {
  55. JSON.parseObject("{\"xxx\":33}", StackTraceElement.class);
  56. } catch (JSONException ex) {
  57. error = ex;
  58. }
  59. Assert.assertNotNull(error);
  60. }
  61. public void test_stack_error_5() throws Exception {
  62. Exception error = null;
  63. try {
  64. JSON.parseObject("{\"nativeMethod\":33}", StackTraceElement.class);
  65. } catch (JSONException ex) {
  66. error = ex;
  67. }
  68. Assert.assertNotNull(error);
  69. }
  70. public void test_stack_error_6() throws Exception {
  71. Exception error = null;
  72. try {
  73. JSON.parseObject("{\"lineNumber\":33}", StackTraceElement.class);
  74. } catch (JSONException ex) {
  75. error = ex;
  76. }
  77. Assert.assertNotNull(error);
  78. }
  79. public void test_stack_error_7() throws Exception {
  80. Exception error = null;
  81. try {
  82. JSON.parseObject("{\"fileName\":33}", StackTraceElement.class);
  83. } catch (JSONException ex) {
  84. error = ex;
  85. }
  86. Assert.assertNotNull(error);
  87. }
  88. public void test_stack_error_8() throws Exception {
  89. Exception error = null;
  90. try {
  91. JSON.parseObject("{\"methodName\":33}", StackTraceElement.class);
  92. } catch (JSONException ex) {
  93. error = ex;
  94. }
  95. Assert.assertNotNull(error);
  96. }
  97. public void test_stack_error_9() throws Exception {
  98. Exception error = null;
  99. try {
  100. JSON.parseObject("{\"className\":33}", StackTraceElement.class);
  101. } catch (JSONException ex) {
  102. error = ex;
  103. }
  104. Assert.assertNotNull(error);
  105. }
  106. public void test_stack_error_10() throws Exception {
  107. Exception error = null;
  108. try {
  109. JSON.parseObject("{\"lineNumber\":true}", StackTraceElement.class);
  110. } catch (JSONException ex) {
  111. error = ex;
  112. }
  113. Assert.assertNotNull(error);
  114. }
  115. public static class VO {
  116. private StackTraceElement value;
  117. public StackTraceElement getValue() {
  118. return value;
  119. }
  120. public void setValue(StackTraceElement value) {
  121. this.value = value;
  122. }
  123. }
  124. }