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 */ 16 package org.yaml.snakeyaml.constructor; 17 18 import junit.framework.TestCase; 19 import org.yaml.snakeyaml.error.YAMLException; 20 import org.yaml.snakeyaml.nodes.Node; 21 import org.yaml.snakeyaml.nodes.SequenceNode; 22 import org.yaml.snakeyaml.nodes.Tag; 23 24 import java.util.ArrayList; 25 26 public class AbstractConstructTest extends TestCase { 27 28 public void testNotRecursive() { 29 AbstractConstruct abstractConstruct = new AbstractConstruct() { 30 public Object construct(Node node) { 31 return null; 32 } 33 }; 34 Node node = new SequenceNode(Tag.SEQ, true, new ArrayList<Node>(), null, null, false); 35 try { 36 abstractConstruct.construct2ndStep(node, ""); 37 fail(); 38 } catch (YAMLException e) { 39 assertEquals("Unexpected recursive structure for Node: <org.yaml.snakeyaml.nodes.SequenceNode (tag=tag:yaml.org,2002:seq, value=[])>", e.getMessage()); 40 } 41 } 42 43 public void testRecursive() { 44 AbstractConstruct abstractConstruct = new AbstractConstruct() { 45 46 public Object construct(Node node) { 47 return null; 48 } 49 }; 50 Node node = new SequenceNode(Tag.SEQ, true, new ArrayList<Node>(), null, null, false); 51 node.setTwoStepsConstruction(true); 52 try { 53 abstractConstruct.construct2ndStep(node, ""); 54 fail(); 55 } catch (IllegalStateException e) { 56 assertEquals("Not Implemented in org.yaml.snakeyaml.constructor.AbstractConstructTest$2", e.getMessage()); 57 } 58 } 59 } 60