1/**
2 * Copyright (c) 2008, 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 */
16package org.yaml.snakeyaml.error;
17
18import junit.framework.TestCase;
19
20public 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}
62