Skip to content

Commit

Permalink
新增断言
Browse files Browse the repository at this point in the history
  • Loading branch information
kymjs committed Mar 20, 2024
1 parent 930c99a commit fcfcd2f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/com/therouter/Extension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.therouter

fun require(pass: Boolean, tag: String, msg: String) {
if (!pass) {
throw IllegalArgumentException("TheRouter::$tag::$msg")
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/therouter/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTitle("功能介绍");
setTitle("TheRouter功能介绍");
// 如果用到了 @Autowired 注解,需要加这一行,这一行直接写在BaseActivity中更好
// 如果用到了onNewIntent(),也需要调用这一行,并且在调用前需要将新intent 重新set一遍
// TheRouter.inject(this);

TextView textView = findViewById(R.id.content_version);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.therouter.app.navigator;

import static com.therouter.ExtensionKt.require;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Expand Down Expand Up @@ -86,42 +88,54 @@ protected void onCreate(Bundle savedInstanceState) {

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

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

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

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

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

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

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

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

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

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

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

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

if (button1 != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.therouter.app.navigator;

import static com.therouter.ExtensionKt.require;
import static com.therouter.app.KotlinPathIndex.Test.HOME2;

import android.os.Bundle;
Expand Down Expand Up @@ -29,6 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
textView.setText("子类 @Autowired 数据:" + stringChildClassField);
if (stringChildClassFields != null) {
textView.append("\n stringChildClassFields: " + stringChildClassFields.get(0).get(0));
require("stringChildClassFields".equals(stringChildClassFields.get(0).get(0)), "NavigatorTargetActivity", "stringChildClassFields数值不对");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public class NavigatorTestActivity extends AppCompatActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navigator);
setTitle("导航测试用例");
setTitle("页面导航跳转测试用例");
// @Autowired 注入,这一行应该写在BaseActivity中更好
// 如果用到了onNewIntent(),也需要调用这一行,并且在调用前需要将新intent 重新set一遍
TheRouter.inject(this);

InternalBeanTest.RowBean bean = new InternalBeanTest.RowBean();
Expand Down

0 comments on commit fcfcd2f

Please sign in to comment.