// Path: src/main/java/de/otto/edison/hal/EmbeddedTypeInfo.java
// public static EmbeddedTypeInfo withEmbedded(final String rel,
//                                             final Class<? extends HalRepresentation> embeddedType,
//                                             final EmbeddedTypeInfo... nestedTypeInfo) {
//     if (nestedTypeInfo == null || nestedTypeInfo.length == 0) {
//         return new EmbeddedTypeInfo(rel, embeddedType, emptyList());
//     } else {
//         return new EmbeddedTypeInfo(rel, embeddedType, asList(nestedTypeInfo));
//     }
// }
// 
// Path: src/main/java/de/otto/edison/hal/HalParser.java
// public static HalParser parse(final String json) {
//     return new HalParser(json, DEFAULT_JSON_MAPPER);
// }
// 
// Path: src/main/java/de/otto/edison/hal/Link.java
// public static Link link(final String rel, final String href) {
//     return new Link(rel, href);
// }
// 
// Path: src/main/java/de/otto/edison/hal/Link.java
// public static Link self(final String href) {
//     return new Link("self", href);
// }
// 
// Path: src/main/java/de/otto/edison/hal/Links.java
// public static Links emptyLinks() {
//     return new Links();
// }


import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
import static de.otto.edison.hal.EmbeddedTypeInfo.withEmbedded;
import static de.otto.edison.hal.HalParser.parse;
import static de.otto.edison.hal.Link.link;
import static de.otto.edison.hal.Link.self;
import static de.otto.edison.hal.Links.emptyLinks;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
                "           \"_links\":{\"self\":[{\"href\":\"http://example.org/test/bar/01\"}]}" +
                "       }" +
                "   ]}" +
                "}";
        // when
        final SimpleHalRepresentation result = parse(json, new ObjectMapper()).as(SimpleHalRepresentation.class);
        final SimpleHalRepresentation expectedResult = parse(json).as(SimpleHalRepresentation.class);
        // then
        assertThat(result, is(expectedResult));
    }

    @Test
    public void shouldParseEmbeddedItemsWithSpecificType() throws IOException {
        // given
        final String json =
                "{" +
                        "\"_embedded\":{\"bar\":[" +
                        "   {" +
                        "       \"value\":\"3\"," +
                        "       \"_links\":{\"self\":[{\"href\":\"http://example.org/test/bar/01\"}]}" +
                        "   }" +
                        "]}" +
                        "}";
        // when
        final SimpleHalRepresentation result = parse(json)
                .as(SimpleHalRepresentation.class, withEmbedded("bar", EmbeddedHalRepresentation.class));
        // then
        final List<EmbeddedHalRepresentation> embeddedItems = result.getEmbedded().getItemsBy("bar", EmbeddedHalRepresentation.class);
        assertThat(embeddedItems, hasSize(1));
        assertThat(embeddedItems.get(0).getClass(), equalTo(EmbeddedHalRepresentation.class));
// Path: src/main/java/de/otto/edison/hal/EmbeddedTypeInfo.java
// public static EmbeddedTypeInfo withEmbedded(final String rel,
//                                             final Class<? extends HalRepresentation> embeddedType,
//                                             final EmbeddedTypeInfo... nestedTypeInfo) {
//     if (nestedTypeInfo == null || nestedTypeInfo.length == 0) {
//         return new EmbeddedTypeInfo(rel, embeddedType, emptyList());
//     } else {
//         return new EmbeddedTypeInfo(rel, embeddedType, asList(nestedTypeInfo));
//     }
// }
// 
// Path: src/main/java/de/otto/edison/hal/HalParser.java
// public static HalParser parse(final String json) {
//     return new HalParser(json, DEFAULT_JSON_MAPPER);
// }
// 
// Path: src/main/java/de/otto/edison/hal/Link.java
// public static Link link(final String rel, final String href) {
//     return new Link(rel, href);
// }
// 
// Path: src/main/java/de/otto/edison/hal/Link.java
// public static Link self(final String href) {
//     return new Link("self", href);
// }
// 
// Path: src/main/java/de/otto/edison/hal/Links.java
// public static Links emptyLinks() {
//     return new Links();
// }


// Path: src/test/java/de/otto/edison/hal/HalParserTest.java
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
import static de.otto.edison.hal.EmbeddedTypeInfo.withEmbedded;
import static de.otto.edison.hal.HalParser.parse;
import static de.otto.edison.hal.Link.link;
import static de.otto.edison.hal.Link.self;
import static de.otto.edison.hal.Links.emptyLinks;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

                "           \"_links\":{\"self\":[{\"href\":\"http://example.org/test/bar/01\"}]}" +
                "       }" +
                "   ]}" +
                "}";
        // when
        final SimpleHalRepresentation result = parse(json, new ObjectMapper()).as(SimpleHalRepresentation.class);
        final SimpleHalRepresentation expectedResult = parse(json).as(SimpleHalRepresentation.class);
        // then
        assertThat(result, is(expectedResult));
    }

    @Test
    public void shouldParseEmbeddedItemsWithSpecificType() throws IOException {
        // given
        final String json =
                "{" +
                        "\"_embedded\":{\"bar\":[" +
                        "   {" +
                        "       \"value\":\"3\"," +
                        "       \"_links\":{\"self\":[{\"href\":\"http://example.org/test/bar/01\"}]}" +
                        "   }" +
                        "]}" +
                        "}";
        // when
        final SimpleHalRepresentation result = parse(json)
                .as(SimpleHalRepresentation.class, withEmbedded("bar", EmbeddedHalRepresentation.class));
        // then
        final List<EmbeddedHalRepresentation> embeddedItems = result.getEmbedded().getItemsBy("bar", EmbeddedHalRepresentation.class);
        assertThat(embeddedItems, hasSize(1));
        assertThat(embeddedItems.get(0).getClass(), equalTo(EmbeddedHalRepresentation.class));
        assertThat(embeddedItems.get(0).getLinks().getLinkBy("self").get(), is(link("self", "http://example.org/test/bar/01")));