-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganize tests by command type grouping
- Loading branch information
John Loehrer
committed
Aug 8, 2024
1 parent
a724fb6
commit d978222
Showing
9 changed files
with
1,445 additions
and
1,312 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
.../test/src/test/scala/com/github/scoquelin/arugula/LettuceRedisBaseAsyncCommandsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.scoquelin.arugula | ||
|
||
import io.lettuce.core.RedisFuture | ||
import org.mockito.Mockito.{verify, when} | ||
import org.scalatest.matchers.must.Matchers | ||
import org.scalatest.{FutureOutcome, wordspec} | ||
|
||
|
||
class LettuceRedisBaseAsyncCommandsSpec extends wordspec.FixtureAsyncWordSpec with Matchers { | ||
|
||
override type FixtureParam = LettuceRedisCommandsClientFixture.TestContext | ||
|
||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = | ||
withFixture(test.toNoArgAsyncTest(new LettuceRedisCommandsClientFixture.TestContext)) | ||
|
||
"LettuceRedisBaseAsyncCommands" should { | ||
|
||
"delegate PING command to Lettuce and lift result into a Future" in { testContext => | ||
import testContext._ | ||
|
||
val expectedValue = "PONG" | ||
val mockRedisFuture: RedisFuture[String] = mockRedisFutureToReturn(expectedValue) | ||
when(lettuceAsyncCommands.ping()).thenReturn(mockRedisFuture) | ||
|
||
testClass.ping.map { result => | ||
result mustBe expectedValue | ||
verify(lettuceAsyncCommands).ping() | ||
succeed | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
.../test/src/test/scala/com/github/scoquelin/arugula/LettuceRedisCommandsClientFixture.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.github.scoquelin.arugula | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
import com.github.scoquelin.arugula.connection.RedisConnection | ||
import io.lettuce.core.RedisFuture | ||
import org.mockito.Mockito.when | ||
import org.scalatestplus.mockito.MockitoSugar | ||
|
||
import java.util.concurrent.CompletableFuture | ||
|
||
object LettuceRedisCommandsClientFixture { | ||
import io.lettuce.core.api.async.{RedisAsyncCommands => JRedisAsyncCommands} | ||
|
||
|
||
class Mocks extends MockitoSugar { | ||
val redisConnection: RedisConnection[String, String] = mock[RedisConnection[String, String]] | ||
val lettuceAsyncCommands: JRedisAsyncCommands[String, String] = mock[JRedisAsyncCommands[String, String]] | ||
def redisFuture[T]: RedisFuture[T] = mock[RedisFuture[T]] | ||
} | ||
|
||
class TestContext(implicit executionContext: ExecutionContext) { | ||
val mocks = new Mocks | ||
val redisConnection: RedisConnection[String, String] = mocks.redisConnection | ||
val lettuceAsyncCommands: JRedisAsyncCommands[String, String] = mocks.lettuceAsyncCommands | ||
|
||
def mockRedisFutureToReturn[T](value: T): RedisFuture[T] = { | ||
val redisFuture = mocks.redisFuture[T] | ||
val completableFuture = new CompletableFuture[T]() | ||
completableFuture.complete(value) | ||
when(redisFuture.toCompletableFuture).thenReturn(completableFuture) | ||
redisFuture | ||
} | ||
|
||
when(redisConnection.async).thenReturn(Future.successful(lettuceAsyncCommands)) | ||
|
||
val testClass = new LettuceRedisCommandsClient[String, String](redisConnection, cluster = false) | ||
} | ||
|
||
} |
Oops, something went wrong.