package com.box.boxjavalibv2.dao;

import java.io.File;
import java.io.IOException;

import junit.framework.Assert;

import org.apache.commons.io.FileUtils;
import org.junit.Test;

import com.box.boxjavalibv2.testutils.TestUtils;
import com.box.restclientv2.exceptions.BoxRestException;

public class BoxObjectFallBackTest {

    @Test
    public void testFallBack() throws IOException, BoxRestException {
        String json = FileUtils.readFileToString(new File("testdata/wrongtype.json"));
        BoxTypedObject obj = (BoxTypedObject) TestUtils.getFromJSON(json, BoxTypedObject.class);
        Assert.assertEquals(BoxTypedObject.class, obj.getClass());

        BoxItem obj1 = (BoxItem) TestUtils.getFromJSON(json, BoxItem.class);
        Assert.assertEquals(BoxItem.class, obj1.getClass());
    }
}

@@ -281,16 +281,130 @@
 ption;%0A%0A
+/**%0A * Test when parsing box object, if type cannot be recognized, we fall back to the specified base object.%0A */%0A
 public c
@@ -902,16 +902,265 @@
 lass());
+%0A%0A        // Make sure can also parse for string without type.%0A        json = json.replace(%22%5C%22type%5C%22:%5C%22notype%5C%22,%22, %22%22);%0A        obj1 = (BoxItem) TestUtils.getFromJSON(json, BoxItem.class);%0A        Assert.assertEquals(BoxItem.class, obj1.getClass());
 %0A    %7D%0A%7D

improve unit test