• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala verify类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: PHPMemCacheClientTest

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

import com.twitter.finagle.memcached._
import com.twitter.hashing.KeyHasher
import org.junit.runner.RunWith
import org.mockito.Mockito.verify
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar

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

  class Context {
    val client1 = mock[Client]
    val client2 = mock[Client]
    val client3 = mock[Client]
    val phpMemCacheClient = new PHPMemCacheClient(Array(client1, client2, client3), KeyHasher.FNV1_32)
  }

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

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

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

    phpMemCacheClient.release()
    verify(client1).release()
    verify(client2).release()
    verify(client3).release()
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:42,代码来源:PHPMemCacheClientTest.scala


示例17: SignalRefreshedTemplateSourceSpec

//设置package包名称以及导入依赖的类
package de.frosner.broccoli.templates

import de.frosner.broccoli.signal.SignalManager
import org.mockito.Mockito.{times, verify}
import org.mockito.{ArgumentCaptor, Matchers}
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification
import sun.misc.{Signal, SignalHandler}

class SignalRefreshedTemplateSourceSpec extends Specification with Mockito {
  "Receiving a SIGUSR2 signal" should {
    "update the cache" in {
      val signalManager = mock[SignalManager]
      val testTemplateSource = mock[CachedTemplateSource]
      val signalRefreshedTemplateSource = new SignalRefreshedTemplateSource(testTemplateSource, signalManager)
      val handler = ArgumentCaptor.forClass(classOf[SignalHandler])
      there was one(signalManager).register(Matchers.eq(new Signal("USR2")), handler.capture())

      there was no(testTemplateSource).refresh()
      there was no(testTemplateSource).loadTemplates()
      signalRefreshedTemplateSource.loadTemplates()

      there was no(testTemplateSource).refresh()
      there was one(testTemplateSource).loadTemplates()
      verify(testTemplateSource, times(1)).loadTemplates()

      handler.getValue.handle(new Signal("USR2"))
      there was one(testTemplateSource).refresh()
      there was one(testTemplateSource).loadTemplates()
    }
  }
} 
开发者ID:FRosner,项目名称:cluster-broccoli,代码行数:33,代码来源:SignalRefreshedTemplateSourceSpec.scala


示例18: SynchronizerSpec

//设置package包名称以及导入依赖的类
package fr.univ_lille.cristal.emeraude.chasqui.tests

import fr.univ_lille.cristal.emeraude.chasqui.core.SynchronizerStrategy
import org.mockito.ArgumentMatchers
import org.mockito.Mockito.verify


class SynchronizerSpec extends ChasquiBaseSpec {

  "A node that processed all messages in time t" should "inform its synchronizer strategy to wait" in {
    val nodeA = newNode

    val synchronizerStrategy = mock[SynchronizerStrategy]
    nodeA.setSynchronizerStrategy(synchronizerStrategy)

    //This will process all message in time 1 and inform it finished to its synchronizer strategy
    nodeA.advanceSimulationTime()

    //We sleep here to wait the actor system to react
    //This is not the best way to test, because it may not scale in the future
    // but it's a practical and simple one to start with
    Thread.sleep(500)

    verify(synchronizerStrategy).notifyFinishedTime(
      org.mockito.ArgumentMatchers.eq(nodeA.actor),
      ArgumentMatchers.any(),
      org.mockito.ArgumentMatchers.eq(1L),
      org.mockito.ArgumentMatchers.eq(0),
      org.mockito.ArgumentMatchers.eq(0))

  }
} 
开发者ID:guillep,项目名称:chasqui,代码行数:33,代码来源:SynchronizerSpec.scala


示例19: StackDescribeTest

//设置package包名称以及导入依赖的类
package uk.co.telegraph.plugin.pipeline.tasks

import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.{eq => mEq}
import org.mockito.Mockito
import org.mockito.Mockito.{times, verify}
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfter, FunSpec, Matchers}
import sbt.Logger
import uk.co.telegraph.cloud._
import uk.co.telegraph.plugin.pipeline.StackAuth
import StackDescribeTest._

@RunWith(classOf[JUnitRunner])
class StackDescribeTest extends FunSpec with BeforeAndAfter with Matchers{

  val SampleInvalidStackName = "invalid-test-stack"

  before{
    Mockito.reset(MockInterpreter)
  }

  describe("Given the 'StackDescribe' operation, "){
    it("I should be able to get a stack name if the stack exists"){
      Mockito.when(MockInterpreter.apply( mEq(Describe(SampleStackName)) ))
        .thenReturn(Some(SampleStackInfo))

      val res = StackDescribeMocked(
        SampleStackName,
        SampleStackRegion,
        SampleStackAuth
      )(SampleEnvironment, SampleLogger)

      res shouldBe Some(SampleStackInfo)

      verify(MockInterpreter, times(1)).apply( mEq(Describe(SampleStackName)) )
    }

    it("I should get nothing with an invalid stack"){
      Mockito.when(MockInterpreter.apply( mEq(Describe(SampleInvalidStackName)) ))
        .thenReturn(None)

      val res = StackDescribeMocked(
        SampleInvalidStackName,
        SampleStackRegion,
        SampleStackAuth
      )(SampleEnvironment, SampleLogger)

      res shouldBe None

      verify(MockInterpreter, times(1)).apply( mEq(Describe(SampleInvalidStackName)) )
    }
  }
}

object StackDescribeTest {
  object StackDescribeMocked extends StackDescribe{
    override def interpreter(region: StackRegion, auth: StackAuth)(implicit logger: Logger) = MockInterpreter
  }
} 
开发者ID:telegraph,项目名称:sbt-pipeline-plugin,代码行数:61,代码来源:StackDescribeTest.scala


示例20: EvictingCacheTest

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

import com.twitter.util.{Promise, Future}
import java.util.concurrent.ConcurrentHashMap
import org.junit.runner.RunWith
import org.mockito.Mockito.{verify, never}
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar

@RunWith(classOf[JUnitRunner])
class EvictingCacheTest extends FunSuite with MockitoSugar {
  test("EvictingCache should evict on failed futures for set") {
    val cache = mock[FutureCache[String, String]]
    val fCache = new EvictingCache(cache)
    val p = Promise[String]
    fCache.set("key", p)
    verify(cache).set("key", p)
    p.setException(new Exception)
    verify(cache).evict("key", p)
  }

  test("EvictingCache should keep satisfied futures for set") {
    val cache = mock[FutureCache[String, String]]
    val fCache = new EvictingCache(cache)
    val p = Promise[String]
    fCache.set("key", p)
    verify(cache).set("key", p)
    p.setValue("value")
    verify(cache, never).evict("key", p)
  }

  test("EvictingCache should evict on failed futures for getOrElseUpdate") {
    val map = new ConcurrentHashMap[String, Future[String]]()
    val cache = new ConcurrentMapCache(map)
    val fCache = new EvictingCache(cache)
    val p = Promise[String]
    assert(fCache.getOrElseUpdate("key")(p).poll == p.poll)
    p.setException(new Exception)
    assert(fCache.get("key") == None)
  }

  test("EvictingCache should keep satisfied futures for getOrElseUpdate") {
    val map = new ConcurrentHashMap[String, Future[String]]()
    val cache = new ConcurrentMapCache(map)
    val fCache = new EvictingCache(cache)
    val p = Promise[String]
    assert(fCache.getOrElseUpdate("key")(p).poll == p.poll)
    p.setValue("value")
    assert(fCache.get("key").map(_.poll) == Some(p.poll))
  }
} 
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:53,代码来源:EvictingCacheTest.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala NumberFormat类代码示例发布时间:2022-05-23
下一篇:
Scala MLUtils类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap