@@ -0,0 +1,2251 @@
+/**%0A * Copyright (c) 2008-2012, http://www.snakeyaml.org%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.yaml.snakeyaml.issues.issue139;%0A%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Aimport junit.framework.TestCase;%0A%0Aimport org.yaml.snakeyaml.Yaml;%0Aimport org.yaml.snakeyaml.constructor.Constructor;%0Aimport org.yaml.snakeyaml.error.YAMLException;%0Aimport org.yaml.snakeyaml.nodes.MappingNode;%0Aimport org.yaml.snakeyaml.nodes.Node;%0Aimport org.yaml.snakeyaml.nodes.NodeTuple;%0A%0Apublic class UniqueKeyTest extends TestCase %7B%0A%0A    public void testNotUnique() %7B%0A        String data = %22%7Bkey: 1, key: 2%7D%22;%0A        Yaml yaml = new Yaml(new UniqueKeyConstructor());%0A        try %7B%0A            yaml.load(data);%0A            fail(%22The same key must be rejected%22);%0A        %7D catch (Exception e) %7B%0A            assertEquals(%22The key is not unique key%22, e.getMessage());%0A        %7D%0A    %7D%0A%0A    private class UniqueKeyConstructor extends Constructor %7B%0A%0A        @Override%0A        protected void constructMapping2ndStep(MappingNode node, Map%3CObject, Object%3E mapping) %7B%0A            List%3CNodeTuple%3E nodeValue = (List%3CNodeTuple%3E) node.getValue();%0A            for (NodeTuple tuple : nodeValue) %7B%0A                Node keyNode = tuple.getKeyNode();%0A                Node valueNode = tuple.getValueNode();%0A                Object key = constructObject(keyNode);%0A                if (key != null) %7B%0A                    key.hashCode();// check circular dependencies%0A                %7D%0A                Object value = constructObject(valueNode);%0A                Object old = mapping.put(key, value);%0A                if (old != null) %7B%0A                    throw new YAMLException(%22The key is not unique %22 + key);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A%7D%0A

Add example of unique keys