Skip to content

Commit f8354ca

Browse files
add test activity.
1 parent 4c80ffd commit f8354ca

3 files changed

Lines changed: 149 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.thirtydegreesray.dataautoaccess.sample.test;
2+
3+
/**
4+
* Created by ThirtyDegreesRay on 2016/9/12 11:21
5+
*/
6+
7+
public class CharSequenceBean implements CharSequence{
8+
9+
private String charString;
10+
11+
public CharSequenceBean(String charString){
12+
this.charString = charString;
13+
}
14+
15+
@Override
16+
public int length() {
17+
return charString.length();
18+
}
19+
20+
@Override
21+
public char charAt(int index) {
22+
return charString.charAt(index);
23+
}
24+
25+
@Override
26+
public CharSequence subSequence(int start, int end) {
27+
return charString.substring(start, end);
28+
}
29+
30+
@Override
31+
public boolean equals(Object obj) {
32+
if(!(obj instanceof CharSequenceBean)){
33+
return false;
34+
}
35+
CharSequenceBean charSequenceBean = (CharSequenceBean) obj;
36+
return charString.equals(charSequenceBean.charString);
37+
}
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.thirtydegreesray.dataautoaccess.sample.test;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* Created by ThirtyDegreesRay on 2016/9/12 11:10
7+
*/
8+
9+
public class SerializableBean implements Serializable {
10+
11+
int size ;
12+
String name ;
13+
14+
public SerializableBean initData(){
15+
size = 2;
16+
name = "ParcelableClass";
17+
return this;
18+
}
19+
20+
@Override
21+
public boolean equals(Object obj) {
22+
if(!(obj instanceof SerializableBean)){
23+
return false;
24+
}
25+
SerializableBean serializableBean = (SerializableBean) obj;
26+
if(size != serializableBean.size){
27+
return false;
28+
}
29+
return name.equals(serializableBean.name);
30+
}
31+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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

Comments
 (0)