Skip to content

Commit dda7ff6

Browse files
committed
improve test feedback
1 parent af0c824 commit dda7ff6

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/field/SdkJiraField.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,12 @@ private fun IssueInputParameters.setIssueType(field: JiraIssueTypeNameField) {
190190
private fun JiraCustomField.customField(): CustomField {
191191
val fields = customFieldManager.getCustomFieldObjectsByName(customFieldName)
192192
when {
193-
fields.isEmpty() -> throw IllegalArgumentException("Field name is unknown")
194-
fields.size > 1 -> throw IllegalArgumentException("Field name is not unique")
195-
else -> return fields.firstOrNull()!!
193+
fields.isEmpty() ->
194+
throw IllegalArgumentException("Field '$customFieldName' is unknown")
195+
fields.size > 1 ->
196+
throw IllegalArgumentException("Field '$customFieldName' is not unique")
197+
else ->
198+
return fields.firstOrNull()!!
196199
}
197200
}
198201

kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/util/EitherExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ inline fun <B> Either.Companion.catchJiraClientError(
7979
): Either<JiraClientError, B> = catch(f).mapLeft {
8080
JiraClientError(
8181
error = error ?: "Jira-Fehler",
82-
message = message ?: it.message ?: "-",
82+
message = message ?: it.localizedMessage ?: it.message ?: "-",
8383
stacktrace = it.stackTraceToString(),
8484
500
8585
)

kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/JiraIssueOperatorTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ interface JiraIssueOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFiel
3939
@Test
4040
fun issues_01DeleteAllIssuesAndCreateTenTestIssues() {
4141
runBlocking {
42-
val result = either {
42+
either {
4343
val existingIssueIds = issueOperator.getIssuesByJQL("") { jsonObject, _ ->
4444
Either.Right(jsonObject.getAsJsonPrimitive("key").asString)
4545
}
4646

4747
existingIssueIds.orFail().forEach {
48-
issueOperator.deleteIssue(it)
48+
issueOperator.deleteIssue(it).orFail()
4949
}
5050

5151
(1..10).forEach { searchedKeyIndex ->
@@ -62,8 +62,7 @@ interface JiraIssueOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFiel
6262
fields
6363
).bind()
6464
}
65-
}
66-
assertThat(result is Either.Right, equalTo(true))
65+
}.orFail()
6766
}
6867
}
6968

kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/util/AssertionExtensions.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ import junit.framework.TestCase
2525

2626
internal fun <R> Either<JiraClientError, R?>.orFail(): R {
2727
this.mapLeft {
28-
TestCase.fail("Unexpected JiraClientError: ${it.error} - ${it.message}")
28+
val msg = "Unexpected JiraClientError: ${it.error} - ${it.message}"
29+
TestCase.fail(msg)
2930
}
3031
return this.getOrNull()!!
3132
}
3233

3334
internal fun Either<JiraClientError, Unit>.orFail() {
3435
this.mapLeft {
35-
TestCase.fail("Unexpected JiraClientError: ${it.error} - ${it.message}")
36+
val msg = "Unexpected JiraClientError: ${it.error} - ${it.message}"
37+
TestCase.fail(msg)
3638
}
3739
}
3840

kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/util/JiraIssueTestHelper.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fun issueParser(jsonObject: JsonObject, map: Map<String, String>): Either<JiraCl
8787

8888
fun fieldByName(name: String): JsonElement? =
8989
fields
90-
.get(resolveConfig(name, map))
90+
.getNullSafe(resolveConfig(name, map))
9191
?.let { if (it.isJsonNull) null else it }
9292

9393
val key = jsonObject.get("key").asString
@@ -111,13 +111,13 @@ fun issueParser(jsonObject: JsonObject, map: Map<String, String>): Either<JiraCl
111111

112112
val statusObject: JsonObject = fields.get("status").asJsonObject
113113
val status = JiraStatus(
114-
statusObject.get("id").asString,
115-
statusObject.get("name").asString,
116-
statusObject.get("statusCategory").asJsonObject.get("key").asString
114+
statusObject.getNullSafe("id")?.asString ?: "",
115+
statusObject.getNullSafe("name")?.asString ?: "",
116+
statusObject.getNullSafe("statusCategory")?.asJsonObject?.getNullSafe("key")?.asString ?: ""
117117
)
118118

119119
val transitions =
120-
jsonObject.get("transitions")?.asJsonArray
120+
jsonObject.getNullSafe("transitions")?.asJsonArray
121121
?.map {
122122
val transition = it.asJsonObject
123123
val name = transition.get("name").asString
@@ -150,8 +150,14 @@ fun issueParser(jsonObject: JsonObject, map: Map<String, String>): Either<JiraCl
150150
)
151151
}
152152

153-
fun JsonObject.getNullSafe(fieldName: String) =
154-
if (get(fieldName)?.isJsonNull ?: true) null else get(fieldName)
153+
fun JsonObject.getNullSafe(fieldName: String): JsonElement? {
154+
if (!this.has(fieldName)) return null
155+
val jsonElement = get(fieldName)
156+
return when {
157+
jsonElement?.isJsonNull == true -> null
158+
else -> jsonElement
159+
}
160+
}
155161

156162
fun JsonArray.parseInsightFieldKey(): String = firstOrNull()?.asString?.parseInsightFieldKey() ?: ""
157163

0 commit comments

Comments
 (0)