This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.nhaarman.mockitokotlin2.argumentCaptor | |
| import com.nhaarman.mockitokotlin2.mock | |
| import com.nhaarman.mockitokotlin2.times | |
| import com.nhaarman.mockitokotlin2.verify | |
| import org.junit.Test | |
| data class SomeArgument(val someProperty: Int) | |
| class SomeDependency { | |
| fun someFunction(someArgument: SomeArgument) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // before java 8 | |
| verify(someDependency).someFunction(argThat(new ArgumentMatcher<SomeArgument>() { | |
| @Override | |
| public boolean matches(SomeArgument argument) { | |
| return expectedProperty == argument.getSomeProperty(); | |
| } | |
| })); | |
| // java 8 | |
| verify(someDependency).someFunction(argThat(argument -> expectedProperty == argument.getSomeProperty())); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SomeObjectTest { | |
| private val someDependency = mock<SomeDependency>() | |
| private val someObject = SomeObject(someDependency) | |
| @Test | |
| fun testSomeFunction(){ | |
| // given | |
| val expectedProperty = 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.nhaarman.mockitokotlin2.argumentCaptor | |
| import com.nhaarman.mockitokotlin2.mock | |
| import com.nhaarman.mockitokotlin2.verify | |
| import org.junit.Test | |
| class SomeDependency { | |
| fun someFunction(someArgument: () -> Unit) { | |
| someArgument.invoke() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.nhaarman.mockitokotlin2.argumentCaptor | |
| import com.nhaarman.mockitokotlin2.mock | |
| import com.nhaarman.mockitokotlin2.verify | |
| import org.junit.Test | |
| data class SomeArgument(val someProperty: Int) | |
| class SomeDependency { | |
| fun someFunction(someArgument: SomeArgument) { | |
| // some code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public int returnStuff(int argument1, int argument2) { | |
| if(argument1 == 0 && argument2 < 3) { | |
| return 1; | |
| } | |
| else if (argument2 == 1 && argument2 >= 3) { | |
| return 2; | |
| } | |
| return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public String returnStuff(SomeObject argument) { | |
| if(!argument.isValid()) { | |
| return; | |
| } | |
| return "Stuff"; | |
| } | |
| public String doStuff(SomeObject argument) { | |
| if(argument.isValid()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void validateArgument1(SomeObject argument1){ | |
| if(!argument1.isValid()) { | |
| throw new Exception(); | |
| } | |
| if(!argument2.isValid()) { | |
| throw new Exception(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public String returnStuff(SomeObject argument1, SomeObject argument2){ | |
| if (!argument1.isValid()) { | |
| throw new Exception(); | |
| } | |
| if (!argument2.isValid()) { | |
| throw new Exception(); | |
| } | |
| SomeObject otherVal1 = doSomeStuff(argument1, argument2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RunWith(MockitoJUnitRunner::class) | |
| class SearchViewModelTest { | |
| @get:Rule | |
| var instantExecutorRule = InstantTaskExecutorRule() | |
| @get:Rule | |
| val coroutineTestRule = CoroutineTestRule() | |
| private lateinit var searchViewModel: SearchViewModel |
NewerOlder