11package nl .sikken .bertrik .cayenne ;
22
3- import org .junit .jupiter .api .Assertions ;
43import org .junit .jupiter .api .Test ;
54import org .slf4j .Logger ;
65import org .slf4j .LoggerFactory ;
76
87import java .util .Base64 ;
98
9+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
10+ import static org .junit .jupiter .api .Assertions .assertEquals ;
11+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
12+ import static org .junit .jupiter .api .Assertions .assertNull ;
13+ import static org .junit .jupiter .api .Assertions .assertThrows ;
14+ import static org .junit .jupiter .api .Assertions .assertTrue ;
15+
1016/**
1117 * Unit tests for CayenneMessage.
1218 */
@@ -28,8 +34,8 @@ public void testTwoTemperatureSensors() throws CayenneException {
2834 payload .parse (data );
2935 LOG .info ("payload: {}" , payload );
3036
31- Assertions . assertArrayEquals (new String []{"27.2" }, payload .ofChannel (3 ).format ());
32- Assertions . assertArrayEquals (new String []{"25.5" }, payload .ofChannel (5 ).format ());
37+ assertArrayEquals (new String []{"27.2" }, payload .ofChannel (3 ).format ());
38+ assertArrayEquals (new String []{"25.5" }, payload .ofChannel (5 ).format ());
3339 }
3440
3541 /**
@@ -44,8 +50,8 @@ public void testTemperaturePlusAccel() throws CayenneException {
4450 CayenneMessage payload = new CayenneMessage ();
4551 payload .parse (data );
4652
47- Assertions . assertArrayEquals (new String []{"-4.1" }, payload .ofChannel (1 ).format ());
48- Assertions . assertArrayEquals (new String []{"1.234" , "-1.234" , "0.000" }, payload .ofChannel (6 ).format ());
53+ assertArrayEquals (new String []{"-4.1" }, payload .ofChannel (1 ).format ());
54+ assertArrayEquals (new String []{"1.234" , "-1.234" , "0.000" }, payload .ofChannel (6 ).format ());
4955 }
5056
5157 /**
@@ -59,7 +65,7 @@ public void testGps() throws CayenneException {
5965 CayenneMessage payload = new CayenneMessage ();
6066 payload .parse (data );
6167
62- Assertions . assertArrayEquals (new String []{"42.3519" , "-87.9094" , "10.00" }, payload .ofChannel (1 ).format ());
68+ assertArrayEquals (new String []{"42.3519" , "-87.9094" , "10.00" }, payload .ofChannel (1 ).format ());
6369 }
6470
6571 /**
@@ -73,7 +79,7 @@ public void testHumidity() throws CayenneException {
7379 CayenneMessage payload = new CayenneMessage ();
7480 payload .parse (data );
7581
76- Assertions . assertArrayEquals (new String []{"50.0" }, payload .ofChannel (1 ).format ());
82+ assertArrayEquals (new String []{"50.0" }, payload .ofChannel (1 ).format ());
7783 }
7884
7985 /**
@@ -88,9 +94,9 @@ public void testActualData() throws CayenneException {
8894 CayenneMessage payload = new CayenneMessage ();
8995 payload .parse (data );
9096
91- Assertions . assertArrayEquals (new String []{"52.0225" , "4.6928" , "-2.00" }, payload .ofChannel (1 ).format ());
92- Assertions . assertArrayEquals (new String []{"247.84" }, payload .ofChannel (2 ).format ());
93- Assertions . assertArrayEquals (new String []{"27.0" }, payload .ofChannel (3 ).format ());
97+ assertArrayEquals (new String []{"52.0225" , "4.6928" , "-2.00" }, payload .ofChannel (1 ).format ());
98+ assertArrayEquals (new String []{"247.84" }, payload .ofChannel (2 ).format ());
99+ assertArrayEquals (new String []{"27.0" }, payload .ofChannel (3 ).format ());
94100 }
95101
96102 /**
@@ -107,22 +113,22 @@ public void testActualData2() throws CayenneException {
107113 payload .parse (data );
108114
109115 // verify we can get at the data by channel
110- Assertions . assertArrayEquals (new String []{"52.0225" , "4.6925" , "-17.00" }, payload .ofChannel (1 ).format ());
111- Assertions . assertArrayEquals (new String []{"4.15" }, payload .ofChannel (2 ).format ());
112- Assertions . assertArrayEquals (new String []{"24.0" }, payload .ofChannel (3 ).format ());
116+ assertArrayEquals (new String []{"52.0225" , "4.6925" , "-17.00" }, payload .ofChannel (1 ).format ());
117+ assertArrayEquals (new String []{"4.15" }, payload .ofChannel (2 ).format ());
118+ assertArrayEquals (new String []{"24.0" }, payload .ofChannel (3 ).format ());
113119
114120 // verify we can also get data by type
115- Assertions . assertArrayEquals (new String []{"52.0225" , "4.6925" , "-17.00" },
121+ assertArrayEquals (new String []{"52.0225" , "4.6925" , "-17.00" },
116122 payload .ofType (ECayenneItem .GPS_LOCATION ).format ());
117- Assertions . assertArrayEquals (new String []{"4.15" }, payload .ofType (ECayenneItem .ANALOG_INPUT ).format ());
118- Assertions . assertArrayEquals (new String []{"24.0" }, payload .ofType (ECayenneItem .TEMPERATURE ).format ());
123+ assertArrayEquals (new String []{"4.15" }, payload .ofType (ECayenneItem .ANALOG_INPUT ).format ());
124+ assertArrayEquals (new String []{"24.0" }, payload .ofType (ECayenneItem .TEMPERATURE ).format ());
119125
120126 // verify non-existing channel and type
121- Assertions . assertNull (payload .ofChannel (0 ));
122- Assertions . assertNull (payload .ofType (ECayenneItem .BAROMETER ));
127+ assertNull (payload .ofChannel (0 ));
128+ assertNull (payload .ofType (ECayenneItem .BAROMETER ));
123129
124130 // verify toString method
125- Assertions . assertNotNull (payload .toString ());
131+ assertNotNull (payload .toString ());
126132 }
127133
128134 /**
@@ -134,31 +140,31 @@ public void testActualData2() throws CayenneException {
134140 public void testParseEmpty () throws CayenneException {
135141 CayenneMessage payload = new CayenneMessage ();
136142 payload .parse (new byte [0 ]);
137- Assertions . assertTrue (payload .getItems ().isEmpty ());
143+ assertTrue (payload .getItems ().isEmpty ());
138144 }
139145
140146 /**
141147 * Verifies parsing a short buffer
142148 */
143149 @ Test
144150 public void testShortBuffer () {
145- Assertions . assertThrows (CayenneException .class , () -> new CayenneMessage ().parse (new byte []{0 }));
151+ assertThrows (CayenneException .class , () -> new CayenneMessage ().parse (new byte []{0 }));
146152 }
147153
148154 /**
149155 * Verifies parsing of a buffer containing a non-supported data type.
150156 */
151157 @ Test
152158 public void testInvalidType () {
153- Assertions . assertThrows (CayenneException .class , () -> new CayenneMessage ().parse (new byte []{0 , 100 }));
159+ assertThrows (CayenneException .class , () -> new CayenneMessage ().parse (new byte []{0 , 100 }));
154160 }
155161
156162 /**
157163 * Verifies parsing of a buffer containing insufficient data during parsing.
158164 */
159165 @ Test
160166 public void testShortData () {
161- Assertions . assertThrows (CayenneException .class , () ->
167+ assertThrows (CayenneException .class , () ->
162168 new CayenneMessage ().parse (new byte []{2 , 1 }));
163169 }
164170
@@ -176,7 +182,7 @@ public void encodeFloat() throws CayenneException {
176182
177183 CayenneMessage decoded = new CayenneMessage ();
178184 decoded .parse (encoded );
179- Assertions . assertEquals (-12.34 , decoded .getItems ().get (0 ).getValues ()[0 ].doubleValue (), 0.01 );
185+ assertEquals (-12.34 , decoded .getItems ().get (0 ).getValues ()[0 ].doubleValue (), 0.01 );
180186 }
181187
182188 /**
@@ -194,9 +200,9 @@ public void encodeHumidity() throws CayenneException {
194200 decoded .parse (encoded );
195201
196202 CayenneItem item = decoded .getItems ().get (0 );
197- Assertions . assertEquals (ECayenneItem .HUMIDITY , item .getType ());
198- Assertions . assertEquals (35.5 , item .getValues ()[0 ].doubleValue (), 0.1 );
199- Assertions . assertEquals ("35.5" , item .format ()[0 ]);
203+ assertEquals (ECayenneItem .HUMIDITY , item .getType ());
204+ assertEquals (35.5 , item .getValues ()[0 ].doubleValue (), 0.1 );
205+ assertEquals ("35.5" , item .format ()[0 ]);
200206 }
201207
202208 /**
@@ -214,8 +220,8 @@ public void testDigitalInput() throws CayenneException {
214220 decoded .parse (encoded );
215221
216222 CayenneItem item = decoded .getItems ().get (0 );
217- Assertions . assertEquals (ECayenneItem .DIGITAL_INPUT , item .getType ());
218- Assertions . assertEquals (1 , item .getValues ()[0 ].intValue ());
223+ assertEquals (ECayenneItem .DIGITAL_INPUT , item .getType ());
224+ assertEquals (1 , item .getValues ()[0 ].intValue ());
219225 }
220226
221227 /**
@@ -231,9 +237,9 @@ public void testPresence() throws CayenneException {
231237 decoded .parse (encoded );
232238
233239 CayenneItem item = decoded .getItems ().get (0 );
234- Assertions . assertEquals (ECayenneItem .PRESENCE , item .getType ());
235- Assertions . assertEquals (7 , item .getValues ()[0 ].intValue ());
236- Assertions . assertEquals ("7" , item .format ()[0 ]);
240+ assertEquals (ECayenneItem .PRESENCE , item .getType ());
241+ assertEquals (7 , item .getValues ()[0 ].intValue ());
242+ assertEquals ("7" , item .format ()[0 ]);
237243 }
238244
239245 /**
@@ -245,8 +251,8 @@ public void testPackedFormat() throws CayenneException {
245251 byte [] data = {0x67 , 0x01 , 0x10 , 0x67 , 0x00 , (byte ) 0xFF };
246252 message .parse (data );
247253
248- Assertions . assertEquals (27.2 , message .ofChannel (0 ).getValue ().doubleValue (), 0.01 );
249- Assertions . assertEquals (25.5 , message .ofChannel (1 ).getValue ().doubleValue (), 0.01 );
254+ assertEquals (27.2 , message .ofChannel (0 ).getValue ().doubleValue (), 0.01 );
255+ assertEquals (25.5 , message .ofChannel (1 ).getValue ().doubleValue (), 0.01 );
250256 }
251257
252258}
0 commit comments