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

Add ContributorsRepository Tests #130

Merged
merged 7 commits into from Feb 7, 2017

Conversation

Projects
None yet
4 participants
@kikuchy
Contributor

kikuchy commented Feb 6, 2017

Issue

  • N/A

Overview (Required)

  • Create interfaces ContributorsReadWriteDataSource ContributorsReadDataSource for abstracting ContributorsLocalDataSource and ContributorsRemoteDataSource
  • Add ContributorsRepositoryTest

Links

  • N/A

Screenshot

N/A

Note

I want to use kmockito to mock DataSource interfaces in a test code.
But I'm not good at usage of kmockito and mockito, so I make mock (stub) class by hands.
Please tell me a good way of how to mock interfaces if you know.

+ }
+ val remoteRepository = object : ContributorsReadDataSource {
+ override fun findAll(): Single<List<Contributor>> = Single.just(listOf())
+ }

This comment has been minimized.

@kikuchy

kikuchy Feb 6, 2017

Contributor

I mocked interfaces by hands. I want to use mockito if it can 😢

@kikuchy

kikuchy Feb 6, 2017

Contributor

I mocked interfaces by hands. I want to use mockito if it can 😢

This comment has been minimized.

@kgmyshin

kgmyshin Feb 6, 2017

Contributor

This comment has been minimized.

@kikuchy

kikuchy Feb 6, 2017

Contributor

Thanks @kgmyshin ! 🙌

@kikuchy

kikuchy Feb 6, 2017

Contributor

Thanks @kgmyshin ! 🙌

This comment has been minimized.

@kikuchy

kikuchy Feb 6, 2017

Contributor

Thanks again!

But I have a question.

I make DataSources open public class and use mock<ContributorsLocalDataSource>().
But Mockito rises a reflection error on my Mac (not on Circle CI, it looks like there are no errors for me).

org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: class io.github.droidkaigi.confsched2017.repository.contributors.ContributorsLocalDataSource.

Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.


Java               : 1.8
JVM vendor name    : Oracle Corporation
JVM vendor version : 25.5-b02
JVM name           : Java HotSpot(TM) 64-Bit Server VM
JVM version        : 1.8.0_05-b13
JVM info           : mixed mode
OS name            : Mac OS X
OS version         : 10.12.3


Underlying exception : java.lang.IllegalArgumentException: object is not an instance of declaring class

https://github.com/kikuchy/conference-app-2017/blob/d26b8154e65baa1068c56c892b04516cad8f2357/app/src/test/java/io/github/droidkaigi/confsched2017/repository/contributors/ContributorsRepositoryTest.kt#L13

What is difference between your code and my code...? 🤔

@kikuchy

kikuchy Feb 6, 2017

Contributor

Thanks again!

But I have a question.

I make DataSources open public class and use mock<ContributorsLocalDataSource>().
But Mockito rises a reflection error on my Mac (not on Circle CI, it looks like there are no errors for me).

org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: class io.github.droidkaigi.confsched2017.repository.contributors.ContributorsLocalDataSource.

Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.


Java               : 1.8
JVM vendor name    : Oracle Corporation
JVM vendor version : 25.5-b02
JVM name           : Java HotSpot(TM) 64-Bit Server VM
JVM version        : 1.8.0_05-b13
JVM info           : mixed mode
OS name            : Mac OS X
OS version         : 10.12.3


Underlying exception : java.lang.IllegalArgumentException: object is not an instance of declaring class

https://github.com/kikuchy/conference-app-2017/blob/d26b8154e65baa1068c56c892b04516cad8f2357/app/src/test/java/io/github/droidkaigi/confsched2017/repository/contributors/ContributorsRepositoryTest.kt#L13

What is difference between your code and my code...? 🤔

@konifar

This comment has been minimized.

Show comment
Hide comment
@konifar

konifar Feb 6, 2017

Collaborator

Sorry, I'll go to bed. Let me check this tomorrow 😃

Collaborator

konifar commented Feb 6, 2017

Sorry, I'll go to bed. Let me check this tomorrow 😃

@k-kagurazaka

This comment has been minimized.

Show comment
Hide comment
@k-kagurazaka

k-kagurazaka Feb 6, 2017

Contributor

ContributorsRepository aggregates data sources as interface but receives actual class instances by constructor.
When the type of arguments of the constructor will be changed to interface, we can keep ContributorsLocalDataSource final since no need to mock the actual class directly.

Contributor

k-kagurazaka commented Feb 6, 2017

ContributorsRepository aggregates data sources as interface but receives actual class instances by constructor.
When the type of arguments of the constructor will be changed to interface, we can keep ContributorsLocalDataSource final since no need to mock the actual class directly.

@kikuchy

This comment has been minimized.

Show comment
Hide comment
@kikuchy

kikuchy Feb 7, 2017

Contributor

Thanks @k-kagurazaka ! 😄

Now ContributorsReadWriteDataSource and ContributorsReadDataSource is no use.
I removed them.

Contributor

kikuchy commented Feb 7, 2017

Thanks @k-kagurazaka ! 😄

Now ContributorsReadWriteDataSource and ContributorsReadDataSource is no use.
I removed them.

@konifar

This comment has been minimized.

Show comment
Hide comment
@konifar

konifar Feb 7, 2017

Collaborator

As first test, it looks good.

Collaborator

konifar commented Feb 7, 2017

As first test, it looks good.

@konifar

This comment has been minimized.

Show comment
Hide comment
@konifar

konifar Feb 7, 2017

Collaborator

Thanks for contribution!!

Collaborator

konifar commented Feb 7, 2017

Thanks for contribution!!

@konifar konifar merged commit 917eff6 into DroidKaigi:master Feb 7, 2017

1 check passed

ci/circleci Your tests passed on CircleCI!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment