Просмотр исходного кода

- Add test for format rfidCardNumber in ScanResultActivity
- Change setting for dataBinding in gradle

ilhamitubagoes лет назад: 4
Родитель
Сommit
937f1e71dc

+ 2 - 2
app/build.gradle

@@ -13,8 +13,8 @@ android {
13 13
         versionName gitVersionName
14 14
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 15
     }
16
-    viewBinding {
17
-        enabled = true
16
+    buildFeatures {
17
+        viewBinding = true
18 18
     }
19 19
     signingConfigs {
20 20
         release {

+ 1 - 1
app/src/main/java/com/fusi24/rfid/ui/scanresult/ScanResultActivity.java

@@ -60,7 +60,7 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
60 60
         // Setting digit rfid card using MAX_NUMBER = 10
61 61
         /* FORMAT "%010d"
62 62
         * % ==> used as formatter, 0 ==> used to pad with zeroes instead of spaces
63
-        * 10 ==> minimum of 10 characters wide
63
+        * 10 ==> maximum of 10 characters wide
64 64
         * d ==> as a decimal integer */
65 65
         if (numberRfidTemp != null){
66 66
             if (numberRfidTemp.length() < 10){

+ 80 - 0
app/src/test/java/com/fusi24/rfid/ScanResultUnitTest.java

@@ -0,0 +1,80 @@
1
+package com.fusi24.rfid;
2
+
3
+import org.junit.Test;
4
+
5
+import java.util.Locale;
6
+
7
+import static org.junit.Assert.assertEquals;
8
+
9
+/**
10
+ * Example local unit test, which will execute on the development machine (host).
11
+ *
12
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
13
+ */
14
+public class ScanResultUnitTest {
15
+
16
+    private String numberRfid = "";
17
+
18
+    @Test
19
+    public void formatOneDigit() {
20
+        numberRfid = addZeroToDigit(1);
21
+        assertEquals("0000000001", numberRfid);
22
+    }
23
+
24
+    @Test
25
+    public void formatTwoDigit() {
26
+        numberRfid = addZeroToDigit(12);
27
+        assertEquals("0000000012", numberRfid);
28
+    }
29
+
30
+    @Test
31
+    public void formatThreeDigit() {
32
+        numberRfid = addZeroToDigit(123);
33
+        assertEquals("0000000123", numberRfid);
34
+    }
35
+
36
+    @Test
37
+    public void formatFourDigit() {
38
+        numberRfid = addZeroToDigit(1234);
39
+        assertEquals("0000001234", numberRfid);
40
+    }
41
+
42
+    @Test
43
+    public void formatFiveDigit() {
44
+        numberRfid = addZeroToDigit(12345);
45
+        assertEquals("0000012345", numberRfid);
46
+    }
47
+
48
+    @Test
49
+    public void formatSixDigit() {
50
+        numberRfid = addZeroToDigit(123456);
51
+        assertEquals("0000123456", numberRfid);
52
+    }
53
+
54
+    @Test
55
+    public void formatSevenDigit() {
56
+        numberRfid = addZeroToDigit(1234567);
57
+        assertEquals("0001234567", numberRfid);
58
+    }
59
+
60
+    @Test
61
+    public void formatEightDigit() {
62
+        numberRfid = addZeroToDigit(12345678);
63
+        assertEquals("0012345678", numberRfid);
64
+    }
65
+
66
+    @Test
67
+    public void formatNineDigit() {
68
+        numberRfid = addZeroToDigit(123456789);
69
+        assertEquals("0123456789", numberRfid);
70
+    }
71
+
72
+    // Call this method if digit < 10
73
+    private String addZeroToDigit(Integer number){
74
+        /* FORMAT "%010d"
75
+         * % ==> used as formatter, 0 ==> used to pad with zeroes instead of spaces
76
+         * 10 ==> maximum of 10 characters wide
77
+         * d ==> as a decimal integer */
78
+        return String.format(Locale.getDefault(), "%010d", number);
79
+    }
80
+}