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