PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/java/org/yaml/snakeyaml/Chapter2_2Test.java

https://code.google.com/p/snakeyaml/
Java | 113 lines | 83 code | 9 blank | 21 comment | 1 complexity | bb6d57d266fabad290349142325e1044 MD5 | raw file
Possible License(s): Apache-2.0
  1. /**
  2. * Copyright (c) 2008-2014, http://www.snakeyaml.org
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.yaml.snakeyaml;
  17. import java.util.List;
  18. import java.util.Map;
  19. import junit.framework.TestCase;
  20. /**
  21. * Test Chapter 2.2 from the YAML specification
  22. *
  23. * @author py4fun
  24. * @see http://yaml.org/spec/1.1/
  25. */
  26. public class Chapter2_2Test extends TestCase {
  27. @SuppressWarnings("unchecked")
  28. public void testExample_2_7() {
  29. YamlStream resource = new YamlStream("example2_7.yaml");
  30. List<Object> list = (List<Object>) resource.getNativeData();
  31. assertEquals(2, list.size());
  32. List<String> list1 = (List<String>) list.get(0);
  33. assertEquals(3, list1.size());
  34. assertEquals("Mark McGwire", list1.get(0));
  35. assertEquals("Sammy Sosa", list1.get(1));
  36. assertEquals("Ken Griffey", list1.get(2));
  37. List<String> list2 = (List<String>) list.get(1);
  38. assertEquals(2, list2.size());
  39. assertEquals("Chicago Cubs", list2.get(0));
  40. assertEquals("St Louis Cardinals", list2.get(1));
  41. }
  42. @SuppressWarnings("unchecked")
  43. public void testExample_2_8() {
  44. YamlStream resource = new YamlStream("example2_8.yaml");
  45. List<Object> list = (List<Object>) resource.getNativeData();
  46. assertEquals(2, list.size());
  47. Map<String, String> map1 = (Map<String, String>) list.get(0);
  48. assertEquals(3, map1.size());
  49. assertEquals(new Integer(72200), map1.get("time"));
  50. assertEquals("Sammy Sosa", map1.get("player"));
  51. assertEquals("strike (miss)", map1.get("action"));
  52. Map<String, String> map2 = (Map<String, String>) list.get(1);
  53. assertEquals(3, map2.size());
  54. assertEquals(new Integer(72227), map2.get("time"));
  55. assertEquals("Sammy Sosa", map2.get("player"));
  56. assertEquals("grand slam", map2.get("action"));
  57. }
  58. @SuppressWarnings("unchecked")
  59. public void testExample_2_9() {
  60. YamlDocument document = new YamlDocument("example2_9.yaml");
  61. Map<String, Object> map = (Map<String, Object>) document.getNativeData();
  62. assertEquals(map.toString(), 2, map.size());
  63. List<String> list1 = (List<String>) map.get("hr");
  64. assertEquals(2, list1.size());
  65. assertEquals("Mark McGwire", list1.get(0));
  66. assertEquals("Sammy Sosa", list1.get(1));
  67. List<String> list2 = (List<String>) map.get("rbi");
  68. assertEquals(2, list2.size());
  69. assertEquals("Sammy Sosa", list2.get(0));
  70. assertEquals("Ken Griffey", list2.get(1));
  71. }
  72. @SuppressWarnings("unchecked")
  73. public void testExample_2_10() {
  74. YamlDocument document = new YamlDocument("example2_10.yaml");
  75. Map<String, Object> map = (Map<String, Object>) document.getNativeData();
  76. assertEquals("Examples 2.9 and 2.10 must be identical.",
  77. new YamlDocument("example2_9.yaml").getNativeData(), map);
  78. }
  79. @SuppressWarnings("unchecked")
  80. public void testExample_2_11() {
  81. YamlDocument document = new YamlDocument("example2_11.yaml");
  82. Map<Object, Object> map = (Map<Object, Object>) document.getNativeData();
  83. assertEquals(2, map.size());
  84. for (Object key : map.keySet()) {
  85. List<String> list = (List<String>) key;
  86. assertEquals(2, list.size());
  87. }
  88. }
  89. public void testExample_2_12() {
  90. YamlDocument document = new YamlDocument("example2_12.yaml");
  91. @SuppressWarnings("unchecked")
  92. List<Map<Object, Object>> list = (List<Map<Object, Object>>) document.getNativeData();
  93. assertEquals(3, list.size());
  94. Map<Object, Object> map1 = (Map<Object, Object>) list.get(0);
  95. assertEquals(2, map1.size());
  96. assertEquals("Super Hoop", map1.get("item"));
  97. Map<Object, Object> map2 = (Map<Object, Object>) list.get(1);
  98. assertEquals(2, map2.size());
  99. assertEquals("Basketball", map2.get("item"));
  100. Map<Object, Object> map3 = (Map<Object, Object>) list.get(2);
  101. assertEquals(2, map3.size());
  102. assertEquals("Big Shoes", map3.get("item"));
  103. }
  104. }