コード例 #1
0
 @Test(expected = IOException.class)
 public void networkFails_increasesStats() throws Exception {
   doThrow(new IOException()).when(call).execute();
   syncResult.stats.numIoExceptions = 3;
   try {
     syncAdapter.onPerformSync(null, extras, null, contentProviderClient, syncResult);
   } finally {
     assertThat(syncResult.stats.numIoExceptions).isEqualTo(4);
     verify(factory, never()).createFrom(any(GenreListDTO.class));
     verify(contentProviderClient, never()).bulkInsert(any(Uri.class), any(ContentValues[].class));
   }
 }
コード例 #2
0
  @Test(expected = RemoteException.class)
  public void contentProviderFails_setsDatabaseError() throws Exception {
    GenreListDTO dto =
        new GenreListDTO(
            Arrays.asList(
                new GenreDTO(new GenreId(12), "Adventure"),
                new GenreDTO(new GenreId(28), "Action")));
    when(call.execute()).thenReturn(Response.success(dto));

    when(contentProviderClient.bulkInsert(any(Uri.class), any(ContentValues[].class)))
        .thenThrow(new RemoteException());
    syncResult.databaseError = false;

    try {
      syncAdapter.onPerformSync(null, extras, null, contentProviderClient, syncResult);
    } finally {
      assertThat(syncResult.databaseError).isTrue();
    }
  }
コード例 #3
0
  @Test
  public void callsServiceFactoryAndContentProvider() throws Exception {
    TmdbSyncConstants.putLanguage(extras, LanguageCode.sl);
    GenreListDTO dto =
        new GenreListDTO(
            Arrays.asList(
                new GenreDTO(new GenreId(12), "Adventure"),
                new GenreDTO(new GenreId(28), "Action")));
    when(call.execute()).thenReturn(Response.success(dto));

    syncAdapter.onPerformSync(null, extras, null, contentProviderClient, syncResult);

    ContentValues values1 = new ContentValues(2);
    values1.put(GenreContract._ID, 12);
    values1.put(GenreContract.COLUMN_NAME, "Adventure");
    ContentValues values2 = new ContentValues(2);
    values2.put(GenreContract._ID, 28);
    values2.put(GenreContract.COLUMN_NAME, "Action");
    final ContentValues[] wanted = new ContentValues[] {values1, values2};

    verify(service).getMovieGenreList(eq(LanguageCode.sl));
    verify(factory).createFrom(eq(dto));
    verify(contentProviderClient).bulkInsert(eq(GenreEntity.CONTENT_URI), eq(wanted));
  }