@@ -68,6 +68,9 @@ public void setUp() {
6868 shadowApplication = shadowOf (appContext );
6969 shadowApplication .setComponentNameAndServiceForBindService (serviceComponent , mockBinder );
7070
71+ // Don't call onServiceDisconnected() upon unbindService(), just like the real Android doesn't.
72+ shadowApplication .setUnbindServiceCallsOnServiceDisconnected (false );
73+
7174 binding = newBuilder ().build ();
7275 shadowOf (getMainLooper ()).idle ();
7376 }
@@ -137,6 +140,7 @@ public void testBindUnbind() throws Exception {
137140 assertThat (observer .gotUnboundEvent ).isTrue ();
138141 assertThat (observer .unboundReason .getCode ()).isEqualTo (Code .CANCELLED );
139142 assertThat (binding .isSourceContextCleared ()).isTrue ();
143+ assertThat (shadowApplication .getBoundServiceConnections ()).isEmpty ();
140144 }
141145
142146 @ Test
@@ -174,6 +178,7 @@ public void testBindFailure() throws Exception {
174178 assertThat (observer .gotUnboundEvent ).isTrue ();
175179 assertThat (observer .unboundReason .getCode ()).isEqualTo (Code .UNIMPLEMENTED );
176180 assertThat (binding .isSourceContextCleared ()).isTrue ();
181+ assertThat (shadowApplication .getBoundServiceConnections ()).isEmpty ();
177182 }
178183
179184 @ Test
@@ -187,6 +192,7 @@ public void testBindSecurityException() throws Exception {
187192 assertThat (observer .unboundReason .getCode ()).isEqualTo (Code .PERMISSION_DENIED );
188193 assertThat (observer .unboundReason .getCause ()).isEqualTo (securityException );
189194 assertThat (binding .isSourceContextCleared ()).isTrue ();
195+ assertThat (shadowApplication .getBoundServiceConnections ()).isEmpty ();
190196 }
191197
192198 @ Test
@@ -257,7 +263,8 @@ private void assertNoLockHeld() {
257263 } catch (IllegalMonitorStateException ime ) {
258264 // Expected.
259265 } catch (InterruptedException inte ) {
260- throw new AssertionError ("Interrupted exception when we shouldn't have been able to wait." , inte );
266+ throw new AssertionError (
267+ "Interrupted exception when we shouldn't have been able to wait." , inte );
261268 }
262269 }
263270
0 commit comments