File tree Expand file tree Collapse file tree
src/test/kotlin/com/baeldung/kotlin Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020 </dependency >
2121 <dependency >
2222 <groupId >org.mockito</groupId >
23- <artifactId >mockito-all </artifactId >
23+ <artifactId >mockito-core </artifactId >
2424 <version >${mockito.version} </version >
2525 <scope >test</scope >
2626 </dependency >
3030 <version >${junit.version} </version >
3131 <scope >test</scope >
3232 </dependency >
33+ <dependency >
34+ <groupId >com.nhaarman</groupId >
35+ <artifactId >mockito-kotlin</artifactId >
36+ <version >${mockito-kotlin.version} </version >
37+ <scope >test</scope >
38+ </dependency >
3339 </dependencies >
3440
35-
3641 <build >
3742 <sourceDirectory >${project.basedir} /src/main/kotlin</sourceDirectory >
3843 <testSourceDirectory >${project.basedir} /src/test/kotlin</testSourceDirectory >
106111 </build >
107112
108113 <properties >
109- <mockito .version>1.9.5 </mockito .version>
114+ <mockito .version>2.8.9 </mockito .version>
110115 <junit .version>4.12</junit .version>
111116 <kotlin .version>1.1.2-4</kotlin .version>
117+ <mockito-kotlin .version>1.5.0</mockito-kotlin .version>
112118 <maven-compiler .version>3.5.1</maven-compiler .version>
113119 </properties >
114120
Original file line number Diff line number Diff line change 11package com.baeldung.kotlin ;
22
3- import org.junit.Assert
43import org.junit.Test
5- import java.lang.IllegalStateException
6- import org.mockito.InjectMocks
74import org.mockito.Mockito
85
96class LibraryManagementTest {
@@ -28,6 +25,6 @@ class LibraryManagementTest {
2825
2926 manager.checkout(100 , 1 )
3027
31- Mockito .` verify` (mockBookService).lend(100 , 1 )
28+ Mockito .verify(mockBookService).lend(100 , 1 )
3229 }
3330}
Original file line number Diff line number Diff line change 1+ package com.baeldung.kotlin ;
2+
3+ import com.nhaarman.mockito_kotlin.mock
4+ import com.nhaarman.mockito_kotlin.verify
5+ import com.nhaarman.mockito_kotlin.whenever
6+ import org.junit.Test
7+
8+ class LibraryManagementTestMockitoKotlin {
9+ @Test(expected = IllegalStateException ::class )
10+ fun whenBookIsNotAvailable_thenAnExceptionIsThrown () {
11+ val mockBookService = mock<BookService >()
12+
13+ whenever(mockBookService.inStock(100 )).thenReturn(false )
14+
15+ val manager = LendBookManager (mockBookService)
16+
17+ manager.checkout(100 , 1 )
18+ }
19+
20+ @Test
21+ fun whenBookIsAvailable_thenLendMethodIsCalled () {
22+ val mockBookService : BookService = mock()
23+
24+ whenever(mockBookService.inStock(100 )).thenReturn(true )
25+
26+ val manager = LendBookManager (mockBookService)
27+
28+ manager.checkout(100 , 1 )
29+
30+ verify(mockBookService).lend(100 , 1 )
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments