/*
 * Copyright 2010 Proofpoint, Inc.
 *
 * 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 com.proofpoint.platform.sample;

import com.proofpoint.json.JsonCodec;
import org.testng.annotations.Test;

import java.net.URI;

import static com.proofpoint.json.JsonCodec.jsonCodec;
import static org.testng.Assert.assertEquals;

public class TestPersonWithSelf
{
    private final JsonCodec<PersonWithSelf> codec = jsonCodec(PersonWithSelf.class);

    // TODO: add equivalence test

    @Test
    public void testJsonEncode()
    {
        PersonWithSelf expected = PersonWithSelf.from(new Person("alice@example.com", "Alice"), URI.create("http://example.com/foo"));
        assertEquals(codec.toJson(expected).replaceAll("\r\n", "\n"),
                "{\n" +
                "  \"self\" : \"http://example.com/foo\",\n" +
                "  \"name\" : \"Alice\",\n" +
                "  \"email\" : \"alice@example.com\"\n" +
                "}");
    }
}

@@ -649,33 +649,42 @@
 com.
-proofpoint.json.JsonCodec
+google.common.collect.ImmutableMap
 ;%0Aim
@@ -778,73 +778,43 @@
 son.
-JsonCodec.jsonCodec;%0Aimport static org.testng.Ass
+testing.JsonTest
 er
-t
 .assert
-Equals
+JsonEncode
 ;%0A%0Ap
@@ -850,94 +850,8 @@
 f%0A%7B%0A
-    private final JsonCodec%3CPersonWithSelf%3E codec = jsonCodec(PersonWithSelf.class);%0A%0A
     
@@ -942,34 +942,25 @@
     
-PersonWithSelf expected = 
+assertJsonEncode(
 Pers
@@ -1058,135 +1058,75 @@
 o%22))
-;%0A        assertEquals(codec.toJson(expected).replaceAll(%22%5Cr%5Cn%22, %22%5Cn%22),%0A                %22%7B%5Cn%22 +%0A                %22  %5C%22self%5C%22 : %5C
+,%0A                ImmutableMap.of(%0A                        %22self%22, 
 %22htt
@@ -1144,24 +1144,18 @@
 .com/foo
-%5C
 %22,
-%5Cn%22 +
 %0A       
@@ -1167,37 +1167,32 @@
     
-%22
   
-%5C%22name%5C%22 : %5C
+      %22name%22, 
 %22Alice
-%5C
 %22,
-%5Cn%22 +
 %0A   
@@ -1208,24 +1208,25 @@
     
-%22
   
-%5C%22email%5C%22 : %5C
+      %22email%22, 
 %22ali
@@ -1243,15 +1243,9 @@
 .com
-%5C%22%5Cn%22 +
+%22
 %0A   
@@ -1261,11 +1261,9 @@
     
-%22%7D%22
+)
 );%0A 

Use JsonTester.assertJsonEncode()