aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/yaml/snakeyaml/javabeans
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/yaml/snakeyaml/javabeans')
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/ConstructEmptyBeanTest.java208
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/Door.java93
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/FrontDoor.java45
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/House.java89
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/HouseTest.java239
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/LongTest.java99
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/Room.java77
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/Shape.java20
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/StringArrayTest.java97
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/Triangle.java39
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/TriangleBean.java55
-rw-r--r--src/test/java/org/yaml/snakeyaml/javabeans/TriangleBeanTest.java101
12 files changed, 571 insertions, 591 deletions
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/ConstructEmptyBeanTest.java b/src/test/java/org/yaml/snakeyaml/javabeans/ConstructEmptyBeanTest.java
index 8dea2315..68306426 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/ConstructEmptyBeanTest.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/ConstructEmptyBeanTest.java
@@ -1,131 +1,127 @@
/**
- * 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.javabeans;
import java.io.Serializable;
-
import junit.framework.TestCase;
-
import org.yaml.snakeyaml.Yaml;
public class ConstructEmptyBeanTest extends TestCase {
- /**
- * standard Yaml
- */
- public void testEmptyBean() {
- Yaml yaml = new Yaml();
- EmptyBean bean = (EmptyBean) yaml
- .load("!!org.yaml.snakeyaml.javabeans.ConstructEmptyBeanTest$EmptyBean {}");
- assertNotNull(bean);
- assertNull(bean.getFirstName());
- assertEquals(5, bean.getHatSize());
- }
- /**
- * global tag is correct (but ignored)
- */
- public void testEmptyBean1() {
- Yaml beanLoader = new Yaml();
- EmptyBean bean = beanLoader.loadAs(
- "!!org.yaml.snakeyaml.javabeans.ConstructEmptyBeanTest$EmptyBean {}",
- EmptyBean.class);
- assertNotNull(bean);
- assertNull(bean.getFirstName());
- assertEquals(5, bean.getHatSize());
+ /**
+ * standard Yaml
+ */
+ public void testEmptyBean() {
+ Yaml yaml = new Yaml();
+ EmptyBean bean =
+ yaml.load("!!org.yaml.snakeyaml.javabeans.ConstructEmptyBeanTest$EmptyBean {}");
+ assertNotNull(bean);
+ assertNull(bean.getFirstName());
+ assertEquals(5, bean.getHatSize());
+ }
+
+ /**
+ * global tag is correct (but ignored)
+ */
+ public void testEmptyBean1() {
+ Yaml beanLoader = new Yaml();
+ EmptyBean bean = beanLoader.loadAs(
+ "!!org.yaml.snakeyaml.javabeans.ConstructEmptyBeanTest$EmptyBean {}", EmptyBean.class);
+ assertNotNull(bean);
+ assertNull(bean.getFirstName());
+ assertEquals(5, bean.getHatSize());
+ }
+
+ /**
+ * global tag is ignored
+ */
+ public void testEmptyBean2() {
+ Yaml beanLoader = new Yaml();
+ EmptyBean bean = beanLoader.loadAs("!!Bla-bla-bla {}", EmptyBean.class);
+ assertNotNull(bean);
+ assertNull(bean.getFirstName());
+ assertEquals(5, bean.getHatSize());
+ }
+
+ /**
+ * no tag
+ */
+ public void testEmptyBean3() {
+ Yaml beanLoader = new Yaml();
+ EmptyBean bean = beanLoader.loadAs("{ }", EmptyBean.class);
+ assertNotNull(bean);
+ assertNull(bean.getFirstName());
+ assertEquals(5, bean.getHatSize());
+ }
+
+ /**
+ * empty document
+ */
+ public void testEmptyBean4() {
+ Yaml beanLoader = new Yaml();
+ EmptyBean bean = beanLoader.loadAs("", EmptyBean.class);
+ assertNull(bean);
+ }
+
+ /**
+ * local tag is ignored
+ */
+ public void testEmptyBean5() {
+ Yaml beanLoader = new Yaml();
+ EmptyBean bean = beanLoader.loadAs("!Bla-bla-bla {}", EmptyBean.class);
+ assertNotNull(bean);
+ assertNull(bean.getFirstName());
+ assertEquals(5, bean.getHatSize());
+ }
+
+ /**
+ * invalid document
+ */
+ public void testEmptyBean6() {
+ Yaml beanLoader = new Yaml();
+ try {
+ beanLoader.loadAs("{", EmptyBean.class);
+ fail("Invalid document provided.");
+ } catch (Exception e) {
+ assertEquals("while parsing a flow node\n" + " in 'string', line 1, column 2:\n" + " {\n"
+ + " ^\n" + "expected the node content, but found '<stream end>'\n"
+ + " in 'string', line 1, column 2:\n" + " {\n" + " ^\n", e.getMessage());
}
+ }
- /**
- * global tag is ignored
- */
- public void testEmptyBean2() {
- Yaml beanLoader = new Yaml();
- EmptyBean bean = beanLoader.loadAs("!!Bla-bla-bla {}", EmptyBean.class);
- assertNotNull(bean);
- assertNull(bean.getFirstName());
- assertEquals(5, bean.getHatSize());
- }
+ public static class EmptyBean implements Serializable {
- /**
- * no tag
- */
- public void testEmptyBean3() {
- Yaml beanLoader = new Yaml();
- EmptyBean bean = beanLoader.loadAs("{ }", EmptyBean.class);
- assertNotNull(bean);
- assertNull(bean.getFirstName());
- assertEquals(5, bean.getHatSize());
- }
+ private static final long serialVersionUID = -8001155967276657180L;
+ private String firstName;
+ private int hatSize = 5;
- /**
- * empty document
- */
- public void testEmptyBean4() {
- Yaml beanLoader = new Yaml();
- EmptyBean bean = beanLoader.loadAs("", EmptyBean.class);
- assertNull(bean);
- }
+ public EmptyBean() {}
- /**
- * local tag is ignored
- */
- public void testEmptyBean5() {
- Yaml beanLoader = new Yaml();
- EmptyBean bean = beanLoader.loadAs("!Bla-bla-bla {}", EmptyBean.class);
- assertNotNull(bean);
- assertNull(bean.getFirstName());
- assertEquals(5, bean.getHatSize());
+ public String getFirstName() {
+ return firstName;
}
- /**
- * invalid document
- */
- public void testEmptyBean6() {
- Yaml beanLoader = new Yaml();
- try {
- beanLoader.loadAs("{", EmptyBean.class);
- fail("Invalid document provided.");
- } catch (Exception e) {
- assertEquals("while parsing a flow node\n" + " in 'string', line 1, column 2:\n"
- + " {\n" + " ^\n" + "expected the node content, but found StreamEnd\n"
- + " in 'string', line 1, column 2:\n" + " {\n" + " ^\n", e.getMessage());
- }
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
}
- public static class EmptyBean implements Serializable {
- private static final long serialVersionUID = -8001155967276657180L;
- private String firstName;
- private int hatSize = 5;
-
- public EmptyBean() {
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public int getHatSize() {
- return hatSize;
- }
+ public int getHatSize() {
+ return hatSize;
+ }
- public void setHatSize(int hatSize) {
- this.hatSize = hatSize;
- }
+ public void setHatSize(int hatSize) {
+ this.hatSize = hatSize;
}
+ }
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/Door.java b/src/test/java/org/yaml/snakeyaml/javabeans/Door.java
index 7e3ad133..68b61ac0 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/Door.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/Door.java
@@ -1,67 +1,66 @@
/**
- * 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.javabeans;
public class Door {
- private String id;
- private int height;
- public Door(String id, int height) {
- this.id = id;
- this.height = height;
- }
+ private String id;
+ private int height;
- public Door() {
- this.height = 3;
- }
+ public Door(String id, int height) {
+ this.id = id;
+ this.height = height;
+ }
- public int getHeight() {
- return height;
- }
+ public Door() {
+ this.height = 3;
+ }
- public void setHeight(int height) {
- this.height = height;
- }
+ public int getHeight() {
+ return height;
+ }
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof Door) {
- Door door = (Door) obj;
- return id.equals(door.id);
- } else {
- return false;
- }
- }
+ public void setHeight(int height) {
+ this.height = height;
+ }
- @Override
- public int hashCode() {
- return id.hashCode();
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Door) {
+ Door door = (Door) obj;
+ return id.equals(door.id);
+ } else {
+ return false;
}
+ }
- public String getId() {
- return id;
- }
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
- public void setId(String id) {
- this.id = id;
- }
+ public String getId() {
+ return id;
+ }
- @Override
- public String toString() {
- return "Door id=" + id;
- }
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String toString() {
+ return "Door id=" + id;
+ }
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/FrontDoor.java b/src/test/java/org/yaml/snakeyaml/javabeans/FrontDoor.java
index 2b958da7..0bf99b7b 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/FrontDoor.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/FrontDoor.java
@@ -1,37 +1,36 @@
/**
- * 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.javabeans;
public class FrontDoor extends Door {
- private String keytype;
- public FrontDoor() {
- super();
- }
+ private String keytype;
- public FrontDoor(String id, int height) {
- super(id, height);
- }
+ public FrontDoor() {
+ super();
+ }
- public String getKeytype() {
- return keytype;
- }
+ public FrontDoor(String id, int height) {
+ super(id, height);
+ }
- public void setKeytype(String keytype) {
- this.keytype = keytype;
- }
+ public String getKeytype() {
+ return keytype;
+ }
+
+ public void setKeytype(String keytype) {
+ this.keytype = keytype;
+ }
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/House.java b/src/test/java/org/yaml/snakeyaml/javabeans/House.java
index 41ba335a..81190bde 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/House.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/House.java
@@ -1,17 +1,15 @@
/**
- * 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.javabeans;
@@ -19,50 +17,51 @@ import java.util.List;
import java.util.Map;
public class House {
- private String street;
- private int number;
- private List<Room> rooms;
- private FrontDoor frontDoor;
- private Map<String, String> reminders;
- public String getStreet() {
- return street;
- }
+ private String street;
+ private int number;
+ private List<Room> rooms;
+ private FrontDoor frontDoor;
+ private Map<String, String> reminders;
- public void setStreet(String street) {
- this.street = street;
- }
+ public String getStreet() {
+ return street;
+ }
- public int getNumber() {
- return number;
- }
+ public void setStreet(String street) {
+ this.street = street;
+ }
- public void setNumber(int number) {
- this.number = number;
- }
+ public int getNumber() {
+ return number;
+ }
- public List<Room> getRooms() {
- return rooms;
- }
+ public void setNumber(int number) {
+ this.number = number;
+ }
- public void setRooms(List<Room> rooms) {
- this.rooms = rooms;
- }
+ public List<Room> getRooms() {
+ return rooms;
+ }
- public FrontDoor getFrontDoor() {
- return frontDoor;
- }
+ public void setRooms(List<Room> rooms) {
+ this.rooms = rooms;
+ }
- public void setFrontDoor(FrontDoor frontDoor) {
- this.frontDoor = frontDoor;
- }
+ public FrontDoor getFrontDoor() {
+ return frontDoor;
+ }
- public Map<String, String> getReminders() {
- return reminders;
- }
+ public void setFrontDoor(FrontDoor frontDoor) {
+ this.frontDoor = frontDoor;
+ }
- public void setReminders(Map<String, String> reminders) {
- this.reminders = reminders;
- }
+ public Map<String, String> getReminders() {
+ return reminders;
+ }
+
+ public void setReminders(Map<String, String> reminders) {
+ this.reminders = reminders;
+ }
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/HouseTest.java b/src/test/java/org/yaml/snakeyaml/javabeans/HouseTest.java
index 97c69338..367493c7 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/HouseTest.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/HouseTest.java
@@ -1,17 +1,15 @@
/**
- * 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.javabeans;
@@ -19,9 +17,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-
import junit.framework.TestCase;
-
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
import org.yaml.snakeyaml.TypeDescription;
@@ -30,115 +26,116 @@ import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
public class HouseTest extends TestCase {
- /**
- * no root global tag
- */
- public void testDump1() {
- House house = new House();
- FrontDoor frontDoor = new FrontDoor("qaz1", 5);
- frontDoor.setKeytype("qwerty123");
- house.setFrontDoor(frontDoor);
- List<Room> rooms = new ArrayList<Room>();
- rooms.add(new Room("Hall"));
- rooms.add(new Room("Kitchen"));
- house.setRooms(rooms);
- Map<String, String> reminders = new TreeMap<String, String>();
- reminders.put("today", "do nothig");
- reminders.put("tomorrow", "go shoping");
- house.setReminders(reminders);
- house.setNumber(1);
- house.setStreet("Wall Street");
- Yaml beanDumper = new Yaml();
- String yaml = beanDumper.dumpAsMap(house);
- String etalon = Util.getLocalResource("javabeans/house-dump1.yaml");
- assertEquals(etalon, yaml);
- // load
- Yaml beanLoader = new Yaml();
- House loadedHouse = beanLoader.loadAs(yaml, House.class);
- assertNotNull(loadedHouse);
- assertEquals("Wall Street", loadedHouse.getStreet());
- // dump again
- String yaml3 = beanDumper.dumpAsMap(loadedHouse);
- assertEquals(yaml, yaml3);
- }
- /**
- * with global root class tag (global tag should be avoided)
- */
- public void testDump3() {
- House house = new House();
- FrontDoor frontDoor = new FrontDoor("qaz1", 5);
- frontDoor.setKeytype("qwerty123");
- house.setFrontDoor(frontDoor);
- List<Room> rooms = new ArrayList<Room>();
- rooms.add(new Room("Hall"));
- rooms.add(new Room("Kitchen"));
- house.setRooms(rooms);
- Map<String, String> reminders = new TreeMap<String, String>();
- reminders.put("today", "do nothig");
- reminders.put("tomorrow", "go shoping");
- house.setReminders(reminders);
- house.setNumber(1);
- house.setStreet("Wall Street");
- Yaml beanDumper = new Yaml();
- String yaml = beanDumper.dumpAsMap(house);
- String etalon = Util.getLocalResource("javabeans/house-dump3.yaml");
- assertEquals(etalon, yaml);
- // load
- TypeDescription description = new TypeDescription(House.class);
- description.putListPropertyType("rooms", Room.class);
- Yaml beanLoader = new Yaml(new Constructor(description));
- House loadedHouse = (House) beanLoader.load(yaml);
- House loadedHouse2 = (House) beanLoader.loadAs(yaml, House.class);
- assertNotNull(loadedHouse);
- assertFalse(loadedHouse == loadedHouse2);
- assertEquals("Wall Street", loadedHouse.getStreet());
- assertEquals(1, loadedHouse.getNumber());
- assertEquals(1, loadedHouse2.getNumber());
- FrontDoor fdoor = loadedHouse.getFrontDoor();
- assertEquals(frontDoor.getId(), fdoor.getId());
- assertEquals(frontDoor.getHeight(), fdoor.getHeight());
- assertEquals(frontDoor.getKeytype(), fdoor.getKeytype());
- assertEquals(frontDoor, fdoor);
- assertEquals(reminders, loadedHouse.getReminders());
- List<Room> loadedRooms = loadedHouse.getRooms();
- assertEquals(rooms, loadedRooms);
- // dump again
- String yaml3 = beanDumper.dumpAsMap(loadedHouse);
- assertEquals(yaml, yaml3);
- }
+ /**
+ * no root global tag
+ */
+ public void testDump1() {
+ House house = new House();
+ FrontDoor frontDoor = new FrontDoor("qaz1", 5);
+ frontDoor.setKeytype("qwerty123");
+ house.setFrontDoor(frontDoor);
+ List<Room> rooms = new ArrayList<Room>();
+ rooms.add(new Room("Hall"));
+ rooms.add(new Room("Kitchen"));
+ house.setRooms(rooms);
+ Map<String, String> reminders = new TreeMap<String, String>();
+ reminders.put("today", "do nothig");
+ reminders.put("tomorrow", "go shoping");
+ house.setReminders(reminders);
+ house.setNumber(1);
+ house.setStreet("Wall Street");
+ Yaml beanDumper = new Yaml();
+ String yaml = beanDumper.dumpAsMap(house);
+ String etalon = Util.getLocalResource("javabeans/house-dump1.yaml");
+ assertEquals(etalon, yaml);
+ // load
+ Yaml beanLoader = new Yaml();
+ House loadedHouse = beanLoader.loadAs(yaml, House.class);
+ assertNotNull(loadedHouse);
+ assertEquals("Wall Street", loadedHouse.getStreet());
+ // dump again
+ String yaml3 = beanDumper.dumpAsMap(loadedHouse);
+ assertEquals(yaml, yaml3);
+ }
+
+ /**
+ * with global root class tag (global tag should be avoided)
+ */
+ public void testDump3() {
+ House house = new House();
+ FrontDoor frontDoor = new FrontDoor("qaz1", 5);
+ frontDoor.setKeytype("qwerty123");
+ house.setFrontDoor(frontDoor);
+ List<Room> rooms = new ArrayList<Room>();
+ rooms.add(new Room("Hall"));
+ rooms.add(new Room("Kitchen"));
+ house.setRooms(rooms);
+ Map<String, String> reminders = new TreeMap<String, String>();
+ reminders.put("today", "do nothig");
+ reminders.put("tomorrow", "go shoping");
+ house.setReminders(reminders);
+ house.setNumber(1);
+ house.setStreet("Wall Street");
+ Yaml beanDumper = new Yaml();
+ String yaml = beanDumper.dumpAsMap(house);
+ String etalon = Util.getLocalResource("javabeans/house-dump3.yaml");
+ assertEquals(etalon, yaml);
+ // load
+ TypeDescription description = new TypeDescription(House.class);
+ description.putListPropertyType("rooms", Room.class);
+ Yaml beanLoader = new Yaml(new Constructor(description));
+ House loadedHouse = beanLoader.load(yaml);
+ House loadedHouse2 = beanLoader.loadAs(yaml, House.class);
+ assertNotNull(loadedHouse);
+ assertNotSame(loadedHouse, loadedHouse2);
+ assertEquals("Wall Street", loadedHouse.getStreet());
+ assertEquals(1, loadedHouse.getNumber());
+ assertEquals(1, loadedHouse2.getNumber());
+ FrontDoor fdoor = loadedHouse.getFrontDoor();
+ assertEquals(frontDoor.getId(), fdoor.getId());
+ assertEquals(frontDoor.getHeight(), fdoor.getHeight());
+ assertEquals(frontDoor.getKeytype(), fdoor.getKeytype());
+ assertEquals(frontDoor, fdoor);
+ assertEquals(reminders, loadedHouse.getReminders());
+ List<Room> loadedRooms = loadedHouse.getRooms();
+ assertEquals(rooms, loadedRooms);
+ // dump again
+ String yaml3 = beanDumper.dumpAsMap(loadedHouse);
+ assertEquals(yaml, yaml3);
+ }
- /**
- * with global root class tag (global tag should be avoided)
- */
- public void testDump2() {
- House house = new House();
- FrontDoor frontDoor = new FrontDoor("qaz1", 5);
- frontDoor.setKeytype("qwerty123");
- house.setFrontDoor(frontDoor);
- List<Room> rooms = new ArrayList<Room>();
- rooms.add(new Room("Hall"));
- rooms.add(new Room("Kitchen"));
- house.setRooms(rooms);
- Map<String, String> reminders = new TreeMap<String, String>();
- reminders.put("today", "do nothig");
- reminders.put("tomorrow", "go shoping");
- house.setReminders(reminders);
- house.setNumber(1);
- house.setStreet("Wall Street");
- DumperOptions options = new DumperOptions();
- options.setDefaultFlowStyle(FlowStyle.BLOCK);
- Yaml beanDumper = new Yaml(options);
- String yaml = beanDumper.dump(house);
- String etalon = Util.getLocalResource("javabeans/house-dump2.yaml");
- assertEquals(etalon, yaml);
- // load
- Yaml beanLoader = new Yaml();
- House loadedHouse = beanLoader.loadAs(yaml, House.class);
- assertNotNull(loadedHouse);
- assertEquals("Wall Street", loadedHouse.getStreet());
- // dump again
- String yaml3 = beanDumper.dump(loadedHouse);
- assertEquals(yaml, yaml3);
- }
+ /**
+ * with global root class tag (global tag should be avoided)
+ */
+ public void testDump2() {
+ House house = new House();
+ FrontDoor frontDoor = new FrontDoor("qaz1", 5);
+ frontDoor.setKeytype("qwerty123");
+ house.setFrontDoor(frontDoor);
+ List<Room> rooms = new ArrayList<Room>();
+ rooms.add(new Room("Hall"));
+ rooms.add(new Room("Kitchen"));
+ house.setRooms(rooms);
+ Map<String, String> reminders = new TreeMap<String, String>();
+ reminders.put("today", "do nothig");
+ reminders.put("tomorrow", "go shoping");
+ house.setReminders(reminders);
+ house.setNumber(1);
+ house.setStreet("Wall Street");
+ DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(FlowStyle.BLOCK);
+ Yaml beanDumper = new Yaml(options);
+ String yaml = beanDumper.dump(house);
+ String etalon = Util.getLocalResource("javabeans/house-dump2.yaml");
+ assertEquals(etalon, yaml);
+ // load
+ Yaml beanLoader = new Yaml();
+ House loadedHouse = beanLoader.loadAs(yaml, House.class);
+ assertNotNull(loadedHouse);
+ assertEquals("Wall Street", loadedHouse.getStreet());
+ // dump again
+ String yaml3 = beanDumper.dump(loadedHouse);
+ assertEquals(yaml, yaml3);
+ }
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/LongTest.java b/src/test/java/org/yaml/snakeyaml/javabeans/LongTest.java
index 7b7deaf3..16d2cc84 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/LongTest.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/LongTest.java
@@ -1,73 +1,72 @@
/**
- * 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.javabeans;
import junit.framework.TestCase;
-
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
public class LongTest extends TestCase {
- public void testLongFail() {
- DumperOptions options = new DumperOptions();
- options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
- Yaml yaml = new Yaml(options);
- Foo foo = new Foo();
- String output = yaml.dump(foo);
- // System.out.println(output);
- try {
- yaml.load(output);
- } catch (Exception e) {
- assertTrue(e.getMessage(), e.getMessage().contains("argument type mismatch"));
- }
+
+ public void testLongFail() {
+ DumperOptions options = new DumperOptions();
+ options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
+ Yaml yaml = new Yaml(options);
+ Foo foo = new Foo();
+ String output = yaml.dump(foo);
+ // System.out.println(output);
+ try {
+ yaml.load(output);
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), e.getMessage().contains("argument type mismatch"));
}
+ }
- public static class Foo {
- private Long bar = Long.valueOf(42L);
+ public static class Foo {
- public Long getBar() {
- return bar;
- }
+ private Long bar = Long.valueOf(42L);
- public void setBar(Long bar) {
- this.bar = bar;
- }
+ public Long getBar() {
+ return bar;
}
- public void testLongRepresenter() {
- DumperOptions options = new DumperOptions();
- options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
- Representer repr = new Representer();
- repr.addClassTag(Long.class, new Tag("!!java.lang.Long"));
- Yaml yaml = new Yaml(repr, options);
-
- Foo foo = new Foo();
- String output = yaml.dump(foo);
- // System.out.println(output);
- Foo foo2 = (Foo) yaml.load(output);
- assertEquals(new Long(42L), foo2.getBar());
+ public void setBar(Long bar) {
+ this.bar = bar;
}
+ }
- public void testLongConstructor() {
- String doc = "!!org.yaml.snakeyaml.javabeans.LongTest$Foo\n\"bar\": !!int \"42\"";
- // System.out.println(doc);
- Yaml yaml = new Yaml();
- Foo foo2 = (Foo) yaml.load(doc);
- assertEquals(new Long(42L), foo2.getBar());
- }
+ public void testLongRepresenter() {
+ DumperOptions options = new DumperOptions();
+ options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
+ Representer repr = new Representer();
+ repr.addClassTag(Long.class, new Tag("!!java.lang.Long"));
+ Yaml yaml = new Yaml(repr, options);
+
+ Foo foo = new Foo();
+ String output = yaml.dump(foo);
+ // System.out.println(output);
+ Foo foo2 = yaml.load(output);
+ assertEquals(Long.valueOf(42L), foo2.getBar());
+ }
+
+ public void testLongConstructor() {
+ String doc = "!!org.yaml.snakeyaml.javabeans.LongTest$Foo\n\"bar\": !!int \"42\"";
+ // System.out.println(doc);
+ Yaml yaml = new Yaml();
+ Foo foo2 = yaml.load(doc);
+ assertEquals(Long.valueOf(42L), foo2.getBar());
+ }
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/Room.java b/src/test/java/org/yaml/snakeyaml/javabeans/Room.java
index 31e0ebde..4332d9a5 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/Room.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/Room.java
@@ -1,57 +1,56 @@
/**
- * 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.javabeans;
public class Room {
- private String name;
- public Room() {
- this.name = "Bedroom";
- }
+ private String name;
- public Room(String name) {
- this.name = name;
- }
+ public Room() {
+ this.name = "Bedroom";
+ }
- public String getName() {
- return name;
- }
+ public Room(String name) {
+ this.name = name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ public String getName() {
+ return name;
+ }
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof Room) {
- Room room = (Room) obj;
- return name.equals(room.name);
- } else {
- return false;
- }
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- @Override
- public int hashCode() {
- return name.hashCode();
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Room) {
+ Room room = (Room) obj;
+ return name.equals(room.name);
+ } else {
+ return false;
}
+ }
- @Override
- public String toString() {
- return "Room name=" + name;
- }
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "Room name=" + name;
+ }
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/Shape.java b/src/test/java/org/yaml/snakeyaml/javabeans/Shape.java
index ec086e48..29e7ad13 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/Shape.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/Shape.java
@@ -1,21 +1,19 @@
/**
- * 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.javabeans;
public interface Shape {
- public int process();
+ int process();
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/StringArrayTest.java b/src/test/java/org/yaml/snakeyaml/javabeans/StringArrayTest.java
index 5a380491..4fcb1afb 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/StringArrayTest.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/StringArrayTest.java
@@ -1,70 +1,69 @@
/**
- * 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.javabeans;
-import java.util.Arrays;
+import static org.junit.Assert.assertArrayEquals;
import junit.framework.TestCase;
-
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
public class StringArrayTest extends TestCase {
- public void testStrings() {
- A a = new A();
- a.setNames(new String[] { "aaa", "bbb", "ccc" });
- Yaml yaml = new Yaml();
- String output = yaml.dump(a);
- assertEquals("!!org.yaml.snakeyaml.javabeans.StringArrayTest$A\nnames: [aaa, bbb, ccc]\n",
- output);
- A b = (A) yaml.load(output);
- assertTrue(Arrays.equals(a.getNames(), b.getNames()));
- }
- public void testStringsPretty() {
- A a = new A();
- a.setNames(new String[] { "aaa", "bbb", "ccc" });
- DumperOptions options = new DumperOptions();
- options.setPrettyFlow(true);
- Yaml yaml = new Yaml(options);
- String output = yaml.dump(a);
- assertEquals(
- "!!org.yaml.snakeyaml.javabeans.StringArrayTest$A\nnames: [\n aaa,\n bbb,\n ccc]\n",
- output);
- A b = (A) yaml.load(output);
- assertTrue(Arrays.equals(a.getNames(), b.getNames()));
- }
+ public void testStrings() {
+ A a = new A();
+ a.setNames(new String[] {"aaa", "bbb", "ccc"});
+ Yaml yaml = new Yaml();
+ String output = yaml.dump(a);
+ assertEquals("!!org.yaml.snakeyaml.javabeans.StringArrayTest$A\nnames: [aaa, bbb, ccc]\n",
+ output);
+ A b = yaml.load(output);
+ assertArrayEquals(a.getNames(), b.getNames());
+ }
+
+ public void testStringsPretty() {
+ A a = new A();
+ a.setNames(new String[] {"aaa", "bbb", "ccc"});
+ DumperOptions options = new DumperOptions();
+ options.setPrettyFlow(true);
+ Yaml yaml = new Yaml(options);
+ String output = yaml.dump(a);
+ assertEquals(
+ "!!org.yaml.snakeyaml.javabeans.StringArrayTest$A\nnames: [\n aaa,\n bbb,\n ccc\n]\n",
+ output);
+ A b = yaml.load(output);
+ assertArrayEquals(a.getNames(), b.getNames());
+ }
- public static class A {
- String[] names;
+ public static class A {
- public String[] getNames() {
- return names;
- }
+ String[] names;
- public void setNames(String[] names) {
- this.names = names;
- }
+ public String[] getNames() {
+ return names;
+ }
+
+ public void setNames(String[] names) {
+ this.names = names;
+ }
- public String getName(int index) {
- return names[index];
- }
+ public String getName(int index) {
+ return names[index];
+ }
- public void setName(int index, String name) {
- this.names[index] = name;
- }
+ public void setName(int index, String name) {
+ this.names[index] = name;
}
+ }
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/Triangle.java b/src/test/java/org/yaml/snakeyaml/javabeans/Triangle.java
index 10acc6dc..6476dbc9 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/Triangle.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/Triangle.java
@@ -1,32 +1,31 @@
/**
- * 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.javabeans;
public class Triangle implements Shape {
- private String name;
- public String getName() {
- return name;
- }
+ private String name;
- public void setName(String name) {
- this.name = name;
- }
+ public String getName() {
+ return name;
+ }
- public int process() {
- return 7;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int process() {
+ return 7;
+ }
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/TriangleBean.java b/src/test/java/org/yaml/snakeyaml/javabeans/TriangleBean.java
index 68930902..9f459047 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/TriangleBean.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/TriangleBean.java
@@ -1,42 +1,41 @@
/**
- * 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.javabeans;
public class TriangleBean {
- private String name;
- private Shape shape;
- public String getName() {
- return name;
- }
+ private String name;
+ private Shape shape;
- public void setName(String name) {
- this.name = name;
- }
+ public String getName() {
+ return name;
+ }
- public Shape getShape() {
- return shape;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setShape(Shape shape) {
- this.shape = shape;
- }
+ public Shape getShape() {
+ return shape;
+ }
- @Override
- public String toString() {
- return "TriangleBean name=" + name;
- }
+ public void setShape(Shape shape) {
+ this.shape = shape;
+ }
+
+ @Override
+ public String toString() {
+ return "TriangleBean name=" + name;
+ }
}
diff --git a/src/test/java/org/yaml/snakeyaml/javabeans/TriangleBeanTest.java b/src/test/java/org/yaml/snakeyaml/javabeans/TriangleBeanTest.java
index 8e84e753..a5448eb8 100644
--- a/src/test/java/org/yaml/snakeyaml/javabeans/TriangleBeanTest.java
+++ b/src/test/java/org/yaml/snakeyaml/javabeans/TriangleBeanTest.java
@@ -1,69 +1,66 @@
/**
- * 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.javabeans;
import junit.framework.TestCase;
-
import org.yaml.snakeyaml.Yaml;
public class TriangleBeanTest extends TestCase {
- public void testGetTriangle() {
- Triangle triangle = new Triangle();
- triangle.setName("Triangle25");
- TriangleBean bean = new TriangleBean();
- bean.setShape(triangle);
- bean.setName("Bean25");
- Yaml beanDumper = new Yaml();
- String output = beanDumper.dumpAsMap(bean);
- assertEquals(
- "name: Bean25\nshape: !!org.yaml.snakeyaml.javabeans.Triangle\n name: Triangle25\n",
- output);
- Yaml beanLoader = new Yaml();
- TriangleBean loadedBean = beanLoader.loadAs(output, TriangleBean.class);
- assertNotNull(loadedBean);
- assertEquals("Bean25", loadedBean.getName());
- assertEquals(7, loadedBean.getShape().process());
- }
+ public void testGetTriangle() {
+ Triangle triangle = new Triangle();
+ triangle.setName("Triangle25");
+ TriangleBean bean = new TriangleBean();
+ bean.setShape(triangle);
+ bean.setName("Bean25");
+ Yaml beanDumper = new Yaml();
+ String output = beanDumper.dumpAsMap(bean);
+ assertEquals(
+ "name: Bean25\nshape: !!org.yaml.snakeyaml.javabeans.Triangle\n name: Triangle25\n",
+ output);
+ Yaml beanLoader = new Yaml();
+ TriangleBean loadedBean = beanLoader.loadAs(output, TriangleBean.class);
+ assertNotNull(loadedBean);
+ assertEquals("Bean25", loadedBean.getName());
+ assertEquals(7, loadedBean.getShape().process());
+ }
- public void testClassNotFound() {
- String output = "name: Bean25\nshape: !!org.yaml.snakeyaml.javabeans.Triangle777\n name: Triangle25\n";
- Yaml beanLoader = new Yaml();
- try {
- beanLoader.loadAs(output, TriangleBean.class);
- fail("Class not found expected.");
- } catch (Exception e) {
- assertTrue(
- e.getMessage(),
- e.getMessage().contains(
- "Class not found: org.yaml.snakeyaml.javabeans.Triangle777"));
- }
+ public void testClassNotFound() {
+ String output =
+ "name: Bean25\nshape: !!org.yaml.snakeyaml.javabeans.Triangle777\n name: Triangle25\n";
+ Yaml beanLoader = new Yaml();
+ try {
+ beanLoader.loadAs(output, TriangleBean.class);
+ fail("Class not found expected.");
+ } catch (Exception e) {
+ assertTrue(e.getMessage(),
+ e.getMessage().contains("Class not found: org.yaml.snakeyaml.javabeans.Triangle777"));
}
+ }
- /**
- * Runtime class has less priority then an explicit tag
- */
- public void testClassAndTag() {
- String output = "name: !!whatever Bean25\nshape: !!org.yaml.snakeyaml.javabeans.Triangle\n name: Triangle25\n";
- Yaml beanLoader = new Yaml();
- try {
- beanLoader.loadAs(output, TriangleBean.class);
- fail("Runtime class has less priority then an explicit tag");
- } catch (Exception e) {
- assertTrue(e.getMessage(), e.getMessage().contains("Class not found: whatever"));
- }
+ /**
+ * Runtime class has less priority then an explicit tag
+ */
+ public void testClassAndTag() {
+ String output =
+ "name: !!whatever Bean25\nshape: !!org.yaml.snakeyaml.javabeans.Triangle\n name: Triangle25\n";
+ Yaml beanLoader = new Yaml();
+ try {
+ beanLoader.loadAs(output, TriangleBean.class);
+ fail("Runtime class has less priority then an explicit tag");
+ } catch (Exception e) {
+ assertTrue(e.getMessage(), e.getMessage().contains("Class not found: whatever"));
}
+ }
}