1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.error;
17
18 import junit.framework.TestCase;
19
20 public class MarkedYAMLExceptionTest extends TestCase {
21
22 public void testToString1() {
23 Mark mark = new Mark("test1", 0, 0, 0, "*The first line.\nThe last line.", 0);
24 MarkedYAMLException exception = new MarkedYAMLException(null, null, "Error happened", mark);
25 assertTrue(exception.toString().contains("Error happened"));
26 assertTrue(exception.toString().contains("The first line"));
27 assertTrue(exception.toString(), exception.toString().contains("test1"));
28 }
29
30 public void testToString2() {
31 Mark mark = new Mark("search", 0, 0, 0, "*The first line.\nThe last line.", 0);
32 MarkedYAMLException exception = new MarkedYAMLException("See http://www.google.com", mark,
33 "Error2 happened", mark);
34 assertTrue(exception.toString().contains("Error2 happened"));
35 assertTrue(exception.toString().contains("The first line"));
36 assertTrue(exception.toString().contains("search"));
37 }
38
39 public void testToString3() {
40 MarkedYAMLException exception = new MarkedYAMLException("See http://www.google.com", null,
41 null, null, "Note1");
42 assertTrue(exception.toString().contains("Note1"));
43 }
44
45 public void testToString4() {
46 Mark mark = new Mark("search", 0, 0, 0, "*The first line.\nThe last line.", 0);
47 MarkedYAMLException exception = new MarkedYAMLException("See http://www.google.com", mark,
48 null, null, null, null);
49 assertTrue(exception.toString().contains("first line"));
50 }
51
52 public void testGetters() {
53 Mark mark = new Mark("search", 0, 0, 0, "*The first line.\nThe last line.", 0);
54 MarkedYAMLException exception = new MarkedYAMLException("See http://www.google.com", mark,
55 "Error2 happened", mark);
56 assertEquals("See http://www.google.com", exception.getContext());
57 assertEquals(mark, exception.getContextMark());
58 assertEquals("Error2 happened", exception.getProblem());
59 assertEquals(mark, exception.getProblemMark());
60 }
61 }