-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from nhaarman/improve-captors
Improve argument captors
- Loading branch information
Showing
4 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
import com.nhaarman.expect.expect | ||
import com.nhaarman.mockito_kotlin.argumentCaptor | ||
import com.nhaarman.mockito_kotlin.mock | ||
import com.nhaarman.mockito_kotlin.times | ||
import com.nhaarman.mockito_kotlin.verify | ||
import com.nhaarman.expect.expect | ||
import com.nhaarman.mockito_kotlin.capture | ||
import org.junit.Test | ||
import java.util.* | ||
|
||
class ArgumentCaptorTest { | ||
|
||
@Test | ||
fun explicitCaptor() { | ||
/* Given */ | ||
val date: Date = mock() | ||
val time = argumentCaptor<Long>() | ||
|
||
/* When */ | ||
date.time = 5L | ||
|
||
verify(date).time = capture(time) | ||
expect(time.value).toBe(5L) | ||
/* Then */ | ||
val captor = argumentCaptor<Long>() | ||
verify(date).time = captor.capture() | ||
expect(captor.value).toBe(5L) | ||
} | ||
|
||
@Test | ||
fun implicitCaptor() { | ||
fun argumentCaptor_multipleValues() { | ||
/* Given */ | ||
val date: Date = mock() | ||
|
||
/* When */ | ||
date.time = 5L | ||
date.time = 7L | ||
|
||
verify(date).time = capture { | ||
expect(it).toBe(5L) | ||
} | ||
/* Then */ | ||
val captor = argumentCaptor<Long>() | ||
verify(date, times(2)).time = captor.capture() | ||
expect(captor.allValues).toBe(listOf(5, 7)) | ||
} | ||
} |
This file contains 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