1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.issues.issue40;
17
18 import java.math.BigDecimal;
19
20 import junit.framework.TestCase;
21
22 import org.yaml.snakeyaml.Yaml;
23
24 public class DogFoodBeanTest extends TestCase {
25
26 public void testOwnBigDecimal() {
27 DogFoodBean input = new DogFoodBean();
28 input.setDecimal(new BigDecimal("5"));
29 Yaml yaml = new Yaml();
30 String text = yaml.dump(input);
31
32 assertEquals("!!org.yaml.snakeyaml.issues.issue40.DogFoodBean {decimal: !!float '5'}\n",
33 text);
34 DogFoodBean output = (DogFoodBean) yaml.load(text);
35 assertEquals(output.getDecimal(), input.getDecimal());
36 }
37
38 public void testBigDecimalPrecision() {
39 DogFoodBean input = new DogFoodBean();
40 input.setDecimal(new BigDecimal("5.123"));
41 Yaml yaml = new Yaml();
42 String text = yaml.dump(input);
43
44 assertEquals("!!org.yaml.snakeyaml.issues.issue40.DogFoodBean {decimal: 5.123}\n", text);
45 DogFoodBean output = (DogFoodBean) yaml.load(text);
46 assertEquals(input.getDecimal(), output.getDecimal());
47 }
48
49 public void testBigDecimalNoRootTag() {
50 DogFoodBean input = new DogFoodBean();
51 input.setDecimal(new BigDecimal("5.123"));
52 Yaml yaml = new Yaml();
53 String text = yaml.dumpAsMap(input);
54
55 assertEquals("decimal: 5.123\n", text);
56 Yaml loader = new Yaml();
57 DogFoodBean output = loader.loadAs(text, DogFoodBean.class);
58 assertEquals(input.getDecimal(), output.getDecimal());
59 }
60
61 public void testBigDecimal1() {
62 Yaml yaml = new Yaml();
63 String text = yaml.dump(new BigDecimal("5"));
64 assertEquals("!!float '5'\n", text);
65 }
66
67 public void testBigDecimal2() {
68 Yaml yaml = new Yaml();
69 String text = yaml.dump(new BigDecimal("5.123"));
70 assertEquals("5.123\n", text);
71 }
72 }