1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.constructor;
17
18 import java.math.BigDecimal;
19
20 import junit.framework.TestCase;
21
22 import org.yaml.snakeyaml.Yaml;
23
24 public class BigDecimalBeanConstructorTest extends TestCase {
25
26 public void testRepresentor() {
27 BigDecimalJavaBean bean = new BigDecimalJavaBean();
28 bean.setAmount(1.5f);
29 bean.setNumber(new BigDecimal("3.1416"));
30 Yaml yaml = new Yaml();
31 String output = yaml.dump(bean);
32 String className = this.getClass().getPackage().getName();
33 assertEquals("!!" + className + ".BigDecimalJavaBean {amount: 1.5, number: 3.1416}\n",
34 output);
35 }
36
37 public void testConstructor() {
38 String className = "!!" + this.getClass().getPackage().getName()
39 + ".BigDecimalJavaBean {amount: 1.5, number: 3.1416}";
40 Yaml yaml = new Yaml();
41 BigDecimalJavaBean bean = (BigDecimalJavaBean) yaml.load(className);
42 assertNotNull(bean);
43 assertTrue(1.5 - bean.getAmount() < 0.0000001);
44 assertTrue((new BigDecimal("3.1416")).add(bean.getNumber().negate()).doubleValue() < 0.0000001);
45 }
46
47 public void testConstructorAtomic() {
48 String className = "!!" + this.getClass().getPackage().getName()
49 + ".AtomicJavaBean {amount: 1.5, atomic: 0}";
50 Yaml yaml = new Yaml();
51 try {
52 yaml.load(className);
53 fail("AtomicLong is not supported.");
54 } catch (Exception e) {
55 assertEquals(
56 "Cannot create property=atomic for JavaBean=AtomicJavaBean; Unsupported class: class java.util.concurrent.atomic.AtomicLong",
57 e.getCause().getMessage());
58 }
59 }
60 }