Skip to content

Commit

Permalink
rename rightAssertedJiraClientError to orFail
Browse files Browse the repository at this point in the history
  • Loading branch information
HighKo committed Jan 10, 2024
1 parent b97687f commit d37315d
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package com.linkedplanet.kotlinjiraclient

import com.linkedplanet.kotlinjiraclient.util.rightAssertedJiraClientError
import com.linkedplanet.kotlinjiraclient.util.orFail
import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.notNullValue
Expand All @@ -43,7 +43,7 @@ interface JiraCommentOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFi

val comments = runBlocking {
commentOperator.getComments(issue.key)
}.rightAssertedJiraClientError()
}.orFail()

assertThat(comments, notNullValue())
assertThat(comments.size, equalTo(0))
Expand All @@ -56,7 +56,7 @@ interface JiraCommentOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFi

val comments = runBlocking {
commentOperator.getComments(issue.key)
}.rightAssertedJiraClientError()
}.orFail()

assertThat(comments, notNullValue())
assertThat(comments.size, equalTo(1))
Expand All @@ -76,9 +76,9 @@ interface JiraCommentOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFi
commentToUpdate.id,
"Test-Update"
)
}.rightAssertedJiraClientError()
}.orFail()

val comments = runBlocking { commentOperator.getComments(issue.key) }.rightAssertedJiraClientError()
val comments = runBlocking { commentOperator.getComments(issue.key) }.orFail()
assertThat(comments.size, equalTo(1))
val comment = comments.first()

Expand All @@ -90,10 +90,10 @@ interface JiraCommentOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFi
fun comments_05DeleteComment() {
val (issue, commentToDelete) = jiraCommentTestHelper.createIssueWithComment("comments_05DeleteComment")

runBlocking { commentOperator.deleteComment(issue.key, commentToDelete.id) }.rightAssertedJiraClientError()
runBlocking { commentOperator.deleteComment(issue.key, commentToDelete.id) }.orFail()

val commentsAfterDeletion =
runBlocking { commentOperator.getComments(issue.key) }.rightAssertedJiraClientError()
runBlocking { commentOperator.getComments(issue.key) }.orFail()
assertThat(commentsAfterDeletion.size, equalTo(0))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package com.linkedplanet.kotlinjiraclient

import com.linkedplanet.kotlinjiraclient.util.rightAssertedJiraClientError
import com.linkedplanet.kotlinjiraclient.util.orFail
import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
Expand All @@ -39,7 +39,7 @@ interface JiraIssueLinkOperatorTest<JiraFieldType> : BaseTestConfigProvider<Jira
outward.key,
"Relates"
)
}.rightAssertedJiraClientError()
}.orFail()

// Check
val issueLinks = jiraIssueLinkTestHelper.getIssueLinks(inward.key)
Expand All @@ -51,7 +51,7 @@ interface JiraIssueLinkOperatorTest<JiraFieldType> : BaseTestConfigProvider<Jira
assertThat(outwardIssue.get("key").asString, equalTo(outward.key))

// Delete
runBlocking { issueLinkOperator.deleteIssueLink(issueLinkId) }.rightAssertedJiraClientError()
runBlocking { issueLinkOperator.deleteIssueLink(issueLinkId) }.orFail()

// Check
val issueLinksAfterDeletion = jiraIssueLinkTestHelper.getIssueLinks(inward.key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface JiraIssueOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFiel
Either.Right(jsonObject.getAsJsonPrimitive("key").asString)
}

existingIssueIds.rightAssertedJiraClientError().forEach {
existingIssueIds.orFail().forEach {
issueOperator.deleteIssue(it)
}

Expand Down Expand Up @@ -222,12 +222,12 @@ interface JiraIssueOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFiel
issueTypeId,
fields
)
}.rightAssertedJiraClientError()
}.orFail()
assertThat(creationResponse.self.endsWith("/rest/api/2/issue/${creationResponse.id}"), equalTo(true))

val createdIssue = runBlocking {
issueOperator.getIssueByJQL("key = \"${creationResponse.key}\"", ::issueParser)
}.rightAssertedJiraClientError()
}.orFail()

assertThat(createdIssue.projectId, equalTo(projectId))
assertThat(createdIssue.issueTypeId, equalTo(issueTypeId))
Expand Down Expand Up @@ -263,7 +263,7 @@ interface JiraIssueOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFiel

val issue = runBlocking {
issueOperator.getIssueByJQL("summary ~ \"MyNewSummary\"", ::issueParser)
}.rightAssertedJiraClientError()
}.orFail()

val summary = "MyNewSummary-update"
val description = "MyDescription-update"
Expand Down Expand Up @@ -300,11 +300,11 @@ interface JiraIssueOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFiel
fieldFactory.jiraCustomInsightObjectsField("InsightObjects", insightObjectsKeys)
)
)
}.rightAssertedJiraClientError()
}.orFail()

val issueAfterUpdate = runBlocking {
issueOperator.getIssueByKey(issue.key, ::issueParser)
}.rightAssertedJiraClientError()
}.orFail()

assertThat(issueAfterUpdate.projectId, equalTo(projectId))
assertThat(issueAfterUpdate.issueTypeId, equalTo(issueTypeId))
Expand All @@ -328,11 +328,11 @@ interface JiraIssueOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraFiel

val searchNewIssue = runBlocking {
issueOperator.getIssueByJQL("summary ~ \"MyNewSummary-update\"", ::issueParser)
}.rightAssertedJiraClientError()
}.orFail()

runBlocking {
issueOperator.deleteIssue(searchNewIssue.key)
}.rightAssertedJiraClientError()
}.orFail()

val issuesAfterDeletion = runBlocking {
issueOperator.getIssueByKey(searchNewIssue.key, ::issueParser).orNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package com.linkedplanet.kotlinjiraclient

import com.linkedplanet.kotlinjiraclient.api.model.JiraIssueTypeAttribute
import com.linkedplanet.kotlinjiraclient.util.rightAssertedJiraClientError
import com.linkedplanet.kotlinjiraclient.util.orFail
import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
Expand All @@ -31,13 +31,13 @@ interface JiraIssueTypeOperatorTest<JiraFieldType> : BaseTestConfigProvider<Jira
@Test
fun issueTypes_01GetIssueTypes() {
val issueTypeNames = listOf("Bug", "Epic", "Story", "Sub-task", "Task")
val issueTypes = runBlocking { issueTypeOperator.getIssueTypes(projectId) }.rightAssertedJiraClientError()
val issueTypes = runBlocking { issueTypeOperator.getIssueTypes(projectId) }.orFail()
assertThat(issueTypes.map { it.name }.toSet(), equalTo(issueTypeNames.toSet()))
}

@Test
fun issueTypes_02GetIssueType() {
val issueType = runBlocking { issueTypeOperator.getIssueType(issueTypeId) }.rightAssertedJiraClientError()
val issueType = runBlocking { issueTypeOperator.getIssueType(issueTypeId) }.orFail()
assertThat(issueType.id, equalTo(issueTypeId.toString()))
assertThat(issueType.name, equalTo("Story"))
}
Expand All @@ -50,7 +50,7 @@ interface JiraIssueTypeOperatorTest<JiraFieldType> : BaseTestConfigProvider<Jira
projectId,
issueTypeId
)
}.rightAssertedJiraClientError()
}.orFail()
val expectedAttributes = listOf(
"Epic Link", "Summary", "Issue Type", "Reporter", "Component/s", "Description",
"Fix Version/s", "Priority", "Labels", "Attachment", "Linked Issues", "Assignee",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package com.linkedplanet.kotlinjiraclient

import com.linkedplanet.kotlinjiraclient.util.rightAssertedJiraClientError
import com.linkedplanet.kotlinjiraclient.util.orFail
import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
Expand All @@ -31,7 +31,7 @@ interface JiraProjectOperatorTest<JiraFieldType>: BaseTestConfigProvider<JiraFie
fun projects_01GetProjects() {
val projects = runBlocking {
projectOperator.getProjects()
}.rightAssertedJiraClientError()
}.orFail()

assertThat(projects.size, equalTo(1))
assertThat(projects.first().id, equalTo("10000"))
Expand All @@ -43,7 +43,7 @@ interface JiraProjectOperatorTest<JiraFieldType>: BaseTestConfigProvider<JiraFie
fun projects_02GetProject() {
val project = runBlocking {
projectOperator.getProject(projectId)
}.rightAssertedJiraClientError()
}.orFail()

assertThat(project.id, equalTo("10000"))
assertThat(project.key, equalTo("TEST"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package com.linkedplanet.kotlinjiraclient

import com.linkedplanet.kotlinjiraclient.util.JiraUserTestHelper
import com.linkedplanet.kotlinjiraclient.util.rightAssertedJiraClientError
import com.linkedplanet.kotlinjiraclient.util.orFail
import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
Expand All @@ -30,7 +30,7 @@ interface JiraUserOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraField

@Test
fun users_01GetUsersByProjectKey() {
val users = runBlocking { userOperator.getUsersByProjectKey(projectKey) }.rightAssertedJiraClientError()
val users = runBlocking { userOperator.getUsersByProjectKey(projectKey) }.orFail()
assertThat(users.size, equalTo(2))

val admin = users.firstOrNull { it.name == "admin" }
Expand All @@ -43,7 +43,7 @@ interface JiraUserOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraField
@Test
fun users_02GetAssignableUsersByProjectKey() {
val users =
runBlocking { userOperator.getAssignableUsersByProjectKey(projectKey) }.rightAssertedJiraClientError()
runBlocking { userOperator.getAssignableUsersByProjectKey(projectKey) }.orFail()
assertThat(users.size, equalTo(3))

val admin = users.firstOrNull { it.name == "admin" }
Expand All @@ -58,7 +58,7 @@ interface JiraUserOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraField

@Test
fun users_03GetProjectAdminUsers() {
val users = runBlocking { userOperator.getProjectAdminUsers(projectKey) }.rightAssertedJiraClientError()
val users = runBlocking { userOperator.getProjectAdminUsers(projectKey) }.orFail()
assertThat(users.size, equalTo(1))

val admin = users.firstOrNull { it.name == "admin" }
Expand All @@ -67,7 +67,7 @@ interface JiraUserOperatorTest<JiraFieldType> : BaseTestConfigProvider<JiraField

@Test
fun users_04GetSystemAdminUsers() {
val users = runBlocking { userOperator.getSystemAdminUsers() }.rightAssertedJiraClientError()
val users = runBlocking { userOperator.getSystemAdminUsers() }.orFail()
assertThat(users.size, equalTo(1))

val admin = users.firstOrNull { it.name == "admin" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError
import org.junit.Assert.fail


internal fun <R> Either<JiraClientError, R?>.rightAssertedJiraClientError(): R {
internal fun <R> Either<JiraClientError, R?>.orFail(): R {
this.mapLeft {
fail("Unexpected JiraClientError: ${it.error} - ${it.message}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class JiraCommentTestHelper<JiraFieldType>(
fun createIssueWithComment(testName: String): Pair<JiraIssue, JiraIssueComment> {
val issue = jiraIssueTestHelper.createDefaultIssue(fieldFactory.jiraSummaryField("$testName ticket"))

runBlocking { commentOperator.createComment(issue.key, testName) }.rightAssertedJiraClientError()
runBlocking { commentOperator.createComment(issue.key, testName) }.orFail()
val commentsBeforeUpdate =
runBlocking { commentOperator.getComments(issue.key) }.rightAssertedJiraClientError()
runBlocking { commentOperator.getComments(issue.key) }.orFail()
assertThat(commentsBeforeUpdate.size, equalTo(1))
val commentToUpdate = commentsBeforeUpdate.first()
return Pair(issue, commentToUpdate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class JiraIssueTestHelper<JiraFieldType>(
fieldFactory.jiraIssueTypeField(jiraIssueTypeId),
).plus(fields)
issueOperator.createIssue(projectId, jiraIssueTypeId, combinedFields)
}.rightAssertedJiraClientError()
}.orFail()

fun getIssueByKey(key: String) = runBlocking {
issueOperator.getIssueByKey(key, ::issueParser)
}.rightAssertedJiraClientError()
}.orFail()
}

data class Story(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class JiraTransitionTestHelper(

fun getAvailableTransitions(issueKey: String) = runBlocking {
transitionOperator.getAvailableTransitions(issueKey)
}.rightAssertedJiraClientError()
}.orFail()

fun doTransition(issueKey: String, transitionId: String) = runBlocking {
transitionOperator.doTransition(issueKey, transitionId)
}.rightAssertedJiraClientError()
}.orFail()
}

0 comments on commit d37315d

Please sign in to comment.