diff options
author | Andrey Somov <public.somov@gmail.com> | 2022-09-10 13:51:30 +0300 |
---|---|---|
committer | Andrey Somov <public.somov@gmail.com> | 2022-09-10 14:09:24 +0300 |
commit | 147174089938e8513a85a100e2a6ad2600abd74f (patch) | |
tree | 6c80f294e2493df20c8b31bb8d1a1b690d956fb3 | |
parent | b3980a99e8ebfe74cd14b538b78e2ea29c57110b (diff) | |
download | snakeyaml-147174089938e8513a85a100e2a6ad2600abd74f.tar.gz |
Reformat
11 files changed, 262 insertions, 269 deletions
diff --git a/src/main/java/org/yaml/snakeyaml/LoaderOptions.java b/src/main/java/org/yaml/snakeyaml/LoaderOptions.java index 9625bb2f..911bb043 100644 --- a/src/main/java/org/yaml/snakeyaml/LoaderOptions.java +++ b/src/main/java/org/yaml/snakeyaml/LoaderOptions.java @@ -140,6 +140,7 @@ public class LoaderOptions { /** * The max amount of code points in the input YAML document. Please be aware that byte limit * depends on the encoding. + * * @param codePointLimit - the max allowed size of the YAML data */ public void setCodePointLimit(int codePointLimit) { diff --git a/src/main/java/org/yaml/snakeyaml/Yaml.java b/src/main/java/org/yaml/snakeyaml/Yaml.java index 0cfd2bb2..16114cd9 100644 --- a/src/main/java/org/yaml/snakeyaml/Yaml.java +++ b/src/main/java/org/yaml/snakeyaml/Yaml.java @@ -471,8 +471,8 @@ public class Yaml { } private Object loadFromReader(StreamReader sreader, Class<?> type) { - Composer composer = new Composer(new ParserImpl(sreader, loadingConfig), - resolver, loadingConfig); + Composer composer = + new Composer(new ParserImpl(sreader, loadingConfig), resolver, loadingConfig); constructor.setComposer(composer); return constructor.getSingleData(type); } diff --git a/src/main/java/org/yaml/snakeyaml/constructor/Constructor.java b/src/main/java/org/yaml/snakeyaml/constructor/Constructor.java index 2a87e936..52dd5da8 100644 --- a/src/main/java/org/yaml/snakeyaml/constructor/Constructor.java +++ b/src/main/java/org/yaml/snakeyaml/constructor/Constructor.java @@ -87,6 +87,7 @@ public class Constructor extends SafeConstructor { /** * Create with all possible arguments + * * @param theRoot - the class (usually JavaBean) to be constructed * @param moreTDs - collection of classes used by the root class * @param loadingConfig - configuration diff --git a/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java b/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java index ea154727..b34011c5 100644 --- a/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java +++ b/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java @@ -98,8 +98,7 @@ public class SafeConstructor extends BaseConstructor { keyNode.setType(String.class); keyNode.setTag(Tag.STR); } else { - throw new YAMLException( - "Keys must be scalars but found: " + keyNode); + throw new YAMLException("Keys must be scalars but found: " + keyNode); } } Object key = constructObject(keyNode); @@ -112,9 +111,8 @@ public class SafeConstructor extends BaseConstructor { try { key.hashCode();// check circular dependencies } catch (Exception e) { - throw new ConstructorException("while constructing a mapping", - node.getStartMark(), "found unacceptable key " + key, - tuple.getKeyNode().getStartMark(), e); + throw new ConstructorException("while constructing a mapping", node.getStartMark(), + "found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e); } } } diff --git a/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java b/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java index e810de85..75c9c15a 100644 --- a/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java +++ b/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java @@ -220,7 +220,7 @@ public final class ScannerImpl implements Scanner { this(reader, new LoaderOptions()); } - public ScannerImpl(StreamReader reader, LoaderOptions options) { + public ScannerImpl(StreamReader reader, LoaderOptions options) { this.parseComments = options.isProcessComments(); this.reader = reader; this.tokens = new ArrayList<Token>(100); @@ -232,8 +232,8 @@ public final class ScannerImpl implements Scanner { } /** - * Please use LoaderOptions instead - * Set the scanner to ignore comments or parse them as a <code>CommentToken</code>. + * Please use LoaderOptions instead Set the scanner to ignore comments or parse them as a + * <code>CommentToken</code>. * * @param parseComments <code>true</code> to parse; <code>false</code> to ignore */ @@ -331,8 +331,8 @@ public final class ScannerImpl implements Scanner { */ private void fetchMoreTokens() { if (reader.getIndex() > loaderOptions.getCodePointLimit()) { - throw new YAMLException("The incoming YAML document exceeds the limit: " + - loaderOptions.getCodePointLimit() + " code points."); + throw new YAMLException("The incoming YAML document exceeds the limit: " + + loaderOptions.getCodePointLimit() + " code points."); } // Eat whitespaces and process comments until we reach the next token. scanToNextToken(); @@ -1190,7 +1190,7 @@ public final class ScannerImpl implements Scanner { // whitespace, then this is the start of a plain scalar. return Constant.NULL_BL_T_LINEBR.hasNo(c, "-?:,[]{}#&*!|>'\"%@`") || (Constant.NULL_BL_T_LINEBR.hasNo(reader.peek(1)) - && (c == '-' || (this.flowLevel == 0 && "?:".indexOf(c) != -1))); + && (c == '-' || (this.flowLevel == 0 && "?:".indexOf(c) != -1))); } // Scanners. @@ -1835,7 +1835,7 @@ public final class ScannerImpl implements Scanner { } } // Pass several results back together. - return new Object[]{chunks.toString(), maxIndent, endMark}; + return new Object[] {chunks.toString(), maxIndent, endMark}; } private Object[] scanBlockScalarBreaks(int indent) { @@ -1865,7 +1865,7 @@ public final class ScannerImpl implements Scanner { } } // Return both the assembled intervening string and the end-mark. - return new Object[]{chunks.toString(), endMark}; + return new Object[] {chunks.toString(), endMark}; } /** @@ -2054,7 +2054,7 @@ public final class ScannerImpl implements Scanner { c = reader.peek(length); if (Constant.NULL_BL_T_LINEBR.has(c) || (c == ':' && Constant.NULL_BL_T_LINEBR.has(reader.peek(length + 1), - flowLevel != 0 ? ",[]{}" : "")) + flowLevel != 0 ? ",[]{}" : "")) || (this.flowLevel != 0 && ",?[]{}".indexOf(c) != -1)) { break; } diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue377/ReferencesTest.java b/src/test/java/org/yaml/snakeyaml/issues/issue377/ReferencesTest.java index ed7d1d03..cb17cb8a 100644 --- a/src/test/java/org/yaml/snakeyaml/issues/issue377/ReferencesTest.java +++ b/src/test/java/org/yaml/snakeyaml/issues/issue377/ReferencesTest.java @@ -18,7 +18,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.HashMap; - import org.junit.Test; import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue531/Fuzzy47081Test.java b/src/test/java/org/yaml/snakeyaml/issues/issue531/Fuzzy47081Test.java index 165c3879..61965356 100644 --- a/src/test/java/org/yaml/snakeyaml/issues/issue531/Fuzzy47081Test.java +++ b/src/test/java/org/yaml/snakeyaml/issues/issue531/Fuzzy47081Test.java @@ -24,8 +24,8 @@ import org.yaml.snakeyaml.Yaml; public class Fuzzy47081Test { /** - * Recursive list fails (with StackOverflowError) because it is used as a key - * There is no way to disable recursive sequence + * Recursive list fails (with StackOverflowError) because it is used as a key There is no way to + * disable recursive sequence */ @Test public void parse47081() { @@ -33,9 +33,11 @@ public class Fuzzy47081Test { LoaderOptions options = new LoaderOptions(); options.setAllowRecursiveKeys(true); Yaml yaml = new Yaml(options); - String strYaml = "&a\n" - + "- *a\n" // if this line is removed, the test properly complains about the recursive keys in map -> Recursive key for mapping is detected, but it is not configured to be allowed. - + "- *a:\n"; // when the colon ir removed, the test is Ok, because the recursive list is not a key + String strYaml = "&a\n" + "- *a\n" + // if this line is removed, the test properly complains about the recursive keys in map -> + // Recursive key for mapping is detected, but it is not configured to be allowed. + + "- *a:\n"; // when the colon ir removed, the test is Ok, because the recursive list is + // not a key yaml.load(strYaml); fail("Should report invalid YAML"); } catch (StackOverflowError e) { diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue73/RecursiveSetTest.java b/src/test/java/org/yaml/snakeyaml/issues/issue73/RecursiveSetTest.java index 68aa968e..48aedff9 100644 --- a/src/test/java/org/yaml/snakeyaml/issues/issue73/RecursiveSetTest.java +++ b/src/test/java/org/yaml/snakeyaml/issues/issue73/RecursiveSetTest.java @@ -21,8 +21,6 @@ import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Util; import org.yaml.snakeyaml.Yaml; -import junit.framework.TestCase; - public class RecursiveSetTest extends TestCase { public void testDumpException() { @@ -51,52 +49,52 @@ public class RecursiveSetTest extends TestCase { } } - /** - * XXX: sets can be recursive - */ - @SuppressWarnings("unchecked") - public void testLoadRecursiveTest() { - String doc = Util.getLocalResource("issues/issue73-recursive5.txt"); - // System.out.println(doc); - LoaderOptions options = new LoaderOptions(); - options.setAllowRecursiveKeys(true); - Yaml yaml = new Yaml(options); - Bean1 obj = (Bean1) yaml.load(doc); - Set<Object> set = obj.getSet(); - // System.out.println(set); - assertEquals(LinkedHashSet.class, set.getClass()); - assertEquals("ID123", obj.getId()); - assertEquals(3, set.size()); - assertTrue(set.remove("zzz")); - assertTrue(set.remove("ccc")); - assertFalse(set.contains("111")); - try { - set.contains(set); - fail("Recursive set fails to provide a hashcode."); - } catch (StackOverflowError e) { - // ignore - } - // - Set<Object> self = (Set<Object>) set.iterator().next(); - assertEquals(LinkedHashSet.class, self.getClass()); - assertEquals(set, self); - assertSame(set, self); - assertEquals(1, set.size()); - assertEquals(1, self.size()); - set.add("111"); - assertEquals(2, set.size()); - assertEquals(2, self.size()); - // - self.clear(); - assertTrue(self.isEmpty()); - assertTrue(set.isEmpty()); - assertFalse("Now it should not be recursive any longer (no StackOverflowError).", - set.contains(set)); - // - set.add("jjj"); - assertEquals(1, set.size()); - assertEquals(1, self.size()); + /** + * XXX: sets can be recursive + */ + @SuppressWarnings("unchecked") + public void testLoadRecursiveTest() { + String doc = Util.getLocalResource("issues/issue73-recursive5.txt"); + // System.out.println(doc); + LoaderOptions options = new LoaderOptions(); + options.setAllowRecursiveKeys(true); + Yaml yaml = new Yaml(options); + Bean1 obj = yaml.load(doc); + Set<Object> set = obj.getSet(); + // System.out.println(set); + assertEquals(LinkedHashSet.class, set.getClass()); + assertEquals("ID123", obj.getId()); + assertEquals(3, set.size()); + assertTrue(set.remove("zzz")); + assertTrue(set.remove("ccc")); + assertFalse(set.contains("111")); + try { + set.contains(set); + fail("Recursive set fails to provide a hashcode."); + } catch (StackOverflowError e) { + // ignore } + // + Set<Object> self = (Set<Object>) set.iterator().next(); + assertEquals(LinkedHashSet.class, self.getClass()); + assertEquals(set, self); + assertSame(set, self); + assertEquals(1, set.size()); + assertEquals(1, self.size()); + set.add("111"); + assertEquals(2, set.size()); + assertEquals(2, self.size()); + // + self.clear(); + assertTrue(self.isEmpty()); + assertTrue(set.isEmpty()); + assertFalse("Now it should not be recursive any longer (no StackOverflowError).", + set.contains(set)); + // + set.add("jjj"); + assertEquals(1, set.size()); + assertEquals(1, self.size()); + } public static class Bean1 { diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue73/RecursiveSortedSetTest.java b/src/test/java/org/yaml/snakeyaml/issues/issue73/RecursiveSortedSetTest.java index b720ae60..6229f897 100644 --- a/src/test/java/org/yaml/snakeyaml/issues/issue73/RecursiveSortedSetTest.java +++ b/src/test/java/org/yaml/snakeyaml/issues/issue73/RecursiveSortedSetTest.java @@ -21,8 +21,6 @@ import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Util; import org.yaml.snakeyaml.Yaml; -import junit.framework.TestCase; - public class RecursiveSortedSetTest extends TestCase { public void testDumpException() { @@ -51,36 +49,36 @@ public class RecursiveSortedSetTest extends TestCase { } } - /** - * set and JavaBean refer to each other - */ - public void testLoadRecursiveTest() { - String doc = Util.getLocalResource("issues/issue73-recursive9.txt"); - // System.out.println(doc); - LoaderOptions options = new LoaderOptions(); - options.setAllowRecursiveKeys(true); - Yaml yaml = new Yaml(options); - Bean11 beanWithSet = (Bean11) yaml.load(doc); - Set<Object> set = beanWithSet.getSet(); - assertEquals(TreeSet.class, set.getClass()); - assertEquals("ID555", beanWithSet.getId()); - assertEquals(3, set.size()); - assertTrue(set.remove("ggg")); - // assertFalse(set.remove("ggg"));??? - assertTrue(set.remove("hhh")); - assertEquals(1, set.size()); - // - Bean11 beanRef = (Bean11) set.iterator().next(); - assertEquals(beanWithSet, beanRef); - assertSame(beanWithSet, beanRef); - // - assertFalse(set.isEmpty()); - assertTrue(set.contains(beanWithSet)); - assertFalse(set.add(beanWithSet)); - assertTrue(set.remove(beanWithSet)); - assertFalse(set.remove(beanWithSet)); - assertTrue(set.isEmpty()); - } + /** + * set and JavaBean refer to each other + */ + public void testLoadRecursiveTest() { + String doc = Util.getLocalResource("issues/issue73-recursive9.txt"); + // System.out.println(doc); + LoaderOptions options = new LoaderOptions(); + options.setAllowRecursiveKeys(true); + Yaml yaml = new Yaml(options); + Bean11 beanWithSet = yaml.load(doc); + Set<Object> set = beanWithSet.getSet(); + assertEquals(TreeSet.class, set.getClass()); + assertEquals("ID555", beanWithSet.getId()); + assertEquals(3, set.size()); + assertTrue(set.remove("ggg")); + // assertFalse(set.remove("ggg"));??? + assertTrue(set.remove("hhh")); + assertEquals(1, set.size()); + // + Bean11 beanRef = (Bean11) set.iterator().next(); + assertEquals(beanWithSet, beanRef); + assertSame(beanWithSet, beanRef); + // + assertFalse(set.isEmpty()); + assertTrue(set.contains(beanWithSet)); + assertFalse(set.add(beanWithSet)); + assertTrue(set.remove(beanWithSet)); + assertFalse(set.remove(beanWithSet)); + assertTrue(set.isEmpty()); + } public static class Bean11 implements Comparable<Object> { diff --git a/src/test/java/org/yaml/snakeyaml/recursive/HumanTest.java b/src/test/java/org/yaml/snakeyaml/recursive/HumanTest.java index 34356db5..5cd70c24 100644 --- a/src/test/java/org/yaml/snakeyaml/recursive/HumanTest.java +++ b/src/test/java/org/yaml/snakeyaml/recursive/HumanTest.java @@ -32,8 +32,6 @@ import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.representer.Representer; -import junit.framework.TestCase; - public class HumanTest extends TestCase { public void testNoChildren() { @@ -91,58 +89,58 @@ public class HumanTest extends TestCase { assertSame(father2, father2.getBankAccountOwner()); } - public void testChildren() { - 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.setPartner(mother); - mother.setPartner(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); - // - Set<Human> children = new LinkedHashSet<Human>(2); - children.add(son); - children.add(daughter); - father.setChildren(children); - mother.setChildren(children); - // - Yaml beanDumper = new Yaml(); - String output = beanDumper.dumpAsMap(son); - // System.out.println(output); - String etalon = Util.getLocalResource("recursive/with-children.yaml"); - assertEquals(etalon, output); - TypeDescription humanDescription = new TypeDescription(Human.class); - humanDescription.putMapPropertyType("children", Human.class, Object.class); - - LoaderOptions loaderOptions = new LoaderOptions(); - loaderOptions.setAllowRecursiveKeys(true); - Yaml beanLoader = new Yaml(new Constructor(humanDescription, loaderOptions)); - // - Human son2 = beanLoader.loadAs(output, Human.class); - assertNotNull(son2); - assertEquals("Son", son.getName()); + public void testChildren() { + 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.setPartner(mother); + mother.setPartner(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); + // + Set<Human> children = new LinkedHashSet<Human>(2); + children.add(son); + children.add(daughter); + father.setChildren(children); + mother.setChildren(children); + // + Yaml beanDumper = new Yaml(); + String output = beanDumper.dumpAsMap(son); + // System.out.println(output); + String etalon = Util.getLocalResource("recursive/with-children.yaml"); + assertEquals(etalon, output); + TypeDescription humanDescription = new TypeDescription(Human.class); + humanDescription.putMapPropertyType("children", Human.class, Object.class); + + LoaderOptions loaderOptions = new LoaderOptions(); + loaderOptions.setAllowRecursiveKeys(true); + Yaml beanLoader = new Yaml(new Constructor(humanDescription, loaderOptions)); + // + Human son2 = beanLoader.loadAs(output, Human.class); + assertNotNull(son2); + assertEquals("Son", son.getName()); Human father2 = son2.getFather(); assertEquals("Father", father2.getName()); @@ -164,61 +162,61 @@ public class HumanTest extends TestCase { validateSet(children2); } - public void testChildrenPretty() { - 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.setPartner(mother); - mother.setPartner(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); - // - Set<Human> children = new LinkedHashSet<Human>(2); - children.add(son); - children.add(daughter); - father.setChildren(children); - mother.setChildren(children); - // - DumperOptions options = new DumperOptions(); - options.setDefaultFlowStyle(FlowStyle.FLOW); - options.setPrettyFlow(true); - Yaml beanDumper = new Yaml(options); - String output = beanDumper.dump(son); - // System.out.println(output); - String etalon = Util.getLocalResource("recursive/with-children-pretty.yaml"); - assertEquals(etalon, output); - TypeDescription humanDescription = new TypeDescription(Human.class); - humanDescription.putMapPropertyType("children", Human.class, Object.class); - - LoaderOptions loaderOptions = new LoaderOptions(); - loaderOptions.setAllowRecursiveKeys(true); - Yaml beanLoader = new Yaml(new Constructor(humanDescription, loaderOptions)); - // - Human son2 = beanLoader.loadAs(output, Human.class); - assertNotNull(son2); - assertEquals("Son", son.getName()); + public void testChildrenPretty() { + 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.setPartner(mother); + mother.setPartner(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); + // + Set<Human> children = new LinkedHashSet<Human>(2); + children.add(son); + children.add(daughter); + father.setChildren(children); + mother.setChildren(children); + // + DumperOptions options = new DumperOptions(); + options.setDefaultFlowStyle(FlowStyle.FLOW); + options.setPrettyFlow(true); + Yaml beanDumper = new Yaml(options); + String output = beanDumper.dump(son); + // System.out.println(output); + String etalon = Util.getLocalResource("recursive/with-children-pretty.yaml"); + assertEquals(etalon, output); + TypeDescription humanDescription = new TypeDescription(Human.class); + humanDescription.putMapPropertyType("children", Human.class, Object.class); + + LoaderOptions loaderOptions = new LoaderOptions(); + loaderOptions.setAllowRecursiveKeys(true); + Yaml beanLoader = new Yaml(new Constructor(humanDescription, loaderOptions)); + // + Human son2 = beanLoader.loadAs(output, Human.class); + assertNotNull(son2); + assertEquals("Son", son.getName()); Human father2 = son2.getFather(); assertEquals("Father", father2.getName()); @@ -589,57 +587,57 @@ public class HumanTest extends TestCase { } } - public void testChildrenWithoutRootTag() { - 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.setPartner(mother); - mother.setPartner(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); - // - Set<Human> children = new LinkedHashSet<Human>(2); - children.add(son); - children.add(daughter); - father.setChildren(children); - mother.setChildren(children); - // - Yaml beanDumper = new Yaml(); - String output = beanDumper.dumpAsMap(son); - // System.out.println(output); - String etalon = Util.getLocalResource("recursive/with-children-no-root-tag.yaml"); - assertEquals(etalon, output); - TypeDescription humanDescription = new TypeDescription(Human.class); - humanDescription.putMapPropertyType("children", Human.class, Object.class); - LoaderOptions options = new LoaderOptions(); - options.setAllowRecursiveKeys(true); - Yaml beanLoader = new Yaml(new Constructor(humanDescription, options)); - // - Human son2 = beanLoader.loadAs(output, Human.class); - assertNotNull(son2); - assertEquals("Son", son.getName()); + public void testChildrenWithoutRootTag() { + 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.setPartner(mother); + mother.setPartner(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); + // + Set<Human> children = new LinkedHashSet<Human>(2); + children.add(son); + children.add(daughter); + father.setChildren(children); + mother.setChildren(children); + // + Yaml beanDumper = new Yaml(); + String output = beanDumper.dumpAsMap(son); + // System.out.println(output); + String etalon = Util.getLocalResource("recursive/with-children-no-root-tag.yaml"); + assertEquals(etalon, output); + TypeDescription humanDescription = new TypeDescription(Human.class); + humanDescription.putMapPropertyType("children", Human.class, Object.class); + LoaderOptions options = new LoaderOptions(); + options.setAllowRecursiveKeys(true); + Yaml beanLoader = new Yaml(new Constructor(humanDescription, options)); + // + Human son2 = beanLoader.loadAs(output, Human.class); + assertNotNull(son2); + assertEquals("Son", son.getName()); Human father2 = son2.getFather(); assertEquals("Father", father2.getName()); diff --git a/src/test/java/org/yaml/snakeyaml/recursive/generics/HumanGenericsTest.java b/src/test/java/org/yaml/snakeyaml/recursive/generics/HumanGenericsTest.java index c112c95c..eac51023 100644 --- a/src/test/java/org/yaml/snakeyaml/recursive/generics/HumanGenericsTest.java +++ b/src/test/java/org/yaml/snakeyaml/recursive/generics/HumanGenericsTest.java @@ -33,8 +33,6 @@ import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.nodes.Tag; import org.yaml.snakeyaml.representer.Representer; -import junit.framework.TestCase; - public class HumanGenericsTest extends TestCase { public void testNoChildren() throws IOException, IntrospectionException { @@ -133,12 +131,12 @@ public class HumanGenericsTest extends TestCase { mother.setChildren(children); // - LoaderOptions options = new LoaderOptions(); - options.setAllowRecursiveKeys(true); - Constructor constructor = new Constructor(options); - TypeDescription humanDescription = new TypeDescription(HumanGen.class); - humanDescription.putMapPropertyType("children", HumanGen.class, Object.class); - constructor.addTypeDescription(humanDescription); + LoaderOptions options = new LoaderOptions(); + options.setAllowRecursiveKeys(true); + Constructor constructor = new Constructor(options); + TypeDescription humanDescription = new TypeDescription(HumanGen.class); + humanDescription.putMapPropertyType("children", HumanGen.class, Object.class); + constructor.addTypeDescription(humanDescription); Yaml yaml = new Yaml(constructor); String output = yaml.dump(son); |