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


Scala any类代码示例

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


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

示例1: AddressDetailsControllerTest

//设置package包名称以及导入依赖的类
package controllers

import address.AddressReputationService
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, Materializer}
import model.AddressDetails
import org.mockito.Matchers.any
import org.mockito.Mockito._
import org.scalatest.mock.MockitoSugar
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.libs.json.Reads
import play.api.mvc.Security
import play.api.test.FakeRequest
import play.api.test.Helpers._
import uk.gov.hmrc.http.cache.client.SessionCache
import uk.gov.hmrc.play.http.HeaderCarrier

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future


class AddressDetailsControllerTest extends PlaySpec with MockitoSugar with OneAppPerSuite {

  trait action {
    val cache = mock[SessionCache]
    val ars = mock[AddressReputationService]
    val controller = new AddressDetailsController(ars, cache)
    val req = FakeRequest().withSession(Security.username -> "user")
    val buildingNumber = "25"
    val buildingName = "Starship Enterprise"
    val street = "Waterloo Road"
    val town = "Darlington"
    val postcode = "DL3 5BD"
    val ad = AddressDetails(Some(buildingNumber), Some(buildingName), Some(street), Some(town), postcode)
    implicit val system = ActorSystem("Test")
    implicit def mat: Materializer = ActorMaterializer()
  }

  "get" should {

    "return completed form" in new action {
      // test that when the cache contains address details, we display filled-out form
      when(cache.fetchAndGetEntry[AddressDetails](any[String])(any[HeaderCarrier], any[Reads[AddressDetails]])).thenReturn(Future(Some(ad)))
      val res = call(controller.get(), req)
      status(res) must be(303)
    }

  }

} 
开发者ID:hmrc,项目名称:bank-account-reputation-frontend,代码行数:51,代码来源:AddressDetailsControllerTest.scala

示例2: MyDIControllerTest

//设置package包名称以及导入依赖的类
package controllers.api.standard

import java.util.concurrent.TimeUnit

import akka.actor.ActorSystem
import akka.util.Timeout
import com.github.sample.services.MyService
import org.mockito.Matchers.any
import org.mockito.Mockito._
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FunSpec, MustMatchers}
import play.api.mvc.Result
import play.api.test.FakeRequest
import play.api.test.Helpers

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class MyDIControllerTest extends FunSpec with MustMatchers with MockitoSugar {

  describe("MyDIControllerTest") {

    implicit val timeout = Timeout(5000, TimeUnit.MILLISECONDS)

    it("controllerTest"){
      val mockService = mock[MyService]
      when(mockService.exec(any[String])) thenReturn Future{"str"}

      val actorSystem = ActorSystem.apply()
      val controller = new MyDIController(mockService, actorSystem)

      val result: Future[Result] = controller.message().apply(FakeRequest())
      Helpers.contentAsString(result) mustBe "str"
      Helpers.status(result) mustBe 200
    }
  }

} 
开发者ID:tm-sukehiro,项目名称:play2-sandbox,代码行数:39,代码来源:MyDIControllerTest.scala

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

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

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

示例6: client

//设置package包名称以及导入依赖的类
package com.amarjanica.discourse.unit

import com.amarjanica.discourse.util.SerializableAsJson
import com.amarjanica.discourse.{BaseHttpClient, DiscourseClient}
import com.squareup.okhttp.Request
import org.mockito.Matchers.any
import org.mockito.Mockito._

trait BaseSpec{

  def client(resource: String = "") = {
    val mockBaseHttpClient = mock(classOf[BaseHttpClient])
    val discourseClient = new DiscourseClient("http://localhost:3000", None, mockBaseHttpClient)

    when(mockBaseHttpClient.get(any(classOf[String]), any(classOf[Request.Builder])))
      .thenReturn(
        scala.io.Source.fromInputStream(this.getClass.getResourceAsStream(resource)).mkString
      )
    when(mockBaseHttpClient.post(any(classOf[String]), any(classOf[Request.Builder])))
      .thenReturn(
        scala.io.Source.fromInputStream(this.getClass.getResourceAsStream(resource)).mkString
      )
    when(mockBaseHttpClient.put(any(classOf[String]), any(classOf[SerializableAsJson]), any(classOf[Request.Builder])))
      .thenReturn(
        scala.io.Source.fromInputStream(this.getClass.getResourceAsStream(resource)).mkString
      )
    when(mockBaseHttpClient.delete(any(classOf[String]), any(classOf[Request.Builder])))
      .thenReturn(true)

    discourseClient
  }
} 
开发者ID:amarjanica,项目名称:discourse-scala-client,代码行数:33,代码来源:BaseSpec.scala

示例7: AESIndexOutputTest

//设置package包名称以及导入依赖的类
package org.elasticsearch.index.store

import java.io.File

import org.apache.lucene.util.AESWriter
import org.mockito.Matchers.{any, anyInt}
import org.mockito.Mockito.{times, verify}
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{FlatSpec, Matchers}

class AESIndexOutputTest extends FlatSpec with Matchers with MockitoSugar {

  behavior of "#write"
  it should "write data into writer" in {
    val dir = mock[File]
    val writer = mock[AESWriter]

    var counter = 0
    def closeHandler(name: String) = { counter += 1 }
    def createAESWriter(dir: File, name: String, pageSize: Int) = { writer }

    val output = new AESIndexOutput(dir, "test", 100, closeHandler, createAESWriter)

    val bytes = (1 to 10000).map(_.toByte).toArray[Byte] // We need more data than 8192 byte write buffer
    output.writeBytes(bytes, 0, 9000)
    verify(writer, times(2)).write(any[Array[Byte]], anyInt, anyInt)
  }

  behavior of "#flush"
  it should "flush the writer" in {
    val dir = mock[File]
    val writer = mock[AESWriter]

    var counter = 0
    def closeHandler(name: String) = { counter += 1 }
    def createAESWriter(dir: File, name: String, pageSize: Int) = { writer }

    val output = new AESIndexOutput(dir, "test", 100, closeHandler, createAESWriter)

    output.flush()
    verify(writer, times(1)).flush()
  }

  behavior of "#close"
  it should "call the handler" in {
    val dir = mock[File]
    val writer = mock[AESWriter]

    var counter = 0
    def closeHandler(name: String) = { counter += 1 }
    def createAESWriter(dir: File, name: String, pageSize: Int) = { writer }

    val output = new AESIndexOutput(dir, "test", 100, closeHandler, createAESWriter)

    counter shouldBe 0
    output.close()
    counter shouldBe 1
  }

} 
开发者ID:Workday,项目名称:elasticrypt,代码行数:61,代码来源:AESIndexOutputTest.scala


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