aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/yaml/snakeyaml/immutable/MoreImmutablesTest.java
blob: b96b37a58b35a5222800c95ced4478eb8c119bc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
 * Copyright (c) 2008, http://www.snakeyaml.org
 *
 * 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
 *
 * 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.immutable;

import java.awt.Color;
import java.awt.Insets;
import java.awt.Rectangle;

import javax.swing.BorderFactory;
import javax.swing.border.MatteBorder;

import junit.framework.TestCase;

import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

public class MoreImmutablesTest extends TestCase {

    public void testInsets() {
        Yaml yaml = new Yaml(new ImmutablesRepresenter());
        Insets insets = new Insets(10, 20, 30, 40);
        String dump = yaml.dump(insets);
        assertEquals("!!java.awt.Insets [10, 20, 30, 40]\n", dump);
        Object loaded = yaml.load(dump);
        assertEquals(insets, loaded);
    }

    public void testAwtColor() {
        Yaml yaml = new Yaml(new ImmutablesRepresenter());
        Color color = new Color(10, 20, 30, 40);
        String dump = yaml.dump(color);
        assertEquals("!!java.awt.Color [10, 20, 30, 40]\n", dump);
        Object loaded = yaml.load(dump);
        assertEquals(color, loaded);
    }

    public void testRectangle() {
        Yaml yaml = new Yaml(new ImmutablesRepresenter());
        Rectangle rect = new Rectangle(10, 20, 30, 40);
        String dump = yaml.dump(rect);
        assertEquals("!!java.awt.Rectangle [10, 20, 30, 40]\n", dump);
        Object loaded = yaml.load(dump);
        assertEquals(rect, loaded);
    }

    // matteborder - only with color - no icon
    public void testMatteBorder() {
        DumperOptions options = new DumperOptions();
        options.setWidth(400);
        Yaml yaml = new Yaml(new ImmutablesRepresenter(), options);
        Insets insets = new Insets(10, 20, 30, 40);
        Color color = new Color(100, 150, 200);
        MatteBorder border = BorderFactory.createMatteBorder(insets.top, insets.left,
                insets.bottom, insets.right, color);
        String dump = yaml.dump(border);
        assertEquals(
                "!!javax.swing.border.MatteBorder [!!java.awt.Insets [10, 20, 30, 40], !!java.awt.Color [100, 150, 200, 255]]\n",
                dump);
        Object loaded = yaml.load(dump);
        assertTrue(loaded instanceof MatteBorder);
        MatteBorder loadedBorder = (MatteBorder) loaded;
        assertEquals(insets, loadedBorder.getBorderInsets());
        assertEquals(color, loadedBorder.getMatteColor());
    }
}