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


Scala never类代码示例

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


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

示例3: 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

示例4: RosterTest

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

import java.util.logging.Logger
import org.mockito.Mockito.{never, verify}
import org.mockito.Matchers.anyObject
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.FunSuite
import org.scalatest.mock.MockitoSugar

@RunWith(classOf[JUnitRunner])
class RosterTest extends FunSuite with MockitoSugar {
  def withRoster(fn: (Roster, Logger) => Unit): Unit = {
    val simple = new SimpleRegistry
    simple.put(Seq("foo", "bar"), "fantastic")
    val log = mock[Logger]
    GlobalRegistry.withRegistry(simple) {
      val roster = new Roster(Seq("foo"), Set("bar", "baz"), log)
      fn(roster, log)
    }
  }

  test("Roster#update updates when the key is good") {
    withRoster { (roster, log) =>
      assert(roster("bar") = "qux")
      val expected = Set(
        Entry(Seq("foo", "bar"), "qux")
      )
      assert(GlobalRegistry.get.toSet == expected)
      verify(log, never).warning(anyObject[String])
    }
  }

  test("Roster#update fails to update when the key is bad") {
    withRoster { (roster, log) =>
      assert(!(roster("unseen") = "qux"))
      val expected = Set(
        Entry(Seq("foo", "bar"), "fantastic")
      )
      assert(GlobalRegistry.get.toSet == expected)
      verify(log, never).warning(anyObject[String])
    }
  }

  test("Roster#update logs noisily when the key is good but the registry is inconsistent") {
    val expected =
      "expected there to be a value at key \"(foo,baz)\" in registry but it was empty."
    withRoster { (roster, log) =>
      assert(!(roster("baz") = "qux"))
      val expectedSet = Set(
        Entry(Seq("foo", "bar"), "fantastic"),
        Entry(Seq("foo", "baz"), "qux")
      )
      assert(GlobalRegistry.get.toSet == expectedSet)
      verify(log).warning(expected)
    }
  }
} 
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:59,代码来源:RosterTest.scala


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