package com.stripe.model;

import com.stripe.BaseStripeTest;
import com.stripe.model.StripeObject;

import java.io.IOException;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class ExpandableFieldSerializerTest extends BaseStripeTest {

    private class TestNestedObject implements HasId {
        String id;
        int bar;

        public String getId() {
            return id;
        }
    }

    private class TestTopLevelObject extends StripeObject {
        ExpandableField<TestNestedObject> nested;
    }

    @Test
    public void serializeNotExpanded() throws IOException {
        TestTopLevelObject object = new TestTopLevelObject();
        object.nested = new ExpandableField<TestNestedObject>("id_not_expanded", null);

        String expected = "{\n  \"nested\": \"id_not_expanded\"\n}";
        assertEquals(expected, object.toJson());
    }

    @Test
    public void serializeExpanded() throws IOException {
        TestNestedObject nested = new TestNestedObject();
        nested.id = "id_expanded";
        nested.bar = 42;
        TestTopLevelObject object = new TestTopLevelObject();
        object.nested = new ExpandableField<TestNestedObject>(nested.id, nested);

        String expected = "{\n  \"nested\": {\n    \"id\": \"id_expanded\",\n    \"bar\": 42\n  }\n}";
        assertEquals(expected, object.toJson());
    }

    @Test
    public void serializeNull() throws IOException {
        TestTopLevelObject object = new TestTopLevelObject();
        object.nested = new ExpandableField<TestNestedObject>(null, null);

        String expected = "{\n  \"nested\": null\n}";
        assertEquals(expected, object.toJson());
    }
}

@@ -260,20 +260,17 @@
 Test %7B%0A%0A
-    
+%09
 private 
@@ -311,24 +311,18 @@
 HasId %7B%0A
-        
+%09%09
 String i
@@ -324,24 +324,18 @@
 ing id;%0A
-        
+%09%09
 int bar;
@@ -336,24 +336,18 @@
 t bar;%0A%0A
-        
+%09%09
 public S
@@ -366,52 +366,31 @@
 ) %7B%0A
-            return id;%0A        %7D%0A    %7D%0A%0A    
+%09%09%09return id;%0A%09%09%7D%0A%09%7D%0A%0A%09
 priv
@@ -441,24 +441,18 @@
 bject %7B%0A
-        
+%09%09
 Expandab
@@ -485,37 +485,28 @@
 nested;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Test%0A
-    
+%09
 public v
@@ -549,32 +549,26 @@
 Exception %7B%0A
-        
+%09%09
 TestTopLevel
@@ -605,32 +605,26 @@
 elObject();%0A
-        
+%09%09
 object.neste
@@ -688,32 +688,26 @@
 d%22, null);%0A%0A
-        
+%09%09
 String expec
@@ -751,32 +751,26 @@
 nded%5C%22%5Cn%7D%22;%0A
-        
+%09%09
 assertEquals
@@ -798,37 +798,28 @@
 son());%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Test%0A
-    
+%09
 public v
@@ -859,32 +859,26 @@
 Exception %7B%0A
-        
+%09%09
 TestNestedOb
@@ -915,24 +915,18 @@
 ject();%0A
-        
+%09%09
 nested.i
@@ -944,24 +944,18 @@
 anded%22;%0A
-        
+%09%09
 nested.b
@@ -963,24 +963,18 @@
 r = 42;%0A
-        
+%09%09
 TestTopL
@@ -1015,32 +1015,26 @@
 elObject();%0A
-        
+%09%09
 object.neste
@@ -1092,32 +1092,26 @@
 , nested);%0A%0A
-        
+%09%09
 String expec
@@ -1189,32 +1189,26 @@
 2%5Cn  %7D%5Cn%7D%22;%0A
-        
+%09%09
 assertEquals
@@ -1240,29 +1240,20 @@
 ));%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Test%0A
-    
+%09
 publ
@@ -1297,24 +1297,18 @@
 ption %7B%0A
-        
+%09%09
 TestTopL
@@ -1353,24 +1353,18 @@
 ject();%0A
-        
+%09%09
 object.n
@@ -1423,24 +1423,18 @@
 null);%0A%0A
-        
+%09%09
 String e
@@ -1475,16 +1475,10 @@
 %7D%22;%0A
-        
+%09%09
 asse
@@ -1514,16 +1514,13 @@
 son());%0A
-    
+%09
 %7D%0A%7D%0A

Switch indentation to tabs