|
@@ -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
|
+}
|