1/**
2 * Copyright (c) 2008, http://www.snakeyaml.org
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package examples;
17
18import java.io.StringReader;
19
20import junit.framework.TestCase;
21
22import org.yaml.snakeyaml.Yaml;
23
24public class CustomJavaObjectWithBinaryStringTest extends TestCase {
25    public static class Pojo {
26        private String data;
27
28        public Pojo() {
29        }
30
31        public Pojo(String data) {
32            this.data = data;
33        }
34
35        public String getData() {
36            return data;
37        }
38
39        public void setData(String data) {
40            this.data = data;
41        }
42
43        @Override public int hashCode() {
44            final int prime = 31;
45            int result = 1;
46            result = prime * result + ((data == null) ? 0 : data.hashCode());
47            return result;
48        }
49
50        @Override public boolean equals(Object obj) {
51            if (this == obj)
52                return true;
53            if (obj == null)
54                return false;
55            if (getClass() != obj.getClass())
56                return false;
57            Pojo other = (Pojo) obj;
58            if (data == null) {
59                if (other.data != null)
60                    return false;
61            } else if (!data.equals(other.data))
62                return false;
63            return true;
64        }
65
66    }
67
68    public void testDump() {
69        Yaml yaml = new Yaml();
70        Pojo expected = new Pojo(new String(new byte[] { 13, 14, 15, 16 }));
71        String output = yaml.dump(expected);
72
73        assertTrue(output.contains("data: !!binary |-"));
74        assertTrue(output.contains("DQ4PEA=="));
75
76        Pojo actual = (Pojo) yaml.load(new StringReader(output));
77        assertEquals(expected, actual);
78    }
79
80}
81