Skip to content

Commit fcfcd2f

Browse files
committed
新增断言
1 parent 930c99a commit fcfcd2f

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.therouter
2+
3+
fun require(pass: Boolean, tag: String, msg: String) {
4+
if (!pass) {
5+
throw IllegalArgumentException("TheRouter::$tag::$msg")
6+
}
7+
}

app/src/main/java/com/therouter/app/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ public class MainActivity extends AppCompatActivity {
1414
protected void onCreate(Bundle savedInstanceState) {
1515
super.onCreate(savedInstanceState);
1616
setContentView(R.layout.main);
17-
setTitle("功能介绍");
17+
setTitle("TheRouter功能介绍");
1818
// 如果用到了 @Autowired 注解,需要加这一行,这一行直接写在BaseActivity中更好
19+
// 如果用到了onNewIntent(),也需要调用这一行,并且在调用前需要将新intent 重新set一遍
1920
// TheRouter.inject(this);
2021

2122
TextView textView = findViewById(R.id.content_version);

app/src/main/java/com/therouter/app/navigator/NavigatorTargetActivity.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.therouter.app.navigator;
22

3+
import static com.therouter.ExtensionKt.require;
4+
35
import android.os.Bundle;
46
import android.view.View;
57
import android.widget.Button;
@@ -86,42 +88,54 @@ protected void onCreate(Bundle savedInstanceState) {
8688

8789
final TextView textView1 = findViewById(R.id.textview1);
8890
textView1.setText("接收int值传递:integer2=" + intValue);
91+
require(intValue == 12345678, "NavigatorTargetActivity", "intValue数值不对");
8992

9093
final TextView textView2 = findViewById(R.id.textview2);
9194
textView2.setText("用String传递int数据:" + stringIntValue);
95+
require("12345678".equals(stringIntValue), "NavigatorTargetActivity", "stringIntValue数值不对");
9296

9397
final TextView textView3 = findViewById(R.id.textview3);
9498
textView3.setText("接收包含大小写数字的String值传递:" + str_123_Value);
99+
require("测试传中文字符串".equals(str_123_Value), "NavigatorTargetActivity", "str_123_Value数值不对");
95100

96101
final TextView textView4 = findViewById(R.id.textview4);
97102
textView4.setText("接收故意传递非boolean值给boolean变量:" + boolParseError);
103+
require(!boolParseError, "NavigatorTargetActivity", "boolParseError数值不对");
98104

99105
final TextView textview4_1 = findViewById(R.id.textview4_1);
100106
textview4_1.setText("用字符串传一个很大的值给short变量:" + shortParseError);
107+
require(0 == shortParseError, "NavigatorTargetActivity", "shortParseError数值不对");
101108

102109
final TextView textView5 = findViewById(R.id.textview5);
103110
textView5.setText("接收boolean值:boolValue=" + boolValue);
111+
require(boolValue, "NavigatorTargetActivity", "boolValue数值不对");
104112

105113
final TextView textview6 = findViewById(R.id.textview6);
106114
textview6.setText("接收Long类型的值:longValue=" + longValue);
115+
require(123456789012345L == longValue, "NavigatorTargetActivity", "longValue数值不对");
107116

108117
final TextView textview7 = findViewById(R.id.textview7);
109118
textview7.setText("接收Char类型的值:" + charValue);
119+
require('c' == charValue, "NavigatorTargetActivity", "charValue数值不对");
110120

111121
final TextView textview8 = findViewById(R.id.textview8);
112122
textview8.setText("接收double类型的值(key与关键字同名情况):" + doubleValue);
123+
require(3.14159265358972 == doubleValue, "NavigatorTargetActivity", "doubleValue数值不对");
113124

114125
final TextView textview9 = findViewById(R.id.textview9);
115126
textview9.setText("接收float类型的值:" + floatValue);
127+
require(3.1415927F == floatValue, "NavigatorTargetActivity", "floatValue数值不对");
116128

117129
final TextView textview10 = findViewById(R.id.textview10);
118130
if (serializableBean != null) {
119131
textview10.setText("接收 SerializableObject 的值:" + serializableBean.hello);
132+
require("helloField".equals(serializableBean.hello), "NavigatorTargetActivity", "serializableBean.hello数值不对");
120133
}
121134

122135
final TextView textview11 = findViewById(R.id.textview11);
123136
if (parcelableBean != null) {
124137
textview11.setText("接收 ParcelableObject 的值:" + parcelableBean.hello);
138+
require("helloField".equals(parcelableBean.hello), "NavigatorTargetActivity", "parcelableBean.hello数值不对");
125139
}
126140

127141
if (button1 != null) {

app/src/main/java/com/therouter/app/navigator/NavigatorTargetActivity2.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.therouter.app.navigator;
22

3+
import static com.therouter.ExtensionKt.require;
34
import static com.therouter.app.KotlinPathIndex.Test.HOME2;
45

56
import android.os.Bundle;
@@ -29,6 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
2930
textView.setText("子类 @Autowired 数据:" + stringChildClassField);
3031
if (stringChildClassFields != null) {
3132
textView.append("\n stringChildClassFields: " + stringChildClassFields.get(0).get(0));
33+
require("stringChildClassFields".equals(stringChildClassFields.get(0).get(0)), "NavigatorTargetActivity", "stringChildClassFields数值不对");
3234
}
3335
}
3436
}

app/src/main/java/com/therouter/app/navigator/NavigatorTestActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ public class NavigatorTestActivity extends AppCompatActivity {
3535
protected void onCreate(@Nullable Bundle savedInstanceState) {
3636
super.onCreate(savedInstanceState);
3737
setContentView(R.layout.navigator);
38-
setTitle("导航测试用例");
38+
setTitle("页面导航跳转测试用例");
3939
// @Autowired 注入,这一行应该写在BaseActivity中更好
40+
// 如果用到了onNewIntent(),也需要调用这一行,并且在调用前需要将新intent 重新set一遍
4041
TheRouter.inject(this);
4142

4243
InternalBeanTest.RowBean bean = new InternalBeanTest.RowBean();

0 commit comments

Comments
 (0)