4141
4242import java .util .HashMap ;
4343import java .util .concurrent .Callable ;
44- import java .util .concurrent .CountDownLatch ;
4544import java .util .concurrent .TimeUnit ;
46- import java .util .concurrent .TimeoutException ;
4745
4846@ RunWith (AndroidJUnit4 .class )
4947public class IntegrationTests implements RCDeviceListener , ServiceConnection {
5048 private static final String TAG = "IntegrationTests" ;
5149 //private Handler testHandler;
52- static private final int TIMEOUT = 120000 ;
50+ static private final int TIMEOUT = 30000 ;
5351
5452 // Condition variables
5553 private boolean initialized ; // = false;
@@ -58,17 +56,15 @@ public class IntegrationTests implements RCDeviceListener, ServiceConnection {
5856
5957 RCDevice .RCDeviceBinder binder ;
6058
61-
6259 //@Rule
6360 //public UiThreadTestRule uiThreadTestRule = new UiThreadTestRule();
6461
6562 //@Rule
6663 //public final ServiceTestRule mServiceRule = new ServiceTestRule();
67- //public final ServiceTestRule mServiceRule = ServiceTestRule.withTimeout(60L, TimeUnit.SECONDS);
68-
69-
70-
7164
65+ /**
66+ * Test Cases
67+ */
7268 @ Before
7369 public void initialize ()
7470 {
@@ -78,31 +74,25 @@ public void initialize()
7874 serviceDisconnected = false ;
7975 }
8076
81-
8277 /*
8378 @After
8479 public void afterAction() {
8580 }
8681 */
8782
88-
89- @ Test (timeout = TIMEOUT )
9083 // Test initializing RCDevice with proper credentials and cleartext signaling
91- public void deviceInitialize_Valid () throws TimeoutException
84+ @ Test (timeout = TIMEOUT )
85+ public void deviceInitialize_Valid ()
9286 {
93- Log .i (TAG , "------------------------------------------------------------" );
9487 InstrumentationRegistry .getTargetContext ().bindService (new Intent (InstrumentationRegistry .getTargetContext (), RCDevice .class ), this , Context .BIND_AUTO_CREATE );
9588
9689 await ().atMost (10 , TimeUnit .SECONDS ).until (serviceOnConnected ());
97- //device = binder.getService();
98- //IBinder binder = mServiceRule.bindService(new Intent(InstrumentationRegistry.getTargetContext(), RCDevice.class));
9990
10091 // Get the reference to the service, or you can call public methods on the binder directly.
10192 final RCDevice device = binder .getService ();
10293
10394 HandlerThread clientHandlerThread = new HandlerThread ("client-thread" );
10495 clientHandlerThread .start ();
105- Log .e (TAG , "---- client-thread id: " + clientHandlerThread .getId ());
10696 Handler clientHandler = new Handler (clientHandlerThread .getLooper ());
10797
10898 clientHandler .post (new Runnable () {
@@ -132,7 +122,6 @@ public void run() {
132122 }
133123 });
134124
135- //Log.i(TAG, "Before wait");
136125 await ().atMost (10 , TimeUnit .SECONDS ).until (deviceOnInitialized ());
137126
138127 clientHandler .post (new Runnable () {
@@ -145,35 +134,24 @@ public void run() {
145134 await ().atMost (10 , TimeUnit .SECONDS ).until (deviceOnReleased ());
146135
147136 clientHandlerThread .quit ();
148-
149-
150137 //assertThat(released).isTrue();
151138
152- Log .i (TAG , "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" );
153-
154139 InstrumentationRegistry .getTargetContext ().unbindService (this );
155-
156- //await().atMost(15, TimeUnit.SECONDS).until(serviceOnDisconnected());
157140 }
158141
159-
142+ // Test initializing RCDevice with proper credentials and encrypted signaling
160143 @ Test (timeout = TIMEOUT )
161- // Test initializing RCDevice with proper credentials and cleartext signaling
162- public void deviceInitialize_EncryptedSignaling_Valid () throws TimeoutException
144+ public void deviceInitialize_EncryptedSignaling_Valid ()
163145 {
164- Log .i (TAG , "------------------------------------------------------------" );
165146 InstrumentationRegistry .getTargetContext ().bindService (new Intent (InstrumentationRegistry .getTargetContext (), RCDevice .class ), this , Context .BIND_AUTO_CREATE );
166147
167148 await ().atMost (10 , TimeUnit .SECONDS ).until (serviceOnConnected ());
168- //device = binder.getService();
169- //IBinder binder = mServiceRule.bindService(new Intent(InstrumentationRegistry.getTargetContext(), RCDevice.class));
170149
171150 // Get the reference to the service, or you can call public methods on the binder directly.
172151 final RCDevice device = binder .getService ();
173152
174- HandlerThread clientHandlerThread = new HandlerThread ("client-thread-2 " );
153+ HandlerThread clientHandlerThread = new HandlerThread ("client-thread" );
175154 clientHandlerThread .start ();
176- Log .e (TAG , "---- client-thread-2 id: " + clientHandlerThread .getId ());
177155 Handler clientHandler = new Handler (clientHandlerThread .getLooper ());
178156
179157 clientHandler .post (new Runnable () {
@@ -203,7 +181,6 @@ public void run() {
203181 }
204182 });
205183
206- //Log.i(TAG, "Before wait");
207184 await ().atMost (10 , TimeUnit .SECONDS ).until (deviceOnInitialized ());
208185
209186 clientHandler .post (new Runnable () {
@@ -216,15 +193,9 @@ public void run() {
216193 await ().atMost (10 , TimeUnit .SECONDS ).until (deviceOnReleased ());
217194
218195 clientHandlerThread .quit ();
219-
220-
221196 //assertThat(released).isTrue();
222197
223- Log .i (TAG , "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" );
224-
225198 InstrumentationRegistry .getTargetContext ().unbindService (this );
226-
227- //await().atMost(15, TimeUnit.SECONDS).until(serviceOnDisconnected());
228199 }
229200
230201
@@ -252,13 +223,15 @@ public Boolean call() throws Exception {
252223 }
253224 };
254225 }
226+ /*
255227 private Callable<Boolean> serviceOnDisconnected() {
256228 return new Callable<Boolean>() {
257229 public Boolean call() throws Exception {
258230 return serviceDisconnected; // The condition that must be fulfilled
259231 }
260232 };
261233 }
234+ */
262235
263236
264237 /**
@@ -281,26 +254,27 @@ public void onInitialized(RCDevice device, RCDeviceListener.RCConnectivityStatus
281254 initialized = true ;
282255 }
283256 }
284-
285257 public void onReleased (RCDevice device , int statusCode , String statusText )
286258 {
287259 Log .i (TAG , "%% onReleased" );
288260 if (statusCode == 0 ) {
289261 released = true ;
290262 }
291263 }
292-
293264 public void onConnectivityUpdate (RCDevice device , RCConnectivityStatus connectivityStatus )
294265 {
295266 Log .i (TAG , "%% onConnectivityUpdate" );
296267
297268 }
298-
299269 public void onMessageSent (RCDevice device , int statusCode , String statusText , String jobId )
300270 {
301271 Log .i (TAG , "%% onMessageSent" );
302272 }
303273
274+
275+ /**
276+ * Service callbacks
277+ */
304278 @ Override
305279 public void onServiceConnected (ComponentName name , IBinder service )
306280 {
@@ -310,6 +284,7 @@ public void onServiceConnected(ComponentName name, IBinder service)
310284 serviceConnected = true ;
311285 }
312286
287+ // Notice that this isn't called as a result of unbind
313288 @ Override
314289 public void onServiceDisconnected (ComponentName name )
315290 {
0 commit comments