|
1 | 1 | import com.nhaarman.expect.expect
|
2 | 2 | import com.nhaarman.expect.expectErrorWithMessage
|
| 3 | +import com.nhaarman.expect.fail |
3 | 4 | import com.nhaarman.mockito_kotlin.*
|
4 | 5 | import org.junit.Test
|
5 | 6 | import org.mockito.exceptions.base.MockitoAssertionError
|
@@ -376,6 +377,80 @@ class MockitoTest {
|
376 | 377 | expect(result).toBeTheSameAs(mock)
|
377 | 378 | }
|
378 | 379 |
|
| 380 | + @Test |
| 381 | + fun testMockStubbing_doThrow() { |
| 382 | + /* Given */ |
| 383 | + val mock = mock<Methods> { mock -> |
| 384 | + on { builderMethod() } doThrow IllegalArgumentException() |
| 385 | + } |
| 386 | + |
| 387 | + try { |
| 388 | + /* When */ |
| 389 | + mock.builderMethod() |
| 390 | + fail("No exception thrown") |
| 391 | + } catch(e: IllegalArgumentException) { |
| 392 | + } |
| 393 | + } |
| 394 | + |
| 395 | + @Test |
| 396 | + fun testMockStubbing_doThrowClass() { |
| 397 | + /* Given */ |
| 398 | + val mock = mock<Methods> { mock -> |
| 399 | + on { builderMethod() } doThrow IllegalArgumentException::class |
| 400 | + } |
| 401 | + |
| 402 | + try { |
| 403 | + /* When */ |
| 404 | + mock.builderMethod() |
| 405 | + fail("No exception thrown") |
| 406 | + } catch(e: IllegalArgumentException) { |
| 407 | + } |
| 408 | + } |
| 409 | + |
| 410 | + @Test |
| 411 | + fun testMockStubbing_doThrowVarargs() { |
| 412 | + /* Given */ |
| 413 | + val mock = mock<Methods> { mock -> |
| 414 | + on { builderMethod() }.doThrow(IllegalArgumentException(), UnsupportedOperationException()) |
| 415 | + } |
| 416 | + |
| 417 | + try { |
| 418 | + /* When */ |
| 419 | + mock.builderMethod() |
| 420 | + fail("No exception thrown") |
| 421 | + } catch(e: IllegalArgumentException) { |
| 422 | + } |
| 423 | + |
| 424 | + try { |
| 425 | + /* When */ |
| 426 | + mock.builderMethod() |
| 427 | + fail("No exception thrown") |
| 428 | + } catch(e: UnsupportedOperationException) { |
| 429 | + } |
| 430 | + } |
| 431 | + |
| 432 | + @Test |
| 433 | + fun testMockStubbing_doThrowClassVarargs() { |
| 434 | + /* Given */ |
| 435 | + val mock = mock<Methods> { mock -> |
| 436 | + on { builderMethod() }.doThrow(IllegalArgumentException::class, UnsupportedOperationException::class) |
| 437 | + } |
| 438 | + |
| 439 | + try { |
| 440 | + /* When */ |
| 441 | + mock.builderMethod() |
| 442 | + fail("No exception thrown") |
| 443 | + } catch(e: IllegalArgumentException) { |
| 444 | + } |
| 445 | + |
| 446 | + try { |
| 447 | + /* When */ |
| 448 | + mock.builderMethod() |
| 449 | + fail("No exception thrown") |
| 450 | + } catch(e: UnsupportedOperationException) { |
| 451 | + } |
| 452 | + } |
| 453 | + |
379 | 454 | @Test
|
380 | 455 | fun doReturn_withSingleItemList() {
|
381 | 456 | /* Given */
|
|
0 commit comments