JobServiceConnection implements ServiceConnection { @Override public synchronized void onServiceConnected(ComponentName name, IBinder service) { if (wasUnbound()) { Log.w(TAG, "Connection have been used already."); return; } binder = IRemoteJobService.Stub.asInterface(service); Set<JobInvocation> startedJobs = new HashSet<>(); for (Entry<JobInvocation, Boolean> entry : jobStatuses.entrySet()) { if (Boolean.FALSE.equals(entry.getValue())) { try { binder.start(encodeJob(entry.getKey()), callback); startedJobs.add(entry.getKey()); } catch (RemoteException remoteException) { Log.e(TAG, "Failed to start job " + entry.getKey(), remoteException); unbind(); return; } } } for (JobInvocation invocation : startedJobs) { jobStatuses.put(invocation, true); } } JobServiceConnection(IJobCallback callback, Context context); @Override synchronized void onServiceConnected(ComponentName name, IBinder service); @Override synchronized void onServiceDisconnected(ComponentName name);  }
@Test public void onServiceConnectedWrongBinder_doesNotThrow() throws Exception { IBinder binder = mock(IBinder.class); connection.onServiceConnected(null, binder); }