-
-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
###Feature/Add extractors and test samples for SQLException #1779
Changes from all commits
5a6b185
076c136
2f35e51
bcda35f
c491978
aab9b3f
99ec8e8
fcdcf8c
d021ec6
21f7c3d
016ac33
e33fedc
0a9ab8a
904b2e1
4521ddb
d400a45
552f710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ch.tutteli.atrium.api.fluent.en_GB | ||
|
||
import ch.tutteli.atrium.creating.Expect | ||
import ch.tutteli.atrium.creating.FeatureExpect | ||
import java.sql.SQLException | ||
|
||
/** | ||
* Extracts the [errorCode][SQLException.getErrorCode] property from the subject of the assertion. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please copy the kdoc from collectionFeatureExtractors.kt -> |
||
* | ||
* @since 1.3.0 | ||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.SQLExceptionFeaturesSamples.errorCodeFeature | ||
*/ | ||
val <T : SQLException> Expect<T>.errorCode: FeatureExpect<T, Int> | ||
get() = feature("errorCode", SQLException::getErrorCode) | ||
|
||
/** | ||
* Extracts the [errorCode][SQLException.getErrorCode] property from the subject of the assertion and makes it the new subject. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here, please copy the KDoc from collectionFeatureExtractors.kt -> fun size |
||
* | ||
* @since 1.3.0 | ||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.SQLExceptionFeaturesSamples.sqlStateFeature | ||
*/ | ||
fun <T : SQLException> Expect<T>.errorCode(assertionCreator: Expect<Int>.() -> Unit) = | ||
feature("errorCode", SQLException::getErrorCode, assertionCreator) | ||
|
||
/** | ||
* Extracts the [sqlState][SQLException.getSQLState] property from the subject of the assertion. | ||
* | ||
* @since 1.3.0 | ||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.SQLExceptionFeaturesSamples.errorCode | ||
*/ | ||
val <T : SQLException> Expect<T>.sqlState: FeatureExpect<T, String> | ||
get() = feature("sqlState", SQLException::getSQLState) | ||
|
||
/** | ||
* Extracts the [sqlState][SQLException.getSQLState] property from the subject of the assertion and makes it the new subject. | ||
* | ||
* @since 1.3.0 | ||
* @sample ch.tutteli.atrium.api.fluent.en_GB.samples.SQLExceptionFeaturesSamples.sqlState | ||
*/ | ||
fun <T : SQLException> Expect<T>.sqlState(assertionCreator: Expect<String>.() -> Unit) = | ||
feature("sqlState", SQLException::getSQLState, assertionCreator) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package ch.tutteli.atrium.api.fluent.en_GB.samples | ||
|
||
import ch.tutteli.atrium.api.fluent.en_GB.* | ||
import ch.tutteli.atrium.api.verbs.expect | ||
import java.sql.SQLException | ||
import kotlin.test.Test | ||
|
||
class SQLExceptionFeaturesSamples { | ||
|
||
@Test | ||
fun errorCodeFeature() { | ||
val exception = SQLException("Test exception", "42000", 1001) | ||
|
||
expect(exception) | ||
.errorCode // subject is now of type Int | ||
.toEqual(1001) | ||
|
||
fails { | ||
expect(exception) | ||
.errorCode // subject is now of type Int | ||
.toEqual(9999) // fails | ||
.toBeGreaterThan(1000) // not evaluated/reported because `toEqual` already fails | ||
// use `.errorCode { ... }` if you want all assertions evaluated | ||
} | ||
} | ||
|
||
@Test | ||
fun errorCode() { | ||
val exception = SQLException("Test exception", "42000", 1001) | ||
|
||
expect(exception).errorCode { // subject within this expectation-group is of type Int | ||
toBeGreaterThan(1000) | ||
toEqual(1001) | ||
} // subject here is back to type SQLException | ||
|
||
fails { | ||
expect(exception).errorCode { | ||
toEqual(9999) // fails | ||
toBeGreaterThan(1000) // still evaluated even though `toEqual` already fails | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun sqlStateFeature() { | ||
val exception = SQLException("Test exception", "42000", 1001) | ||
|
||
expect(exception) | ||
.sqlState // subject is now of type String | ||
.toEqual("42000") | ||
|
||
fails { | ||
expect(exception) | ||
.sqlState // subject is now of type String | ||
.toEqual("00000") // fails | ||
.toContain("42") // not evaluated/reported because `toEqual` already fails | ||
// use `.sqlState { ... }` if you want all assertions evaluated | ||
} | ||
} | ||
|
||
|
||
|
||
@Test | ||
fun sqlState() { | ||
val exception = SQLException("Test exception", "42000", 1001) | ||
|
||
expect(exception).sqlState { // subject within this expectation-group is of type String | ||
toEqual("42000") | ||
toContain("42") | ||
} // subject here is back to type SQLException | ||
|
||
fails { | ||
expect(exception).sqlState { | ||
toEqual("00000") // fails | ||
toContain("42") // still evaluated even though `toEqual` already fails | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you also need to generate the api for Kotlin 1.9 and newer. Run
KOTLIN_VERSION=1.9 ./gradlew apiDump
to achieve this (or copy those lines over to using-kotlin-1.9-or-newer/atrium-api-fluent.api).