当前位置: 首页>>代码示例>>Scala>>正文


Scala verify类代码示例

本文整理汇总了Scala中org.mockito.Mockito.verify的典型用法代码示例。如果您正苦于以下问题:Scala verify类的具体用法?Scala verify怎么用?Scala verify使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了verify类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: SourceTrackingMonitorTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.builder

import com.twitter.finagle.{Failure, RequestException}
import java.io.IOException
import java.util.logging.{Level, Logger}
import org.junit.runner.RunWith
import org.mockito.Matchers.{any, eq => mockitoEq}
import org.mockito.Mockito.{never, verify}
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar

@RunWith(classOf[JUnitRunner])
class SourceTrackingMonitorTest extends FunSuite with MockitoSugar {
  test("handles unrolling properly") {
    val logger = mock[Logger]
    val monitor = new SourceTrackingMonitor(logger, "qux")
    val e = new Exception
    val f1 = new Failure("foo", Some(e), sources = Map(Failure.Source.Service -> "tweet"))
    val f2 = new Failure("bar", Some(f1))
    val exc = new RequestException(f2)
    exc.serviceName = "user"
    monitor.handle(exc)
    verify(logger).log(
      Level.SEVERE,
      "The 'qux' service " +
        Seq("user", "tweet").mkString(" on behalf of ") +
        " threw an exception",
      exc
    )
  }

  test("logs IOExceptions at Level.FINE") {
    val logger = mock[Logger]
    val ioEx = new IOException("hi")
    val monitor = new SourceTrackingMonitor(logger, "umm")
    monitor.handle(ioEx)
    verify(logger).log(mockitoEq(Level.FINE), any(), mockitoEq(ioEx))
  }

  test("logs Failure.rejected at Level.FINE") {
    val logger = mock[Logger]
    val monitor = new SourceTrackingMonitor(logger, "umm")
    val rejected = Failure.rejected("try again")
    monitor.handle(rejected)

    verify(logger).log(mockitoEq(Level.FINE), any(), mockitoEq(rejected))
    verify(logger, never()).log(mockitoEq(Level.WARNING), any(), mockitoEq(rejected))
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:51,代码来源:SourceTrackingMonitorTest.scala

示例2: RefcountedServiceTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.service

import com.twitter.util._
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito.{times, verify, when}
import org.mockito.{Matchers, Mockito}
import org.mockito.Matchers._
import com.twitter.finagle.Service

@RunWith(classOf[JUnitRunner])
class RefcountedServiceTest extends FunSuite with MockitoSugar {

  class PoolServiceWrapperHelper {
    val service = mock[Service[Any, Any]]
    when(service.close(any)) thenReturn Future.Done
    val promise = new Promise[Any]
    when(service(Matchers.any)) thenReturn promise
    val wrapper = Mockito.spy(new RefcountedService[Any, Any](service))
  }

  test("PoolServiceWrapper should call release() immediately when no requests have been made") {
    val h = new PoolServiceWrapperHelper
    import h._

    verify(service, times(0)).close(any)
    wrapper.close()
    verify(service).close(any)
  }

  test("PoolServiceWrapper should call release() after pending request finishes") {
    val h = new PoolServiceWrapperHelper
    import h._

    val f = wrapper(123)
    assert(!f.isDefined)
    verify(service)(123)

    wrapper.close()
    verify(service, times(0)).close(any)

    promise() = Return(123)
    verify(service).close(any)
    assert(f.isDefined)
    assert(Await.result(f) == 123)
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:50,代码来源:RefcountedServiceTest.scala

示例3: DatabaseReaderActivitySpec

//设置package包名称以及导入依赖的类
package test.yumi.pipeline.activities

import java.util.Properties

import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions
import org.mockito.Mockito.{verify, when}
import test.yumi.pipeline.MockSessionSpec
import yumi.YumiMap
import yumi.pipeline.activities.DatabaseReaderActivity

class DatabaseReaderActivitySpec extends MockSessionSpec {

  it should "load sql server table as spark view" in new MockSessionScope {

    // Arrange
    val url = "url"
    val table = "table_name"
    val as = "as"
    val driver = "com.mysql.Driver"
    val properties = Map("batchSize" -> "2000")
    val expectedProperties = new Properties()
    properties.foreach {
      case (key, value) =>
        expectedProperties.setProperty(key, value)
    }
    expectedProperties.put(JDBCOptions.JDBC_DRIVER_CLASS, driver)

    val parameters = createParameters()
      .add("url", url)
      .add("table", table)
      .add("driver", driver)
      .add("as", as)
      .add("properties", properties)
      .build()
    val sessionData = YumiMap()
    val dataFrame = mock[DataFrame]

    when(dataFrameReader.jdbc(any[String], any[String], any[Properties])).thenReturn(dataFrame)

    // Act
    val activity = new DatabaseReaderActivity(parameters)
    val resultSessionData = activity.invoke(sessionData)

    // Assert
    verify(sparkSession).read
    verify(dataFrameReader)
      .jdbc(url, table, expectedProperties)
    verify(dataFrame).createTempView(as)

    resultSessionData === sessionData
  }
} 
开发者ID:coderdiaries,项目名称:yumi,代码行数:54,代码来源:DatabaseReaderActivitySpec.scala

示例4: DatabaseWriterActivitySpec

//设置package包名称以及导入依赖的类
package test.yumi.pipeline.activities

import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions
import org.mockito.Mockito.{verify, when}
import test.yumi.pipeline.MockSessionSpec
import yumi.YumiMap
import yumi.pipeline.activities.DatabaseWriterActivity

class DatabaseWriterActivitySpec extends MockSessionSpec {

  it should "write to database table from spark view" in new MockSessionScope {

    // Arrange
    val url = "jdbc:postgresql://yumi.rds.amazonaws.com:5432/yumi_postgresql?user=yumi&password=somepassword"
    val table = "table_name"
    val as = "as"
    val mode = "append"
    val jdbcDriverClass = "org.postgresql.Driver"
    val properties = Map("batchSize" -> "2000")

    val completeOptions: Map[String, String] = properties +
      (JDBCOptions.JDBC_TABLE_NAME -> as) +
      (JDBCOptions.JDBC_DRIVER_CLASS -> jdbcDriverClass) +
      ("url" -> url)

    val parameters = createParameters()
      .add("url", url)
      .add("table", table)
      .add("as", as)
      .add("properties", properties)
      .add("mode", mode)
      .add("driver", jdbcDriverClass)
      .build()
    val sessionData = YumiMap()
    val dataFrame = mock[DataFrame]

    when(sparkSession.table(table)).thenReturn(dataFrame)

    // Act
    val activity = new DatabaseWriterActivity(parameters)
    val resultSessionData = activity.invoke(sessionData)

    // Assert
    verify(dataFrameWriter).write(dataFrame, "jdbc:postgresql", mode, url, completeOptions)

    resultSessionData === sessionData
  }
} 
开发者ID:coderdiaries,项目名称:yumi,代码行数:50,代码来源:DatabaseWriterActivitySpec.scala

示例5: StatsFactoryWrapperTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.factory

import com.twitter.finagle.{ClientConnection, ServiceFactory}
import com.twitter.finagle.stats.InMemoryStatsReceiver
import com.twitter.util.{Await, Future}
import org.junit.runner.RunWith
import org.mockito.Matchers.any
import org.mockito.Mockito.{verify, when}
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar

@RunWith(classOf[JUnitRunner])
class StatsFactoryWrapperTest extends FunSuite with MockitoSugar {
  val underlying = mock[ServiceFactory[Int, Int]]
  val rex = new RuntimeException
  val t = new Throwable(rex)

  test("report exceptions on Service creation failure") {
    val receiver = new InMemoryStatsReceiver
    val statsFac = new StatsFactoryWrapper(underlying, receiver)

    when(underlying(any[ClientConnection])) thenReturn Future.exception(t)

    intercept[Throwable] {
      Await.result(statsFac(ClientConnection.nil))
    }

    val expected = Map(
      List("failures", t.getClass.getName, rex.getClass.getName) -> 1)
    assert(receiver.counters == expected)
    verify(underlying)(ClientConnection.nil)
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:35,代码来源:StatsFactoryWrapperTest.scala

示例6: ProxyThreadFactoryTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.util

import java.util.concurrent.ThreadFactory
import org.junit.runner.RunWith
import org.mockito.Matchers.any
import org.mockito.Mockito.verify
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar

@RunWith(classOf[JUnitRunner])
class ProxyThreadFactoryTest extends FunSuite
  with MockitoSugar {

  private class RunnableCount extends Runnable {
    var runs = 0
    def run(): Unit =
      runs += 1
  }

  test("newProxiedRunnable") {
    var pre = 0
    var post = 0
    val mkProxy = ProxyThreadFactory.newProxiedRunnable(
      () => pre += 1,
      () => post += 1
    )

    val r = new RunnableCount()
    val newR = mkProxy(r)
    newR.run()
    assert(pre == 1)
    assert(post == 1)
    assert(r.runs == 1)
  }

  test("delegates to newRunnable and underlying ThreadFactory") {
    var created = 0
    val newR: Runnable => Runnable = { r =>
      created += 1
      r
    }

    val threadFactory = mock[ThreadFactory]
    val ptf = new ProxyThreadFactory(threadFactory, newR)

    val r = new RunnableCount()
    ptf.newThread(r)
    assert(r.runs == 0)
    assert(created == 1)
    verify(threadFactory).newThread(any())
  }

} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:55,代码来源:ProxyThreadFactoryTest.scala

示例7: OptionallyServableFilterTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.service

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar
import com.twitter.finagle.{NotServableException, Service}
import org.mockito.Mockito.{times, verify, when}
import org.mockito.Matchers._
import com.twitter.util.{Await, Future}

@RunWith(classOf[JUnitRunner])
class OptionallyServableFilterTest extends FunSuite with MockitoSugar {

  class OptionnallyServableFilterHelper {
    val underlying = mock[Service[String, String]]
    when(underlying.close(any)) thenReturn Future.Done

    val fn = mock[String => Future[Boolean]]
    val service = new OptionallyServableFilter(fn) andThen underlying
    val request = "request"
    val response = Future.value("response")
  }

  test("OptionallyServableFilter should passes through when fn returns true") {
    val h = new OptionnallyServableFilterHelper
    import h._

    when(fn.apply(request)) thenReturn Future.value(true)
    when(underlying(request)) thenReturn response
    assert(Await.result(service(request)) == Await.result(response))

    verify(fn).apply(request)
  }

  test("OptionallyServableFilter should throws NotServableException when fn returns false") {
    val h = new OptionnallyServableFilterHelper
    import h._

    when(fn.apply(request)) thenReturn Future.value(false)

    intercept[NotServableException] {
      Await.result(service(request))
    }
    verify(underlying, times(0)).apply(any[String])
    verify(fn).apply(request)
  }

} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:50,代码来源:OptionallyServableFilterTest.scala

示例8: CloseOnReleaseServiceTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.service

import org.junit.runner.RunWith
import org.mockito.Mockito.{verify, when, times}
import org.mockito.Matchers._
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar
import com.twitter.finagle.{WriteException, Service, Status}
import com.twitter.util.{Await, Promise, Future}

@RunWith(classOf[JUnitRunner])
class CloseOnReleaseServiceTest extends FunSuite with MockitoSugar {

  class Helper {
    val service = mock[Service[Any, Any]]
    when(service.close(any)) thenReturn Future.Done
    val promise = new Promise[Any]
    when(service(any)) thenReturn promise
    when(service.status) thenReturn Status.Open
    val wrapper = new CloseOnReleaseService(service)
  }

  test("only call release on the underlying service once") {
    val h = new Helper
    import h._
    
    assert(wrapper.isAvailable)
    verify(service, times(1)).status

    wrapper.close()
    verify(service, times(1)).close(any)
    wrapper.close()
    verify(service, times(1)).close(any)
    
    assert(!wrapper.isAvailable)
    verify(service, times(1)).status
  }

  test("throw a write exception if we attempt to use a released service") {
    val h = new Helper
    import h._

    wrapper.close()
    intercept[WriteException] {
      Await.result(wrapper(132))
    }
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:50,代码来源:CloseOnReleaseServiceTest.scala

示例9: MemorySpaceTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.mux.lease.exp

import com.twitter.conversions.storage.intToStorageUnitableWholeNumber
import com.twitter.util.StorageUnit
import org.mockito.Mockito.{when, verify}
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar

@RunWith(classOf[JUnitRunner])
class MemorySpaceTest extends FunSuite with MockitoSugar {
  test("MemorySpace#left should find the number of bytes left before we hit minDiscount") {
    val nfo = mock[JvmInfo]
    when(nfo.remaining()).thenReturn(10.megabytes)
    val range = StorageUnit.zero
    val minDiscount = 5.megabytes
    val maxDiscount = StorageUnit.zero
    val rSnooper = mock[RequestSnooper]
    val space = new MemorySpace(nfo, minDiscount, maxDiscount, rSnooper)
    assert(space.left == 5.megabytes)
    verify(nfo).remaining()
  }

  test("MemorySpace should be able to compute a discount correctly") {
    val nfo = mock[JvmInfo]
    val minDiscount = 5.megabytes
    val maxDiscount = 10.megabytes
    val rSnooper = mock[RequestSnooper]
    when(rSnooper.handleBytes()).thenReturn(2.megabytes)
    val rnd = mock[GenerationalRandom]
    when(rnd.apply()).thenReturn(107.megabytes.inBytes.toInt)
    val space =
      new MemorySpace(nfo, minDiscount, maxDiscount, rSnooper, NullLogsReceiver, rnd)
    assert(space.discount() == 7.megabytes)
    verify(rnd).apply()
    verify(rSnooper).handleBytes()
  }

  test("MemorySpace should be able to default to a max") {
    val nfo = mock[JvmInfo]
    val minDiscount = 5.megabytes
    val maxDiscount = 8.megabytes
    val rSnooper = mock[RequestSnooper]
    when(rSnooper.handleBytes()).thenReturn(9.megabytes)
    val rnd = mock[GenerationalRandom]
    val space =
      new MemorySpace(nfo, minDiscount, maxDiscount, rSnooper, NullLogsReceiver, rnd)
    assert(space.discount() == 8.megabytes)
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:52,代码来源:MemorySpaceTest.scala

示例10: GenerationalRandomTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.mux.lease.exp

import org.junit.runner.RunWith
import org.mockito.Mockito.{when, verify, times}
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar
import scala.util.Random

@RunWith(classOf[JUnitRunner])
class GenerationalRandomTest extends FunSuite with MockitoSugar {
  test("GenerationalRandom stays the same intragenerationally") {
    val nfo = mock[JvmInfo]
    when(nfo.generation()).thenReturn(0)
    val rnd = new Random(12334)
    val gen = new GenerationalRandom(nfo, rnd)
    verify(nfo).generation()

    val x = gen()
    verify(nfo, times(2)).generation()

    assert(gen() == x)
    verify(nfo, times(3)).generation()
  }

  test("GenerationalRandom changes intergenerationally") {
    val nfo = mock[JvmInfo]
    when(nfo.generation()).thenReturn(0)
    val rnd = new Random(12334)
    val gen = new GenerationalRandom(nfo, rnd)
    verify(nfo).generation()

    val x = gen()
    verify(nfo, times(2)).generation()

    assert(gen() == x)
    verify(nfo, times(3)).generation()

    when(nfo.generation()).thenReturn(1)

    assert(gen() != x)
    verify(nfo, times(5)).generation()
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:45,代码来源:GenerationalRandomTest.scala

示例11: DelayedReleaseServiceTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.http

import com.twitter.finagle.Service
import com.twitter.io.Reader
import com.twitter.util.Future
import org.junit.runner.RunWith
import org.mockito.Matchers.any
import org.mockito.Mockito.{never, stub, verify}
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar

@RunWith(classOf[JUnitRunner])
class DelayedReleaseServiceTest extends FunSuite with MockitoSugar {

  test("close closes underlying") {
    val service = mock[Service[Request, Response]]
    val proxy = new DelayedReleaseService(service)
    stub(service.close()).toReturn(Future.Done)

    proxy.close()
    verify(service).close()
  }

  test("close waits for response completion") {
    val request = Request()
    request.response.setChunked(true)

    val service = mock[Service[Request,Response]]
    stub(service.close()).toReturn(Future.Done)
    stub(service.apply(any[Request])).toReturn(Future.value(request.response))

    val proxy = new DelayedReleaseService(service)

    val f = proxy(request) flatMap { response =>
      proxy.close()
      verify(service, never).close()
      Reader.readAll(response.reader)
    }
    request.response.close() // EOF
    verify(service).close()
  }

  test("inner service failure") {
    val service = mock[Service[Request, Response]]
    val proxy = new DelayedReleaseService(service)
    stub(service.close()).toReturn(Future.Done)
    stub(service.apply(any[Request])).toReturn(Future.exception(new Exception))

    val request = Request()
    request.response.setChunked(true)
    proxy(request)
    proxy.close()
    verify(service).close()
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:57,代码来源:DelayedReleaseServiceTest.scala

示例12: StatsFilterTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.http.filter

import com.twitter.finagle.Service
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.stats.InMemoryStatsReceiver
import com.twitter.util.{Await, Duration, Future, Time}
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.mockito.Mockito.{spy, verify}

@RunWith(classOf[JUnitRunner])
class StatsFilterTest extends FunSuite {

  val service = new Service[Request, Response] {
    def apply(request: Request): Future[Response] = {
      val response = request.response
      response.statusCode = 404
      response.write("hello")
      Future.value(response)
    }
  }

  test("increment stats") {
    val receiver = spy(new InMemoryStatsReceiver)

    val filter = new StatsFilter(receiver) andThen service

    Time.withCurrentTimeFrozen { _ =>
      Await.result(filter(Request()), Duration.fromSeconds(5))
    }

    assert(receiver.counters(Seq("status", "404")) == 1)
    assert(receiver.counters(Seq("status", "4XX")) == 1)
    assert(receiver.stats(Seq("time", "404")) == Seq(0.0))
    assert(receiver.stats(Seq("time", "4XX")) == Seq(0.0))
    assert(receiver.stats(Seq("response_size")) == Seq(5.0))
  }

  test("status and time counters and stats are memoised") {
    val receiver = spy(new InMemoryStatsReceiver)

    val filter = new StatsFilter(receiver) andThen service

    Time.withCurrentTimeFrozen { _ =>
      Await.result(filter(Request()), Duration.fromSeconds(5))
      Await.result(filter(Request()), Duration.fromSeconds(5))
    }

    // Verify that the counters and stats were only created once
    verify(receiver).counter("status", "404")
    verify(receiver).counter("status", "4XX")
    verify(receiver).stat("time", "404")
    verify(receiver).stat("time", "4XX")
    verify(receiver).stat("response_size")
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:58,代码来源:StatsFilterTest.scala

示例13: ClientIdRequiredFilterTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift

import com.twitter.conversions.time._
import com.twitter.finagle.Service
import com.twitter.util.{Await, Future}
import org.junit.runner.RunWith
import org.mockito.Matchers
import org.mockito.Mockito.{times, verify, when}
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar

@RunWith(classOf[JUnitRunner])
class ClientIdRequiredFilterTest extends FunSuite with MockitoSugar {

  case class ClientIdRequiredFilterContext(underlying: Service[String,String]) {
    lazy val service = new ClientIdRequiredFilter andThen underlying
  }

  val request = "request"
  val response = Future.value("response")
  val clientId = ClientId("test")
  
  test("ClientIdRequiredFilter passes through when ClientId exists") {
    val c = ClientIdRequiredFilterContext(mock[Service[String,String]])
    import c._

    when(underlying(request)).thenReturn(response)
    clientId.asCurrent {
      val result = service(request)
      assert(Await.result(result, 10.seconds) == Await.result(response, 10.seconds))
      result
    }
  }

  test("ClientIdRequiredFilter throws NoClientIdSpecifiedException when ClientId does not exist") {
    val c = ClientIdRequiredFilterContext(mock[Service[String,String]])
    import c._

    ClientId.let(None) {
      intercept[NoClientIdSpecifiedException]{
        Await.result(service(request), 10.seconds)
      }
      verify(underlying, times(0)).apply(Matchers.anyString())
    }
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:48,代码来源:ClientIdRequiredFilterTest.scala

示例14: ChannelBufferTransportTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift.transport.netty3

import org.jboss.netty.buffer.ChannelBuffer
import org.junit.runner.RunWith
import org.mockito.Mockito.{verify, when}
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar

@RunWith(classOf[JUnitRunner])
class ChannelBufferTransportTest extends FunSuite with MockitoSugar {

  class ChannelContext{
    val buf = mock[ChannelBuffer]
    lazy val t = new ChannelBufferToTransport(buf)
  }
  val bb = "hello".getBytes

  test("ChannelBufferToTransport writes bytes to the underlying ChannelBuffer") {
    val c = new ChannelContext
    import c._

    t.write(bb, 0, 1)
    verify(buf).writeBytes(bb, 0, 1)

    t.write(bb, 1, 2)
    verify(buf).writeBytes(bb, 1, 2)

    t.write(bb, 0, 5)
    verify(buf).writeBytes(bb, 1, 2)
  }

  test("ChannelBufferToTransport reads bytes from the underlying ChannelBuffer") {
    val c = new ChannelContext
    import c._

    val nReadable = 5
    when(buf.readableBytes).thenReturn(nReadable)
    val b = new Array[Byte](nReadable)
    assert(t.read(b, 0, 10) == nReadable)
    assert(t.read(b, 0, 3) == 3)
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:44,代码来源:ChannelBufferTransportTest.scala

示例15: RubyMemCacheClientTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.memcached.unit

import com.twitter.finagle.memcached._
import org.junit.runner.RunWith
import org.mockito.Mockito.{times, verify}
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar

@RunWith(classOf[JUnitRunner])
class RubyMemCacheClientTest extends FunSuite with MockitoSugar {

  class Context {
    val client1 = mock[Client]
    val client2 = mock[Client]
    val client3 = mock[Client]
    val rubyMemCacheClient = new RubyMemCacheClient(Seq(client1, client2, client3))
  }

  test("pick the correct node") {
    val context = new Context
    import context._

    assert(rubyMemCacheClient.clientOf("apple")    == (client1))
    assert(rubyMemCacheClient.clientOf("banana")   == (client2))
    assert(rubyMemCacheClient.clientOf("cow")      == (client1))
    assert(rubyMemCacheClient.clientOf("dog")      == (client1))
    assert(rubyMemCacheClient.clientOf("elephant") == (client3))
  }

  test("release") {
    val context = new Context
    import context._

    rubyMemCacheClient.release()
    verify(client1, times(1)).release()
    verify(client2, times(1)).release()
    verify(client3, times(1)).release()
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:41,代码来源:RubyMemCacheClientTest.scala


注:本文中的org.mockito.Mockito.verify类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。