Exemplo n.º 1
0
 @SuppressWarnings("unchecked")
 public void testExample_2_22() {
   YamlDocument document = new YamlDocument("example2_22.yaml");
   Map<String, Object> map = (Map<String, Object>) document.getNativeData();
   assertEquals(4, map.size());
   assertEquals(
       "Expect '2001-12-15T02:59:43.1Z' to be a Date.",
       Date.class,
       map.get("canonical").getClass());
   Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
   cal.clear();
   cal.set(Calendar.YEAR, 2001);
   cal.set(Calendar.MONTH, 11); // Java's months are zero-based...
   cal.set(Calendar.DAY_OF_MONTH, 15);
   cal.set(Calendar.HOUR_OF_DAY, 2);
   cal.set(Calendar.MINUTE, 59);
   cal.set(Calendar.SECOND, 43);
   cal.set(Calendar.MILLISECOND, 100);
   Date date = cal.getTime();
   assertEquals(date, map.get("canonical"));
   assertEquals(
       "Expect '2001-12-14t21:59:43.10-05:00' to be a Date.",
       Date.class,
       map.get("iso8601").getClass());
   assertEquals(
       "Expect '2001-12-14 21:59:43.10 -5' to be a Date.",
       Date.class,
       map.get("spaced").getClass());
   assertEquals("Expect '2002-12-14' to be a Date.", Date.class, map.get("date").getClass());
 }
Exemplo n.º 2
0
 @SuppressWarnings("unchecked")
 public void testExample_2_25() {
   YamlDocument document = new YamlDocument("example2_25.yaml");
   Set<String> set = (Set<String>) document.getNativeData();
   assertEquals(3, set.size());
   assertTrue(set.contains("Mark McGwire"));
   assertTrue(set.contains("Sammy Sosa"));
   assertTrue(set.contains("Ken Griff"));
 }
Exemplo n.º 3
0
 @SuppressWarnings("unchecked")
 public void testExample_2_4() {
   YamlDocument document = new YamlDocument("example2_4.yaml");
   List<Map<String, Object>> list = (List<Map<String, Object>>) document.getNativeData();
   assertEquals(2, list.size());
   Map<String, Object> map1 = list.get(0);
   assertEquals(3, map1.size());
   assertEquals("Mark McGwire", map1.get("name"));
 }
Exemplo n.º 4
0
 @SuppressWarnings("unchecked")
 public void testExample_2_23() throws IOException {
   YamlDocument document = new YamlDocument("example2_23.yaml", false, new SomethingConstructor());
   Map<String, Object> map = (Map<String, Object>) document.getNativeData();
   assertEquals(3, map.size());
   String special = (String) map.get("application specific tag");
   assertEquals(
       "THE SEMANTICS OF THE TAG ABOVE MAY BE DIFFERENT FOR DIFFERENT DOCUMENTS.", special);
 }
Exemplo n.º 5
0
 @SuppressWarnings("unchecked")
 public void testExample_2_21() {
   YamlDocument document = new YamlDocument("example2_21.yaml");
   Map<String, Object> map = (Map<String, Object>) document.getNativeData();
   assertEquals(4, map.size());
   assertNull("'~' must be parsed as 'null': " + map.get(null), map.get(null));
   assertTrue((Boolean) map.get(Boolean.TRUE));
   assertFalse((Boolean) map.get(Boolean.FALSE));
   assertEquals("12345", map.get("string"));
 }
Exemplo n.º 6
0
 @SuppressWarnings("unchecked")
 public void testExample_2_23_picture() throws Exception {
   YamlDocument document = new YamlDocument("example2_23_picture.yaml", false);
   Map<String, Object> map = (Map<String, Object>) document.getNativeData();
   assertEquals(1, map.size());
   byte[] picture = (byte[]) map.get("picture");
   assertEquals((byte) 'G', picture[0]);
   assertEquals((byte) 'I', picture[1]);
   assertEquals((byte) 'F', picture[2]);
 }
Exemplo n.º 7
0
 @SuppressWarnings("unchecked")
 public void testExample_2_1() {
   YamlDocument document = new YamlDocument("example2_1.yaml");
   List<String> list = (List<String>) document.getNativeData();
   assertEquals(3, list.size());
   assertEquals("Mark McGwire", list.get(0));
   assertEquals("Sammy Sosa", list.get(1));
   assertEquals("Ken Griffey", list.get(2));
   assertEquals("[Mark McGwire, Sammy Sosa, Ken Griffey]\n", document.getPresentation());
 }
Exemplo n.º 8
0
 @SuppressWarnings("unchecked")
 public void testExample_2_23_non_date() {
   try {
     YamlDocument document = new YamlDocument("example2_23_non_date.yaml");
     Map<String, Object> map = (Map<String, Object>) document.getNativeData();
     assertEquals(1, map.size());
     assertEquals("2002-04-28", map.get("not-date"));
   } catch (RuntimeException e) {
     fail("Cannot parse '!!str': 'not-date: !!str 2002-04-28'");
   }
 }
Exemplo n.º 9
0
 @SuppressWarnings("unchecked")
 public void testExample_2_6() {
   YamlDocument document = new YamlDocument("example2_6.yaml");
   Map<String, Map<String, Object>> map =
       (Map<String, Map<String, Object>>) document.getNativeData();
   assertEquals(2, map.size());
   Map<String, Object> map1 = map.get("Mark McGwire");
   assertEquals(2, map1.size());
   Map<String, Object> map2 = map.get("Sammy Sosa");
   assertEquals(2, map2.size());
 }
Exemplo n.º 10
0
 @SuppressWarnings("unchecked")
 public void testExample_2_19() {
   YamlDocument document = new YamlDocument("example2_19.yaml");
   Map<String, Object> map = (Map<String, Object>) document.getNativeData();
   assertEquals(5, map.size());
   assertEquals("Expect 12345 to be an Integer.", Integer.class, map.get("canonical").getClass());
   assertEquals(new Integer(12345), map.get("canonical"));
   assertEquals(new Integer(12345), map.get("decimal"));
   assertEquals(new Integer(3 * 3600 + 25 * 60 + 45), map.get("sexagesimal"));
   assertEquals(new Integer(014), map.get("octal"));
   assertEquals(new Integer(0xC), map.get("hexadecimal"));
 }
Exemplo n.º 11
0
 @SuppressWarnings("unchecked")
 public void testExample_2_5() {
   YamlDocument document = new YamlDocument("example2_5.yaml");
   List<List<Object>> list = (List<List<Object>>) document.getNativeData();
   assertEquals(3, list.size());
   List<Object> list1 = list.get(0);
   assertEquals(3, list1.size());
   assertEquals("name", list1.get(0));
   assertEquals("hr", list1.get(1));
   assertEquals("avg", list1.get(2));
   assertEquals(3, list.get(1).size());
   assertEquals(3, list.get(2).size());
 }
Exemplo n.º 12
0
 @SuppressWarnings("unchecked")
 public void testExample_2_2() {
   YamlDocument document = new YamlDocument("example2_2.yaml");
   Map<String, Object> map = (Map<String, Object>) document.getNativeData();
   assertEquals(3, map.size());
   assertEquals("Expect 65 to be a Integer", Integer.class, map.get("hr").getClass());
   assertEquals(new Integer(65), map.get("hr"));
   assertEquals(new Float(0.278), new Float("0.278"));
   assertEquals("Expect 0.278 to be a Float", Double.class, map.get("avg").getClass());
   assertEquals(new Double(0.278), map.get("avg"));
   assertEquals("Expect 147 to be an Integer", Integer.class, map.get("rbi").getClass());
   assertEquals(new Integer(147), map.get("rbi"));
 }
Exemplo n.º 13
0
 @SuppressWarnings("unchecked")
 public void testExample_2_20() {
   YamlDocument document = new YamlDocument("example2_20.yaml");
   Map<String, Object> map = (Map<String, Object>) document.getNativeData();
   assertEquals(6, map.size());
   assertEquals(
       "Expect '1.23015e+3' to be a Double.", Double.class, map.get("canonical").getClass());
   assertEquals(new Double(1230.15), map.get("canonical"));
   assertEquals(new Double(12.3015e+02), map.get("exponential"));
   assertEquals(new Double(20 * 60 + 30.15), map.get("sexagesimal"));
   assertEquals(new Double(1230.15), map.get("fixed"));
   assertEquals(Double.NEGATIVE_INFINITY, map.get("negative infinity"));
   assertEquals(Double.NaN, map.get("not a number"));
 }
Exemplo n.º 14
0
 @SuppressWarnings("unchecked")
 public void testExample_2_3() {
   YamlDocument document = new YamlDocument("example2_3.yaml");
   Map<String, List<String>> map = (Map<String, List<String>>) document.getNativeData();
   assertEquals(2, map.size());
   List<String> list1 = map.get("american");
   assertEquals(3, list1.size());
   assertEquals("Boston Red Sox", list1.get(0));
   assertEquals("Detroit Tigers", list1.get(1));
   assertEquals("New York Yankees", list1.get(2));
   List<String> list2 = map.get("national");
   assertEquals(3, list2.size());
   assertEquals("New York Mets", list2.get(0));
   assertEquals("Chicago Cubs", list2.get(1));
   assertEquals("Atlanta Braves", list2.get(2));
 }
Exemplo n.º 15
0
 @SuppressWarnings("unchecked")
 public void testExample_2_26() {
   YamlDocument document = new YamlDocument("example2_26.yaml");
   Map<String, String> map = (Map<String, String>) document.getNativeData();
   assertEquals(3, map.size());
   assertTrue(map instanceof LinkedHashMap);
   assertEquals(new Integer(65), map.get("Mark McGwire"));
   assertEquals(new Integer(63), map.get("Sammy Sosa"));
   assertEquals(new Integer(58), map.get("Ken Griffy"));
   List list = new ArrayList();
   for (String key : map.keySet()) {
     list.add(key);
   }
   assertEquals("Mark McGwire", list.get(0));
   assertEquals("Sammy Sosa", list.get(1));
   assertEquals("Ken Griffy", list.get(2));
 }