Search in sources :

Example 1 with OcsUser

use of it.niedermann.owncloud.notes.shared.model.OcsUser in project nextcloud-notes by stefan-niedermann.

the class CapabilitiesClientTest method testGetDisplayName.

@SuppressWarnings("unchecked")
@Test
public void testGetDisplayName() throws IOException {
    final var mockOcs = new OcsResponse<OcsUser>();
    mockOcs.ocs = new OcsResponse.OcsWrapper<>();
    mockOcs.ocs.data = new OcsUser();
    mockOcs.ocs.data.displayName = "Peter";
    final var responseMock = Response.success(mockOcs);
    final var callMock = mock(Call.class);
    when(ocsAPI.getUser(any())).thenReturn(callMock);
    when(callMock.execute()).thenReturn(responseMock);
    assertEquals("Peter", CapabilitiesClient.getDisplayName(ApplicationProvider.getApplicationContext(), ssoAccount, apiProvider));
    when(callMock.execute()).thenThrow(new RuntimeException() {

        @Override
        public void printStackTrace() {
        // Do not spam console, this will be printed.
        }
    });
    assertNull(CapabilitiesClient.getDisplayName(ApplicationProvider.getApplicationContext(), ssoAccount, apiProvider));
}
Also used : OcsUser(it.niedermann.owncloud.notes.shared.model.OcsUser) OcsResponse(it.niedermann.owncloud.notes.shared.model.OcsResponse) Test(org.junit.Test)

Aggregations

OcsResponse (it.niedermann.owncloud.notes.shared.model.OcsResponse)1 OcsUser (it.niedermann.owncloud.notes.shared.model.OcsUser)1 Test (org.junit.Test)1