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