From 17d91aca55fe88581aab3fdc34d6e16a784b70b0 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 15 May 2013 17:46:58 +0200 Subject: [PATCH] #63 - Added unit test for HalEmbeddedBuilder. --- .../hal/HalEmbeddedBuilderUnitTests.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/test/java/org/springframework/hateoas/hal/HalEmbeddedBuilderUnitTests.java diff --git a/src/test/java/org/springframework/hateoas/hal/HalEmbeddedBuilderUnitTests.java b/src/test/java/org/springframework/hateoas/hal/HalEmbeddedBuilderUnitTests.java new file mode 100644 index 00000000..8c4af518 --- /dev/null +++ b/src/test/java/org/springframework/hateoas/hal/HalEmbeddedBuilderUnitTests.java @@ -0,0 +1,73 @@ +/* + * Copyright 2013 the original author or authors. + * + * 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.springframework.hateoas.hal; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import java.util.List; +import java.util.Map; + +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; +import org.springframework.hateoas.RelProvider; +import org.springframework.hateoas.core.EvoInflectorRelProvider; + +/** + * Unit tests for {@link HalEmbeddedBuilder}. + * + * @author Oliver Gierke + */ +public class HalEmbeddedBuilderUnitTests { + + RelProvider provider; + + @Before + public void setUp() { + provider = new EvoInflectorRelProvider(); + } + + @Test + public void rendersSingleElementsWithSingleEntityRel() { + + Map> map = setUpBuilder("foo", 1L); + + assertThat(map.get("string"), Matchers.> allOf(hasSize(1), hasItem("foo"))); + assertThat(map.get("long"), Matchers.> allOf(hasSize(1), hasItem(1L))); + } + + @Test + public void rendersMultipleElementsWithCollectionResourceRel() { + + Map> map = setUpBuilder("foo", "bar", 1L); + + assertThat(map.containsKey("string"), is(false)); + assertThat(map.get("strings"), Matchers.> allOf(hasSize(2), Matchers. hasItems("foo", "bar"))); + assertThat(map.get("long"), Matchers.> allOf(hasSize(1), hasItem(1L))); + } + + private Map> setUpBuilder(Object... values) { + + HalEmbeddedBuilder builder = new HalEmbeddedBuilder(provider); + + for (Object value : values) { + builder.add(value); + } + + return builder.asMap(); + } +}