Skip to content
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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5a6b185
###feature/Integrate random matrix generation and merge Ubuntu and Wi…
BereKanters Jun 11, 2024
076c136
###feature/Added feature-random-matrix-ci.patch file
BereKanters Jun 12, 2024
2f35e51
###feat/Integrate custom random matrix generation and merge Ubuntu an…
BereKanters Jun 14, 2024
bcda35f
###feat/feature extractors and test samples for SQLException
BereKanters Jun 14, 2024
c491978
###feat/Add feature extractors and test samples for SQLException
BereKanters Jun 15, 2024
aab9b3f
Merge branch 'robstoll:main' into feature/extractors-for-SQLException
BereKanters Jun 16, 2024
99ec8e8
###feature/Integrate random matrix generation and merge Ubuntu and Wi…
BereKanters Jun 11, 2024
fcdcf8c
###feature/Added feature-random-matrix-ci.patch file
BereKanters Jun 12, 2024
d021ec6
###feat/Integrate custom random matrix generation and merge Ubuntu an…
BereKanters Jun 14, 2024
21f7c3d
###feat/feature extractors and test samples for SQLException
BereKanters Jun 14, 2024
016ac33
###feat/Add feature extractors and test samples for SQLException
BereKanters Jun 15, 2024
e33fedc
Integrate Custom Random Matrix Generation and Merge Ubuntu and Window…
BereKanters Jun 16, 2024
0a9ab8a
Merge branch 'feature/extractors-for-SQLException' of https://github.…
BereKanters Jun 16, 2024
904b2e1
###Fix/Removed non needed comment
BereKanters Jun 16, 2024
4521ddb
###Fix/Re-added comment
BereKanters Jun 16, 2024
d400a45
###Fix/Added Requires java to module for sqlExceptionFeatureExtractors
BereKanters Jun 16, 2024
552f710
###Feat/Updated API declarations for new SQLException feature extractors
BereKanters Jun 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,13 @@ public final class ch/tutteli/atrium/api/fluent/en_GB/SequenceSubjectChangersKt
public static final fun asList (Lch/tutteli/atrium/creating/Expect;Lkotlin/jvm/functions/Function1;)Lch/tutteli/atrium/creating/Expect;
}

public final class ch/tutteli/atrium/api/fluent/en_GB/SqlExceptionFeatureExtractorsKt {
Copy link
Owner

@robstoll robstoll Jun 17, 2024

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).

public static final fun errorCode (Lch/tutteli/atrium/creating/Expect;Lkotlin/jvm/functions/Function1;)Lch/tutteli/atrium/creating/Expect;
public static final fun getErrorCode (Lch/tutteli/atrium/creating/Expect;)Lch/tutteli/atrium/creating/FeatureExpect;
public static final fun getSqlState (Lch/tutteli/atrium/creating/Expect;)Lch/tutteli/atrium/creating/FeatureExpect;
public static final fun sqlState (Lch/tutteli/atrium/creating/Expect;Lkotlin/jvm/functions/Function1;)Lch/tutteli/atrium/creating/Expect;
}

public final class ch/tutteli/atrium/api/fluent/en_GB/ThirdPartyExpectationsKt {
public static final fun toHoldThirdPartyExpectation (Lch/tutteli/atrium/creating/Expect;Ljava/lang/String;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lch/tutteli/atrium/creating/Expect;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
requires ch.tutteli.atrium.logic;
requires kotlin.stdlib;
requires ch.tutteli.kbox;
requires java.sql;

exports ch.tutteli.atrium.api.fluent.en_GB;
}
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.
Copy link
Owner

@robstoll robstoll Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please copy the kdoc from collectionFeatureExtractors.kt -> val size and adopt. I prefer if they are all the same, this way changes in the future can be made via search and replace.

*
* @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.
Copy link
Owner

Choose a reason for hiding this comment

The 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
}
}
}
}
Loading