/**
 * 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.issues.issue306;

import org.junit.Test;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Util;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.nodes.Tag;

import java.util.UUID;

import static org.junit.Assert.assertEquals;

public class UuidSupportTest {

    //TODO @Test
    public void loadFromString() {
        String str = UUID.randomUUID().toString();
        Yaml yaml = new Yaml();
        UUID uuid = (UUID) yaml.load(str);
        assertEquals(str, uuid.toString());
    }

    @Test
    public void loadFromBean() {
        String input = Util.getLocalResource("issues/issue306-1.yaml");
        Yaml yaml = new Yaml();
        BeanWithId bean = (BeanWithId) yaml.loadAs(input, BeanWithId.class);
        assertEquals("7f511847-781a-45df-9c8d-1e32e028b9b3", bean.getId().toString());
    }

    @Test
    public void dumpUuid() {
        UUID uuid = UUID.randomUUID();
        Yaml yaml = new Yaml();
        String output = yaml.dump(uuid);
        assertEquals("!!java.util.UUID '" + uuid.toString() + "'\n", output);
    }

    @Test
    public void dumpBean() {
        BeanWithId bean = new BeanWithId();
        bean.setValue(3);
        UUID uuid = UUID.fromString("ac4877be-0c31-4458-a86e-0272efe1aaa8");
        bean.setId(uuid);
        Yaml yaml = new Yaml();
        String output = yaml.dumpAs(bean, Tag.MAP, DumperOptions.FlowStyle.BLOCK);
        String expected = Util.getLocalResource("issues/issue306-2.yaml");
        assertEquals(expected, output);
    }
}

@@ -840,16 +840,48 @@
 il.UUID;
+%0Aimport java.util.regex.Pattern;
 %0A%0Aimport
@@ -923,82 +923,587 @@
 ls;%0A
-%0Apublic class UuidSupportTest %7B%0A%0A    //TODO @Test%0A    public void loadFrom
+import static org.junit.Assert.assertTrue;%0A%0Apublic class UuidSupportTest %7B%0A%0A    public static final Pattern UUID_PATTERN = Pattern%0A            .compile(%22%5E(?:%5C%5Cp%7BXDigit%7D%7B8%7D-%5C%5Cp%7BXDigit%7D%7B4%7D-%5C%5Cp%7BXDigit%7D%7B4%7D-%5C%5Cp%7BXDigit%7D%7B4%7D-%5C%5Cp%7BXDigit%7D%7B12%7D)$%22);%0A    public static final Tag UUID_TAG = new Tag(Tag.PREFIX + %22java.util.UUID%22);%0A%0A    @Test%0A    public void pattern() %7B%0A        assertTrue(UUID_PATTERN.matcher(%227f511847-781a-45df-9c8d-1e32e028b9b3%22).matches());%0A        assertTrue(UUID_PATTERN.matcher(%22AC4877BE-0C31-4458-A86E-0272EFE1AAA8%22).matches());%0A    %7D%0A%0A    @Test%0A    public void dumpAs
 Stri
@@ -1521,18 +1521,17 @@
     
-String str
+UUID uuid
  = U
@@ -1546,16 +1546,43 @@
 omUUID()
+;%0A        String str = uuid
 .toStrin
@@ -1630,67 +1630,485 @@
     
-UUID uuid = (UUID) yaml.load(str);%0A        assertEquals(str
+yaml.addImplicitResolver(UUID_TAG, UUID_PATTERN, null);%0A        String output = yaml.dump(str);%0A        assertEquals(%22'%22 + str + %22'%5Cn%22, output);%0A        assertEquals(str + %22%5Cn%22, yaml.dump(uuid));%0A    %7D%0A%0A    @Test%0A    public void loadAsUuid() %7B%0A        Yaml yaml = new Yaml();%0A        yaml.addImplicitResolver(UUID_TAG, UUID_PATTERN, null);%0A        UUID uuid = (UUID) yaml.load(%227f511847-781a-45df-9c8d-1e32e028b9b3%22);%0A        assertEquals(%227f511847-781a-45df-9c8d-1e32e028b9b3%22
 , uu
@@ -2306,21 +2306,8 @@
 an =
- (BeanWithId)
  yam

Fix issue 306: UUID support is complete