mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-26 06:47:03 +03:00
Add Unit test for fetching DisplayName
This commit is contained in:
parent
af99117c75
commit
140afac576
1 changed files with 24 additions and 0 deletions
|
@ -15,12 +15,18 @@ import org.junit.runner.RunWith;
|
|||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import it.niedermann.owncloud.notes.persistence.sync.OcsAPI;
|
||||
import it.niedermann.owncloud.notes.shared.model.Capabilities;
|
||||
import it.niedermann.owncloud.notes.shared.model.OcsResponse;
|
||||
import it.niedermann.owncloud.notes.shared.model.OcsUser;
|
||||
import okhttp3.Request;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
@ -62,4 +68,22 @@ public class CapabilitiesClientTest {
|
|||
assertEquals("[1.0]", capabilities.getApiVersion());
|
||||
assertEquals("ETag should be read correctly from response but wasn't.", "1234", capabilities.getETag());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetDisplayName() throws IOException {
|
||||
final OcsResponse<OcsUser> mockOcs = new OcsResponse<>();
|
||||
mockOcs.ocs = new OcsResponse.OcsWrapper<>();
|
||||
mockOcs.ocs.data = new OcsUser();
|
||||
mockOcs.ocs.data.displayName = "Peter";
|
||||
|
||||
final Response<OcsResponse<OcsUser>> ocsUserResponseMock = Response.success(mockOcs);
|
||||
final Call<OcsResponse<OcsUser>> callMock = mock(Call.class);
|
||||
|
||||
when(callMock.execute()).thenReturn(ocsUserResponseMock);
|
||||
when(ocsAPI.getUser(any())).thenReturn(callMock);
|
||||
|
||||
final String user = CapabilitiesClient.getDisplayName(ApplicationProvider.getApplicationContext(), ssoAccount, apiProvider);
|
||||
assertEquals("Peter", user);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue