|
| 1 | +package com.thirtydegreesray.dataautoaccess.sample.test; |
| 2 | + |
| 3 | +import android.os.Bundle; |
| 4 | +import android.widget.TextView; |
| 5 | + |
| 6 | +import com.thirtydegreesray.dataautoaccess.DataAutoAccess; |
| 7 | +import com.thirtydegreesray.dataautoaccess.sample.BaseActivity; |
| 8 | +import com.thirtydegreesray.dataautoaccess.sample.R; |
| 9 | + |
| 10 | +import java.util.ArrayList; |
| 11 | + |
| 12 | +/** |
| 13 | + * Created by ThirtyDegreesRay on 2016/9/12 10:10 |
| 14 | + */ |
| 15 | + |
| 16 | +public class TestActivity extends BaseActivity { |
| 17 | + |
| 18 | + private TextView testResult; |
| 19 | + |
| 20 | + @Override |
| 21 | + protected void onCreate(Bundle savedInstanceState) { |
| 22 | + super.onCreate(savedInstanceState); |
| 23 | + setContentView(R.layout.activity_test); |
| 24 | + testResult = (TextView) findViewById(R.id.test_result); |
| 25 | + testResult.setText(test() ? "test ok" : "test error"); |
| 26 | + } |
| 27 | + |
| 28 | + private boolean test() { |
| 29 | + TestClass testClass1 = getTestClass(); |
| 30 | + Bundle bundle = new Bundle(); |
| 31 | + DataAutoAccess.saveData(testClass1, bundle); |
| 32 | + TestClass testClass2 = new TestClass(); |
| 33 | + DataAutoAccess.getData(testClass2, bundle); |
| 34 | + return testClass1.equals(testClass2); |
| 35 | + } |
| 36 | + |
| 37 | + private TestClass getTestClass() { |
| 38 | + TestClass testClass = new TestClass(); |
| 39 | + |
| 40 | + testClass.field1 = "field"; |
| 41 | + testClass.field2 = 1; |
| 42 | + testClass.field3 = true; |
| 43 | + testClass.field4 = 1.2; |
| 44 | + testClass.field5 = 1.2f; |
| 45 | + testClass.field6 = 1; |
| 46 | + testClass.field7 = 1; |
| 47 | + testClass.field8 = 'a'; |
| 48 | + testClass.field9 = 1; |
| 49 | + testClass.field10 = new ParcelableBean(); |
| 50 | + testClass.field10.initData(); |
| 51 | + testClass.field11 = new SerializableBean(); |
| 52 | + testClass.field11.initData(); |
| 53 | + testClass.field12 = new Bundle(); |
| 54 | + testClass.field12.putString("name", "DataAutoAccess"); |
| 55 | + testClass.field28 = new CharSequenceBean("field"); |
| 56 | + |
| 57 | + testClass.field13 = new ArrayList<>(); |
| 58 | + testClass.field13.add("field"); |
| 59 | + testClass.field14 = new ArrayList<>(); |
| 60 | + testClass.field14.add(1); |
| 61 | + testClass.field15 = new ArrayList<>(); |
| 62 | + testClass.field15.add(new ParcelableBean().initData()); |
| 63 | + testClass.field26 = new ArrayList<>(); |
| 64 | + testClass.field26.add(new CharSequenceBean("field")); |
| 65 | + |
| 66 | + testClass.field16 = new String[]{"field"}; |
| 67 | + testClass.field17 = new int[]{1}; |
| 68 | + testClass.field18 = new boolean[]{true}; |
| 69 | + testClass.field19 = new double[]{1.2}; |
| 70 | + testClass.field20 = new float[]{1.2f}; |
| 71 | + testClass.field21 = new long[]{1}; |
| 72 | + testClass.field22 = new byte[]{1}; |
| 73 | + testClass.field23 = new char[]{'a'}; |
| 74 | + testClass.field24 = new short[]{1}; |
| 75 | + testClass.field25 = new ParcelableBean[]{new ParcelableBean().initData()}; |
| 76 | + testClass.field27 = new CharSequenceBean[]{new CharSequenceBean("field")}; |
| 77 | + |
| 78 | + return testClass; |
| 79 | + } |
| 80 | +} |
0 commit comments