Skip to content

Commit

Permalink
chore(tests): AssertJ instead of Hamkrest
Browse files Browse the repository at this point in the history
  • Loading branch information
robfletcher committed Mar 1, 2018
1 parent 22e1fa8 commit 33e2228
Show file tree
Hide file tree
Showing 26 changed files with 409 additions and 534 deletions.
1 change: 0 additions & 1 deletion gradle/spek.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ dependencies {
testCompile "org.jetbrains.spek:spek-subject-extension:$spekVersion"
testCompile "com.nhaarman:mockito-kotlin:1.5.0"
testCompile "org.assertj:assertj-core:3.9.0"
testCompile "com.natpryce:hamkrest:1.4.2.2"
testCompile "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"

testRuntime "org.junit.platform:junit-platform-launcher:$junitVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,10 @@

package com.netflix.spinnaker.orca.dryrun

import com.natpryce.hamkrest.greaterThan
import com.natpryce.hamkrest.should.shouldMatch
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder
import com.netflix.spinnaker.orca.pipeline.model.Stage
import com.netflix.spinnaker.orca.q.buildSyntheticStages
import com.netflix.spinnaker.orca.q.buildTasks
import com.netflix.spinnaker.orca.q.multiTaskStage
import com.netflix.spinnaker.orca.q.pipeline
import com.netflix.spinnaker.orca.q.singleTaskStage
import com.netflix.spinnaker.orca.q.stage
import com.netflix.spinnaker.orca.q.stageWithParallelBranches
import com.netflix.spinnaker.orca.q.stageWithSyntheticBefore
import com.netflix.spinnaker.orca.q.stageWithSyntheticBeforeAndNoTasks
import com.netflix.spinnaker.orca.q.zeroTaskStage
import com.netflix.spinnaker.spek.shouldEqual
import com.netflix.spinnaker.orca.q.*
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
Expand Down Expand Up @@ -61,8 +50,8 @@ object DryRunStageTest : Spek({

it("constructs a single task") {
pipeline.stageByRef("1").tasks.let {
it.size shouldEqual 1
it.first().implementingClass shouldEqual DryRunTask::class.qualifiedName
assertThat(it.size).isEqualTo(1)
assertThat(it.first().implementingClass).isEqualTo(DryRunTask::class.qualifiedName)
}
}
}
Expand All @@ -84,7 +73,7 @@ object DryRunStageTest : Spek({
}

it("does not build any synthetic stages") {
pipeline.stages.size shouldEqual 1
assertThat(pipeline.stages.size).isEqualTo(1)
}
}
}
Expand All @@ -105,7 +94,7 @@ object DryRunStageTest : Spek({
}

it("builds the usual synthetic stages") {
pipeline.stages.size shouldMatch greaterThan(1)
assertThat(pipeline.stages.size).isGreaterThan(1)
}
}
}
Expand All @@ -126,7 +115,7 @@ object DryRunStageTest : Spek({
}

it("builds the usual parallel stages") {
pipeline.stages.size shouldMatch greaterThan(1)
assertThat(pipeline.stages.size).isGreaterThan(1)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion orca-queue-tck/orca-queue-tck.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apply from: "$rootDir/gradle/kotlin.gradle"

dependencies {
compile "com.nhaarman:mockito-kotlin:1.5.0"
compile "com.natpryce:hamkrest:1.4.2.0"
compile "org.assertj:assertj-core:3.9.0"

compile "org.springframework.boot:spring-boot-test:${spinnaker.version('springBoot')}"
compile "com.netflix.spinnaker.keiko:keiko-mem:$keikoVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package com.netflix.spinnaker.orca.q

import com.natpryce.hamkrest.Matcher
import com.natpryce.hamkrest.equalTo
import com.natpryce.hamkrest.has
import com.netflix.spinnaker.orca.ExecutionStatus.NOT_STARTED
import com.netflix.spinnaker.orca.events.ExecutionComplete
import com.netflix.spinnaker.orca.pipeline.model.Execution
Expand All @@ -29,19 +26,19 @@ import org.springframework.context.ApplicationListener
import org.springframework.context.ConfigurableApplicationContext
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.function.Predicate

/**
* An [ApplicationListener] implementation you can use to wait for an execution
* to complete. Much better than `Thread.sleep(whatever)` in your tests.
*/
class ExecutionLatch(matcher: Matcher<ExecutionComplete>)
class ExecutionLatch(private val predicate: Predicate<ExecutionComplete>)
: ApplicationListener<ExecutionComplete> {

private val predicate = matcher.asPredicate()
private val latch = CountDownLatch(1)

override fun onApplicationEvent(event: ExecutionComplete) {
if (predicate.invoke(event)) {
if (predicate.test(event)) {
latch.countDown()
}
}
Expand All @@ -50,9 +47,9 @@ class ExecutionLatch(matcher: Matcher<ExecutionComplete>)
}

fun ConfigurableApplicationContext.runToCompletion(execution: Execution, launcher: (Execution) -> Unit, repository: ExecutionRepository) {
val latch = ExecutionLatch(
has(ExecutionComplete::getExecutionId, equalTo(execution.id))
)
val latch = ExecutionLatch(Predicate<ExecutionComplete> {
it.executionId == execution.id
})
addApplicationListener(latch)
launcher.invoke(execution)
assert(latch.await()) { "Pipeline did not complete" }
Expand All @@ -62,9 +59,9 @@ fun ConfigurableApplicationContext.runToCompletion(execution: Execution, launche

fun ConfigurableApplicationContext.restartAndRunToCompletion(stage: Stage, launcher: (Execution, String) -> Unit, repository: ExecutionRepository) {
val execution = stage.execution
val latch = ExecutionLatch(
has(ExecutionComplete::getExecutionId, equalTo(execution.id))
)
val latch = ExecutionLatch(Predicate {
it.executionId == execution.id
})
addApplicationListener(latch)
launcher.invoke(execution, stage.id)
assert(latch.await()) { "Pipeline did not complete after restarting" }
Expand All @@ -77,10 +74,10 @@ private fun ExecutionRepository.waitForAllStagesToComplete(execution: Execution)
while (!complete) {
Thread.sleep(100)
complete = retrieve(PIPELINE, execution.id)
.run {
status.isComplete && stages
.map(Stage::getStatus)
.all { it.isComplete || it == NOT_STARTED }
}
.run {
status.isComplete && stages
.map(Stage::getStatus)
.all { it.isComplete || it == NOT_STARTED }
}
}
}
Loading

0 comments on commit 33e2228

Please sign in to comment.