package com.clxcommunications.xms;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.junit.Test;

public class ApiErrorTest {

	private final ApiObjectMapper json = new ApiObjectMapper();

	@Test
	public void canSerializeJson() throws Exception {
		String code = RandomStringUtils.randomPrint(1, 20);
		String text = RandomStringUtils.randomPrint(1, 20);
		ApiError input = ImmutableApiError.of(code, text);

		String expected = Utils.join("\n",
		        "{",
		        "  \"code\" : \"" + StringEscapeUtils.escapeJson(code) + "\",",
		        "  \"text\" : \"" + StringEscapeUtils.escapeJson(text) + "\"",
		        "}");

		String actual = json.writeValueAsString(input);

		assertThat(actual, is(TestUtils.jsonEqualTo(expected)));
	}

	@Test
	public void canDeserializeJson() throws Exception {
		String code = RandomStringUtils.randomPrint(1, 20);
		String text = RandomStringUtils.randomPrint(1, 20);
		ApiError expected = ImmutableApiError.of(code, text);

		String input = json.writeValueAsString(expected);

		ApiError actual = json.readValue(input, ApiError.class);

		assertThat(actual, is(expected));
	}

}

@@ -149,28 +149,28 @@
 s.lang3.
-Random
 String
+Escape
 Utils;%0Ai
@@ -183,71 +183,169 @@
 org.
-apache.commons.lang3.StringEscapeUtils;%0Aimport org.junit.Test;%0A
+junit.runner.RunWith;%0A%0Aimport com.pholser.junit.quickcheck.Property;%0Aimport com.pholser.junit.quickcheck.runner.JUnitQuickcheck;%0A%0A@RunWith(JUnitQuickcheck.class)
 %0Apub
@@ -430,28 +430,32 @@
 apper();%0A%0A%09@
-Test
+Property
 %0A%09public voi
@@ -477,136 +477,52 @@
 son(
-) throws Exception %7B%0A%09%09String code = RandomStringUtils.randomPrint(1, 20);%0A%09%09String text = RandomStringUtils.randomPrint(1, 20);
+String code, String text) throws Exception %7B
 %0A%09%09A
@@ -904,20 +904,24 @@
 ;%0A%09%7D%0A%0A%09@
-Test
+Property
 %0A%09public
@@ -949,136 +949,52 @@
 son(
-) throws Exception %7B%0A%09%09String code = RandomStringUtils.randomPrint(1, 20);%0A%09%09String text = RandomStringUtils.randomPrint(1, 20);
+String code, String text) throws Exception %7B
 %0A%09%09A

Use JUnit QuickCheck in ApiError test