Android Open Source - json2view Test Sample Case






From Project

Back to project page json2view.

License

The source code is released under:

MIT License

If you think the Android project json2view listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.avocarrot.json2view;
/*from   w  w w  .java 2 s . com*/
import android.content.Context;
import android.test.InstrumentationTestCase;
import android.test.RenamingDelegatingContext;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.json.JSONObject;

/**
 * Created by avocarrot on 17/12/2014.
 */
public class TestSampleCase extends InstrumentationTestCase {

    JSONObject jsonObject;
    View view2test;
    Context context;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        context = getInstrumentation().getContext();
        jsonObject = Utils.readJson("sample.json", context);
        assertNotNull("Cannot parse json", jsonObject);
        view2test = DynamicView.createView(context, jsonObject);
        assertNotNull("Cannot create dynamic View", view2test);

    }

    public void testView() {
        assertTrue("Parent View is not Relative Layout", view2test instanceof RelativeLayout);
        RelativeLayout relative = (RelativeLayout) view2test;
        assertTrue("expecting Linear Layout", relative.getChildAt(0) instanceof LinearLayout);
        LinearLayout linearLayout = (LinearLayout) relative.getChildAt(0);
        assertEquals("expecting 4 children", linearLayout.getChildCount(), 4);
        assertEquals(linearLayout.getChildAt(0).getClass(), TextView.class);
        assertEquals(linearLayout.getChildAt(1).getClass(), TextView.class);
        assertEquals(linearLayout.getChildAt(2).getClass(), ImageView.class);
        assertEquals(linearLayout.getChildAt(3).getClass(), TextView.class);
    }

}




Java Source Code List

com.avocarrot.json2view.ApplicationTest.java
com.avocarrot.json2view.DynamicHelper.java
com.avocarrot.json2view.DynamicPropertyJsonBuilder.java
com.avocarrot.json2view.DynamicProperty.java
com.avocarrot.json2view.DynamicViewId.java
com.avocarrot.json2view.DynamicViewJsonBuilder.java
com.avocarrot.json2view.DynamicView.java
com.avocarrot.json2view.TestActivity.java
com.avocarrot.json2view.TestImageViewPropertiesCase.java
com.avocarrot.json2view.TestInvalidJson.java
com.avocarrot.json2view.TestLayoutPropertiesCase.java
com.avocarrot.json2view.TestSampleCase.java
com.avocarrot.json2view.TestViewPropertiesCase.java
com.avocarrot.json2view.Utils.java
com.avocarrot.json2view.sample.MainActivity.java