@@ -0,0 +1,3263 @@
+package codes.fabio.animemuzei.remoteservice;%0A%0Aimport codes.fabio.animemuzei.AppSettings;%0Aimport codes.fabio.animemuzei.imgur.ImgurImageRemoteDataSource;%0Aimport com.google.android.apps.muzei.api.Artwork;%0Aimport com.google.android.apps.muzei.api.RemoteMuzeiArtSource;%0Aimport com.google.android.apps.muzei.api.UserCommand;%0Aimport java.util.List;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport rx.Observable;%0A%0Aimport static java.util.Arrays.asList;%0Aimport static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.is;%0Aimport static org.mockito.Matchers.anyLong;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0Apublic class RemoteServiceDelegateTest %7B%0A%0A  private RemoteServiceDelegate delegate;%0A  private List%3CUserCommand%3E userCommandList;%0A  private AppSettings appSettings;%0A  private final int MOCK_REASON = 1;%0A  private ImgurImageRemoteDataSource imgurImageRemoteDataSource;%0A  private AnimeMuzeiRemoteSourceService animeMuzeiRemoteSourceService;%0A%0A  @Before public void setUp() %7B%0A    UserCommand userCommand1 = mock(UserCommand.class);%0A    UserCommand userCommand2 = mock(UserCommand.class);%0A%0A    userCommandList = asList(userCommand1, userCommand2);%0A    appSettings = mock(AppSettings.class);%0A    imgurImageRemoteDataSource = mock(ImgurImageRemoteDataSource.class);%0A    animeMuzeiRemoteSourceService = mock(AnimeMuzeiRemoteSourceService.class);%0A%0A    when(appSettings.getUpdateIntervalMillis()).thenReturn(1000L);%0A%0A    delegate = new RemoteServiceDelegate(userCommandList, appSettings, imgurImageRemoteDataSource);%0A  %7D%0A%0A  @Test public void attachService_storesServiceFieldInValue() throws Exception %7B%0A    delegate.attachService(animeMuzeiRemoteSourceService);%0A    assertThat(delegate.getService(), is(animeMuzeiRemoteSourceService));%0A  %7D%0A%0A  @Test public void attachService_setsCustomUserCommands() %7B%0A    delegate.attachService(animeMuzeiRemoteSourceService);%0A    verify(delegate.getService()).setCustomCommands(userCommandList);%0A  %7D%0A%0A  @Test(expected = IllegalStateException.class)%0A  public void accessingServiceAfter_detachService_throwsException() %7B%0A    delegate.attachService(animeMuzeiRemoteSourceService);%0A    delegate.detachService();%0A    delegate.getService();%0A  %7D%0A%0A  @Test public void rescheduleOnly() throws Exception %7B%0A    delegate.attachService(animeMuzeiRemoteSourceService);%0A    delegate.rescheduleOnly();%0A    verify(delegate.getService()).setNextUpdate(anyLong());%0A  %7D%0A%0A  @Test(expected = RemoteMuzeiArtSource.RetryException.class)%0A  public void tryUpdate_throwsRetryException_InCaseImageResponseThrowsException() throws Exception %7B%0A%0A    when(imgurImageRemoteDataSource.nextImage()).thenThrow(new RuntimeException());%0A%0A    delegate.attachService(animeMuzeiRemoteSourceService);%0A    delegate.tryUpdate(MOCK_REASON);%0A  %7D%0A%0A  @Test public void tryUpdate_setsArtwork_andReschedules() throws Exception %7B%0A    Artwork artwork = mock(Artwork.class);%0A    when(imgurImageRemoteDataSource.nextImage()).thenReturn(Observable.just(artwork));%0A%0A    delegate.attachService(animeMuzeiRemoteSourceService);%0A    delegate.tryUpdate(MOCK_REASON);%0A    verify(delegate.getService()).setArtwork(artwork);%0A    verify(delegate.getService()).setNextUpdate(anyLong());%0A  %7D%0A%7D

Test of RemoteServiceDelegate