add failing HumanTest to test recursive implementation
diff --git a/src/main/java/org/yaml/snakeyaml/constructor/BaseConstructor.java b/src/main/java/org/yaml/snakeyaml/constructor/BaseConstructor.java
index 7e9789b..1b44ada 100644
--- a/src/main/java/org/yaml/snakeyaml/constructor/BaseConstructor.java
+++ b/src/main/java/org/yaml/snakeyaml/constructor/BaseConstructor.java
@@ -13,6 +13,7 @@
import java.util.Stack;
import org.yaml.snakeyaml.composer.Composer;
+import org.yaml.snakeyaml.error.YAMLException;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.ScalarNode;
@@ -232,7 +233,8 @@
// }
protected void pushToConstruction2ndStep(Node node, Object object) {
- // TODO do we need this method ?
- // toBeConstructedAt2ndStep.push(new Tuple<Node, Object>(node, object));
+ toBeConstructedAt2ndStep.push(new Tuple<Node, Object>(node, object));
+ // TODO do we need this method ? (it is never called)
+ throw new YAMLException("??? !!! ???");
}
}
diff --git a/src/test/java/org/pyyaml/PyRecursiveTest.java b/src/test/java/org/pyyaml/PyRecursiveTest.java
index 08b6875..2c9b1da 100644
--- a/src/test/java/org/pyyaml/PyRecursiveTest.java
+++ b/src/test/java/org/pyyaml/PyRecursiveTest.java
@@ -67,7 +67,4 @@
assertSame(tmpInstance.getBar(), value2);
}
}
-
- // TODO write same more complex tests for recursions. maybe recursion in
- // Arrays, bean properties...
}
diff --git a/src/test/java/org/yaml/snakeyaml/recursive/Human.java b/src/test/java/org/yaml/snakeyaml/recursive/Human.java
new file mode 100644
index 0000000..8df0e54
--- /dev/null
+++ b/src/test/java/org/yaml/snakeyaml/recursive/Human.java
@@ -0,0 +1,87 @@
+/*
+ * See LICENSE file in distribution for copyright and licensing information.
+ */
+package org.yaml.snakeyaml.recursive;
+
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+
+public class Human {
+ private String name;
+ private Date birthday;
+ private String birthPlace;
+ private Human father;
+ private Human mother;
+ private Human parner;
+ private Human bankAccountOwner;
+ private List<Human> children;
+
+ public Human() {
+ children = new LinkedList<Human>();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Date getBirthday() {
+ return birthday;
+ }
+
+ public void setBirthday(Date birthday) {
+ this.birthday = birthday;
+ }
+
+ public String getBirthPlace() {
+ return birthPlace;
+ }
+
+ public Human getFather() {
+ return father;
+ }
+
+ public void setFather(Human father) {
+ this.father = father;
+ }
+
+ public Human getMother() {
+ return mother;
+ }
+
+ public void setMother(Human mother) {
+ this.mother = mother;
+ }
+
+ public void setBirthPlace(String birthPlace) {
+ this.birthPlace = birthPlace;
+ }
+
+ public List<Human> getChildren() {
+ return children;
+ }
+
+ public void setChildren(List<Human> children) {
+ this.children = children;
+ }
+
+ public Human getParner() {
+ return parner;
+ }
+
+ public void setParner(Human parner) {
+ this.parner = parner;
+ }
+
+ public Human getBankAccountOwner() {
+ return bankAccountOwner;
+ }
+
+ public void setBankAccountOwner(Human bankAccountOwner) {
+ this.bankAccountOwner = bankAccountOwner;
+ }
+}
diff --git a/src/test/java/org/yaml/snakeyaml/recursive/HumanTest.java b/src/test/java/org/yaml/snakeyaml/recursive/HumanTest.java
new file mode 100644
index 0000000..b4b2cdb
--- /dev/null
+++ b/src/test/java/org/yaml/snakeyaml/recursive/HumanTest.java
@@ -0,0 +1,94 @@
+/*
+ * See LICENSE file in distribution for copyright and licensing information.
+ */
+package org.yaml.snakeyaml.recursive;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.yaml.snakeyaml.Util;
+import org.yaml.snakeyaml.Yaml;
+
+public class HumanTest extends TestCase {
+
+ public void testNoChildren() throws IOException {
+ Human father = new Human();
+ father.setName("Father");
+ father.setBirthday(new Date(1000000000));
+ father.setBirthPlace("Leningrad");
+ father.setBankAccountOwner(father);
+ Human mother = new Human();
+ mother.setName("Mother");
+ mother.setBirthday(new Date(100000000000L));
+ mother.setBirthPlace("Saint-Petersburg");
+ father.setParner(mother);
+ mother.setParner(father);
+ mother.setBankAccountOwner(father);
+ Yaml yaml = new Yaml();
+ String output = yaml.dump(father);
+ String etalon = Util.getLocalResource("recursive/no-children-1.yaml");
+ assertEquals(etalon, output);
+ //
+ Human father2 = (Human) yaml.load(output);
+ assertNotNull(father2);
+ assertEquals("Father", father2.getName());
+ assertEquals("Mother", father2.getParner().getName());
+ assertEquals("Father", father2.getBankAccountOwner().getName());
+ assertSame(father2, father2.getBankAccountOwner());
+ }
+
+ public void testChildren() throws IOException {
+ Human father = new Human();
+ father.setName("Father");
+ father.setBirthday(new Date(1000000000));
+ father.setBirthPlace("Leningrad");
+ father.setBankAccountOwner(father);
+ //
+ Human mother = new Human();
+ mother.setName("Mother");
+ mother.setBirthday(new Date(100000000000L));
+ mother.setBirthPlace("Saint-Petersburg");
+ father.setParner(mother);
+ mother.setParner(father);
+ mother.setBankAccountOwner(father);
+ //
+ Human son = new Human();
+ son.setName("Son");
+ son.setBirthday(new Date(310000000000L));
+ son.setBirthPlace("Munich");
+ son.setBankAccountOwner(father);
+ son.setFather(father);
+ son.setMother(mother);
+ //
+ Human daughter = new Human();
+ daughter.setName("Daughter");
+ daughter.setBirthday(new Date(420000000000L));
+ daughter.setBirthPlace("New York");
+ daughter.setBankAccountOwner(father);
+ daughter.setFather(father);
+ daughter.setMother(mother);
+ //
+ List<Human> children = new ArrayList<Human>(2);
+ children.add(son);
+ children.add(daughter);
+ father.setChildren(children);
+ mother.setChildren(children);
+ //
+ Yaml yaml = new Yaml();
+ String output = yaml.dump(father);
+ System.out.println(output);
+ String etalon = Util.getLocalResource("recursive/with-children-2.yaml");
+ assertEquals(etalon, output);
+ //
+ Human father2 = (Human) yaml.load(output);
+ assertNotNull(father2);
+ assertEquals("Father", father2.getName());
+ assertEquals("Mother", father2.getParner().getName());
+ assertEquals("Father", father2.getBankAccountOwner().getName());
+ assertSame(father2, father2.getBankAccountOwner());
+ }
+}
diff --git a/src/test/resources/recursive/no-children-1.yaml b/src/test/resources/recursive/no-children-1.yaml
new file mode 100644
index 0000000..d86035c
--- /dev/null
+++ b/src/test/resources/recursive/no-children-1.yaml
@@ -0,0 +1,17 @@
+&id001 !!org.yaml.snakeyaml.recursive.Human
+bankAccountOwner: *id001
+birthPlace: Leningrad
+birthday: 1970-01-12T13:46:40Z
+children: []
+father: null
+mother: null
+name: Father
+parner:
+ bankAccountOwner: *id001
+ birthPlace: Saint-Petersburg
+ birthday: 1973-03-03T09:46:40Z
+ children: []
+ father: null
+ mother: null
+ name: Mother
+ parner: *id001
\ No newline at end of file
diff --git a/src/test/resources/recursive/with-children-2.yaml b/src/test/resources/recursive/with-children-2.yaml
new file mode 100644
index 0000000..aad8af8
--- /dev/null
+++ b/src/test/resources/recursive/with-children-2.yaml
@@ -0,0 +1,33 @@
+&id001 !!org.yaml.snakeyaml.recursive.Human
+bankAccountOwner: *id001
+birthPlace: Leningrad
+birthday: 1970-01-12T13:46:40Z
+children: &id002
+- bankAccountOwner: *id001
+ birthPlace: Munich
+ birthday: 1979-10-28T23:06:40Z
+ children: []
+ father: *id001
+ mother: &id003
+ bankAccountOwner: *id001
+ birthPlace: Saint-Petersburg
+ birthday: 1973-03-03T09:46:40Z
+ children: *id002
+ father: null
+ mother: null
+ name: Mother
+ parner: *id001
+ name: Son
+ parner: null
+- bankAccountOwner: *id001
+ birthPlace: New York
+ birthday: 1983-04-24T02:40:00Z
+ children: []
+ father: *id001
+ mother: *id003
+ name: Daughter
+ parner: null
+father: null
+mother: null
+name: Father
+parner: *id003