• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package test
2 
3 /*
4  * The MIT License
5  *
6  * Copyright (c) 2016 Niek Haarman
7  * Copyright (c) 2007 Mockito contributors
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  */
27 
28 import com.nhaarman.expect.expect
29 import org.mockito.kotlin.eq
30 import org.mockito.kotlin.mock
31 import org.junit.After
32 import org.junit.Before
33 import org.junit.Test
34 import org.mockito.Mockito
35 
36 class EqTest : TestBase() {
37 
38     private val interfaceInstance: MyInterface = MyClass()
39     private val openClassInstance: MyClass = MyClass()
40     private val closedClassInstance: ClosedClass = ClosedClass()
41 
42     private lateinit var doAnswer: Open
43 
44     @Before
setupnull45     fun setup() {
46         /* Create a proper Mockito state */
47         doAnswer = Mockito.doAnswer { }.`when`(mock())
48     }
49 
50     @After
tearDownnull51     override fun tearDown() {
52         super.tearDown()
53 
54         /* Close `any` Mockito state */
55         doAnswer.go(0)
56     }
57 
58     @Test
eqInterfaceInstancenull59     fun eqInterfaceInstance() {
60         /* When */
61         val result = eq(interfaceInstance)
62 
63         /* Then */
64         expect(result).toNotBeNull()
65     }
66 
67     @Test
eqOpenClassInstancenull68     fun eqOpenClassInstance() {
69         /* When */
70         val result = eq(openClassInstance)
71 
72         /* Then */
73         expect(result).toNotBeNull()
74     }
75 
76     @Test
eqClosedClassInstancenull77     fun eqClosedClassInstance() {
78         /* When */
79         val result = eq(closedClassInstance)
80 
81         /* Then */
82         expect(result).toNotBeNull()
83     }
84 
85     @Test
nullArgumentnull86     fun nullArgument() {
87         /* Given */
88         val s: String? = null
89 
90         /* When */
91         val result = eq(s)
92 
93         /* Then */
94         expect(result).toBeNull()
95     }
96 
97     private interface MyInterface
98     private open class MyClass : MyInterface
99     class ClosedClass
100 }
101 
102