SetTagTest.java revision b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2
1b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov/**
2b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * Copyright (c) 2008-2011, http://www.snakeyaml.org
3b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov *
4b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * Licensed under the Apache License, Version 2.0 (the "License");
5b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * you may not use this file except in compliance with the License.
6b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * You may obtain a copy of the License at
7b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov *
8b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov *     http://www.apache.org/licenses/LICENSE-2.0
9b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov *
10b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * Unless required by applicable law or agreed to in writing, software
11b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * distributed under the License is distributed on an "AS IS" BASIS,
12b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * See the License for the specific language governing permissions and
14b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * limitations under the License.
15b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov */
16b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov
17b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somovpackage org.yaml.snakeyaml.types;
18b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov
19b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somovimport java.util.Map;
20b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somovimport java.util.Set;
21b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov
22b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somovimport org.yaml.snakeyaml.YamlDocument;
23b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov
24b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov/**
25b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov * @see http://yaml.org/type/set.html
26b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov */
27b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somovpublic class SetTagTest extends AbstractTest {
28b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov
29b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov    @SuppressWarnings("unchecked")
30b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov    public void testSet() {
31b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        YamlDocument document = new YamlDocument("types/set.yaml");
32b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        Map<String, Set<String>> map = (Map<String, Set<String>>) document.getNativeData();
33b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        assertEquals(2, map.size());
34b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        Set<String> set1 = (Set<String>) map.get("baseball players");
35b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        assertEquals(3, set1.size());
36b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        assertTrue(set1.contains("Mark McGwire"));
37b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        assertTrue(set1.contains("Sammy Sosa"));
38b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        assertTrue(set1.contains("Ken Griffey"));
39b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        //
40b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        Set<String> set2 = (Set<String>) map.get("baseball teams");
41b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        assertEquals(3, set2.size());
42b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        assertTrue(set2.contains("Boston Red Sox"));
43b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        assertTrue(set2.contains("Detroit Tigers"));
44b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov        assertTrue(set2.contains("New York Yankees"));
45b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov    }
46b5f4ec3dfb1a49968ebcc1243da10af9a2dc54a2Andrey Somov}
47