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

Scala never类代码示例

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

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala JsResult类代码示例发布时间:2022-05-23
下一篇:
Scala EventBus类代码示例发布时间: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