diff options
Diffstat (limited to 'src/test/java/org/yaml/snakeyaml/issues/issue64/ParameterizedTypeTest.java')
-rw-r--r-- | src/test/java/org/yaml/snakeyaml/issues/issue64/ParameterizedTypeTest.java | 105 |
1 files changed, 52 insertions, 53 deletions
diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue64/ParameterizedTypeTest.java b/src/test/java/org/yaml/snakeyaml/issues/issue64/ParameterizedTypeTest.java index 50c7bc80..828e8c6d 100644 --- a/src/test/java/org/yaml/snakeyaml/issues/issue64/ParameterizedTypeTest.java +++ b/src/test/java/org/yaml/snakeyaml/issues/issue64/ParameterizedTypeTest.java @@ -1,25 +1,21 @@ /** - * Copyright (c) 2008, http://www.snakeyaml.org + * Copyright (c) 2008, SnakeYAML * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.yaml.snakeyaml.issues.issue64; import java.util.LinkedList; import java.util.List; - import junit.framework.TestCase; - import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.AbstractConstruct; import org.yaml.snakeyaml.constructor.Constructor; @@ -31,56 +27,59 @@ import org.yaml.snakeyaml.representer.Representer; public class ParameterizedTypeTest extends TestCase { - public void testRepresenter() { - Yaml yaml = new Yaml(new ClassConstructor(), new ClassRepresenter()); + public void testRepresenter() { + Yaml yaml = new Yaml(new ClassConstructor(), new ClassRepresenter()); + + String methodName = "testMethod"; + List<Class<?>> argTypes = new LinkedList<Class<?>>(); + argTypes.add(String.class); + argTypes.add(Integer.class); + argTypes.add(Boolean.class); + MethodDesc methodDesc = new MethodDesc(methodName, argTypes); - String methodName = "testMethod"; - List<Class<?>> argTypes = new LinkedList<Class<?>>(); - argTypes.add(String.class); - argTypes.add(Integer.class); - argTypes.add(Boolean.class); - MethodDesc methodDesc = new MethodDesc(methodName, argTypes); + String out = yaml.dump(methodDesc); + // System.out.println(out); + assertEquals( + "!!org.yaml.snakeyaml.issues.issue64.MethodDesc\nargTypes: [!clazz 'String', !clazz 'Integer', !clazz 'Boolean']\nname: testMethod\n", + out); + MethodDesc parsed = yaml.load(out); + assertEquals(methodName, parsed.getName()); + List<Class<?>> argTypes2 = parsed.getArgTypes(); + assertEquals(3, argTypes2.size()); + assertEquals(argTypes, argTypes2); + } - String out = yaml.dump(methodDesc); - // System.out.println(out); - assertEquals( - "!!org.yaml.snakeyaml.issues.issue64.MethodDesc\nargTypes: [!clazz 'String', !clazz 'Integer', !clazz 'Boolean']\nname: testMethod\n", - out); - MethodDesc parsed = (MethodDesc) yaml.load(out); - assertEquals(methodName, parsed.getName()); - List<Class<?>> argTypes2 = parsed.getArgTypes(); - assertEquals(3, argTypes2.size()); - assertEquals(argTypes, argTypes2); + static class ClassRepresenter extends Representer { + + public ClassRepresenter() { + this.representers.put(Class.class, new RepresentClass()); } - static class ClassRepresenter extends Representer { - public ClassRepresenter() { - this.representers.put(Class.class, new RepresentClass()); - } + private class RepresentClass implements Represent { - private class RepresentClass implements Represent { - public Node representData(Object data) { - Class<?> clazz = (Class<?>) data; - return representScalar(new Tag("!clazz"), clazz.getSimpleName()); - } - } + public Node representData(Object data) { + Class<?> clazz = (Class<?>) data; + return representScalar(new Tag("!clazz"), clazz.getSimpleName()); + } } + } - static class ClassConstructor extends Constructor { - public ClassConstructor() { - this.yamlConstructors.put(new Tag("!clazz"), new ConstructClass()); - } + static class ClassConstructor extends Constructor { + + public ClassConstructor() { + this.yamlConstructors.put(new Tag("!clazz"), new ConstructClass()); + } - private class ConstructClass extends AbstractConstruct { + private class ConstructClass extends AbstractConstruct { - public Object construct(Node node) { - String clazz = (String) constructScalar((ScalarNode) node); - try { - return Class.forName("java.lang." + clazz); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } + public Object construct(Node node) { + String clazz = constructScalar((ScalarNode) node); + try { + return Class.forName("java.lang." + clazz); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); } + } } + } } |