1463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov/**
2463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov * Copyright (c) 2008, http://www.snakeyaml.org
3463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov *
4463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov * Licensed under the Apache License, Version 2.0 (the "License");
5463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov * you may not use this file except in compliance with the License.
6463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov * You may obtain a copy of the License at
7463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov *
8463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov *     http://www.apache.org/licenses/LICENSE-2.0
9463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov *
10463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov * Unless required by applicable law or agreed to in writing, software
11463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov * distributed under the License is distributed on an "AS IS" BASIS,
12463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov * See the License for the specific language governing permissions and
14463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov * limitations under the License.
15463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov */
16463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somovpackage org.yaml.snakeyaml.constructor;
17463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov
18463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somovimport junit.framework.TestCase;
19463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somovimport org.yaml.snakeyaml.error.YAMLException;
20463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somovimport org.yaml.snakeyaml.nodes.Node;
21463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somovimport org.yaml.snakeyaml.nodes.SequenceNode;
22463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somovimport org.yaml.snakeyaml.nodes.Tag;
23463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov
24463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somovimport java.util.ArrayList;
25463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov
26463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somovpublic class AbstractConstructTest extends TestCase {
27463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov
28463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov    public void testNotRecursive() {
29463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        AbstractConstruct abstractConstruct = new AbstractConstruct() {
30463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov            public Object construct(Node node) {
31463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov                return null;
32463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov            }
33463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        };
34463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        Node node = new SequenceNode(Tag.SEQ, true, new ArrayList<Node>(), null, null, false);
35463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        try {
36463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov            abstractConstruct.construct2ndStep(node, "");
37463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov            fail();
38463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        } catch (YAMLException e) {
39463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov            assertEquals("Unexpected recursive structure for Node: <org.yaml.snakeyaml.nodes.SequenceNode (tag=tag:yaml.org,2002:seq, value=[])>", e.getMessage());
40463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        }
41463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov    }
42463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov
43463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov    public void testRecursive() {
44463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        AbstractConstruct abstractConstruct = new AbstractConstruct() {
45463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov
46463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov            public Object construct(Node node) {
47463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov                return null;
48463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov            }
49463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        };
50463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        Node node = new SequenceNode(Tag.SEQ, true, new ArrayList<Node>(), null, null, false);
51463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        node.setTwoStepsConstruction(true);
52463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        try {
53463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov            abstractConstruct.construct2ndStep(node, "");
54463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov            fail();
55463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        } catch (IllegalStateException e) {
56463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov            assertEquals("Not Implemented in org.yaml.snakeyaml.constructor.AbstractConstructTest$2", e.getMessage());
57463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov        }
58463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov    }
59463ea2a08fdfd3c167fe0aabd444586141d21b64Andrey Somov}
60