Android Open Source - json2view Test Image View Properties 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 .  j a  va2  s .c o m
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.test.InstrumentationTestCase;
import android.view.View;
import android.widget.ImageView;

import static com.avocarrot.json2view.DynamicProperty.NAME;
import static com.avocarrot.json2view.DynamicProperty.TYPE;

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

    DynamicViewJsonBuilder dummyJsonObj;
    Context context;

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

        context = getInstrumentation().getContext();
        dummyJsonObj =
            new DynamicViewJsonBuilder()
                .setWidget("ImageView");

        assertNotNull("Cannot create dynamic jsonObject", dummyJsonObj);

    }

    /* test set padding as integer */
    public void testDummyView() {
        View view = DynamicView.createView(
            context,
            dummyJsonObj
                .build());
        assertNotNull("Cannot create dynamic View", view);
    }

    /* test set src of imageView */
    public void testSrc() {
        View view = DynamicView.createView(
            context,
            dummyJsonObj
                .addProperty(new DynamicPropertyJsonBuilder().setName(NAME.SRC).setType(TYPE.REF).setValue("sample").build())
                .build());
        assertTrue( ( ((BitmapDrawable)((ImageView)view).getDrawable()).getBitmap() ).sameAs(Utils.readDrawable(com.avocarrot.json2view.test.R.drawable.sample, context)));
        /* load other drawable and check */
        view = DynamicView.createView(
            context,
            dummyJsonObj
                .addProperty(new DynamicPropertyJsonBuilder().setName(NAME.SRC).setType(TYPE.REF).setValue("sample").build())
                .build());
        assertFalse( ( ((BitmapDrawable)((ImageView)view).getDrawable()).getBitmap() ).sameAs(Utils.readAssetAsImage("sample2.png", context)));
    }

    /* test set src of imageView */
    public void testSrcBase64() {
        View view = DynamicView.createView(
            context,
            dummyJsonObj
                .addProperty(new DynamicPropertyJsonBuilder().setName(NAME.SRC).setType(TYPE.BASE64).setValue(Utils.readBase64("sample2.png", context)).build())
                .build());
        assertTrue( ( ((BitmapDrawable)((ImageView)view).getDrawable()).getBitmap() ).sameAs(Utils.readAssetAsImage("sample2.png", context)));
    }

}




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