1
1
package org.amshove.kluent
2
2
3
+ import org.junit.Assert.*
3
4
import org.junit.ComparisonFailure
4
5
import kotlin.reflect.KClass
5
- import org.junit.Assert.*
6
- import java.util.*
7
6
8
7
infix fun Any .`should equal` (theOther : Any ) = assertEquals(theOther, this )
9
8
infix fun Any .`should not equal` (theOther : Any ) = assertNotEquals(theOther, this )
@@ -25,12 +24,12 @@ infix fun <T : Exception> (() -> Unit).`should throw`(expectedException: KClass<
25
24
this .invoke()
26
25
fail(" There was an Exception expected to be thrown, but nothing was thrown" , " $expectedException " , " None" )
27
26
} catch (e: Exception ) {
28
- if (expectedException.javaObjectType == AnyException :: class .javaObjectType ) {
27
+ if (expectedException.isAnyException() ) {
29
28
return
30
29
}
31
- if (e.javaClass == expectedException.javaObjectType) {
32
- Unit
33
- } else throw ComparisonFailure ( " Expected ${expectedException.javaObjectType} to be thrown " , " ${expectedException.javaObjectType} " , " ${e.javaClass} " )
30
+ if (e.javaClass ! == expectedException.javaObjectType) {
31
+ throw ComparisonFailure ( " Expected ${expectedException.javaObjectType} to be thrown " , " ${expectedException.javaObjectType} " , " ${e.javaClass} " )
32
+ }
34
33
}
35
34
}
36
35
@@ -48,15 +47,13 @@ infix fun <T : Exception> (() -> Unit).`should throw the Exception`(expectedExce
48
47
infix fun <T : Exception > (() -> Unit ).`should not throw `(expectedException : KClass <T >) {
49
48
try {
50
49
this .invoke()
51
- Unit
52
50
} catch (e: Exception ) {
53
- if (expectedException.javaObjectType == AnyException :: class .javaObjectType ) {
51
+ if (expectedException.isAnyException() ) {
54
52
fail(" Expected no Exception to be thrown" , " No Exception" , " ${e.javaClass} " )
55
53
}
56
54
if (e.javaClass == expectedException.javaObjectType) {
57
55
fail(" Expected ${expectedException.javaObjectType} to not be thrown" , " ${e.javaClass} " , " ${expectedException.javaObjectType} " )
58
56
}
59
- Unit
60
57
}
61
58
}
62
59
@@ -65,7 +62,7 @@ infix fun <T : Exception> (() -> Unit).`should not throw the Exception`(expected
65
62
this .invoke()
66
63
return NotThrowExceptionResult (noException)
67
64
} catch (e: Exception ) {
68
- if (expectedException.javaObjectType == AnyException :: class .javaObjectType ) {
65
+ if (expectedException.isAnyException() ) {
69
66
fail(" Expected no Exception to be thrown" , " No Exception" , " ${e.javaClass} " )
70
67
}
71
68
return NotThrowExceptionResult (e)
@@ -85,6 +82,7 @@ val AnyException = AnyException::class
85
82
class AnyException : Exception () {}
86
83
87
84
private val noException = Exception (" None" )
85
+ private fun <T : Exception > KClass<T>.isAnyException () = this .javaObjectType == AnyException .javaObjectType
88
86
private fun fail (message : String , expected : String , actual : String ): Nothing = throw ComparisonFailure (message, expected, actual)
89
87
private fun <T > join (theArray : Array <T >): String = theArray.joinToString(" , " )
90
88
private fun <T > join (theIterable : Iterable <T >): String = theIterable.joinToString(" , " )
0 commit comments