Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove final from DTO's to support Unit Testing #104

Open
alfanse opened this issue Apr 6, 2018 · 1 comment
Open

Remove final from DTO's to support Unit Testing #104

alfanse opened this issue Apr 6, 2018 · 1 comment

Comments

@alfanse
Copy link

alfanse commented Apr 6, 2018

As a dev,
I want to write unit tests that mock the documentClient
so that I can unit test the behaviour of my classes.

Currently this is very hard thanks to the final classes returned by the documentClient.
i.e.

   import com.microsoft.azure.documentdb.*;
   import static org.assertj.core.api.Java6Assertions.assertThat;
   import static org.mockito.Matchers.*;
   import static org.mockito.Mockito.*;

...

    private void givenAResponse(List<Document> response) {
        DocumentClient documentClient = mock(DocumentClient.class);
        FeedResponse feedResponse = mock(FeedResponse.class);
        QueryIterable queryIterable = mock(QueryIterable.class);
        when(documentClient.queryDocuments(
                eq(CONNECTION_LINK),
                any(String.class),
                any(FeedOptions.class)))
            .thenReturn(feedResponse);
        when(feedResponse.getQueryIterable()).thenReturn(queryIterable);
        when(queryIterable.toList()).thenReturn(response);
    }

fails with:

  org.mockito.exceptions.base.MockitoException: 
  Cannot mock/spy class com.microsoft.azure.documentdb.FeedResponse 
  Mockito cannot mock/spy following:
    - final classes

Please can you remove 'final' from: FeedResponse and QueryIterable?

@moderakh
Copy link
Contributor

@alfanse thanks for reporting this. We are planning to drop the final keyword from some of the surface classes to make them unit testable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants