小编jil*_*len的帖子

用于链接呼叫的模拟或存根

protected int parseExpire(CacheContext ctx) throws AttributeDefineException {
    Method targetMethod = ctx.getTargetMethod();
    CacheEnable cacheEnable = targetMethod.getAnnotation(CacheEnable.class);
    ExpireExpr cacheExpire = targetMethod.getAnnotation(ExpireExpr.class);
    // check for duplicate setting
    if (cacheEnable.expire() != CacheAttribute.DO_NOT_EXPIRE && cacheExpire != null) {
        throw new AttributeDefineException("expire are defined both in @CacheEnable and @ExpireExpr");
    }
    // expire time defined in @CacheEnable or @ExpireExpr
    return cacheEnable.expire() != CacheAttribute.DO_NOT_EXPIRE ? cacheEnable.expire() : parseExpireExpr(cacheExpire, ctx.getArgument());
}
Run Code Online (Sandbox Code Playgroud)

这是测试的方法,

Method targetMethod = ctx.getTargetMethod();
CacheEnable cacheEnable = targetMethod.getAnnotation(CacheEnable.class);
Run Code Online (Sandbox Code Playgroud)

我必须模拟三个CacheContext,Method和CacheEnable.有什么想法让测试用例更简单吗?

java unit-testing mocking mockito

63
推荐指数
3
解决办法
5万
查看次数

如何在编辑emacs lisp脚本时禁用flycheck警告?

我现在正在使用emacs前奏,并发现一切都很好.但

编辑el文件时会显示很多flycheck警告

和语法着色被覆盖

警告如"第一行应该是表格包---摘要"

如何关闭这些警告?

emacs flycheck

18
推荐指数
2
解决办法
4830
查看次数

在circe中将所有键从`下划线'转换为`camel case`的json对象

起源

{
  "first_name" : "foo",
  "last_name" : "bar",
  "parent" : {
    "first_name" : "baz",
    "last_name" : "bazz",
  }
}
Run Code Online (Sandbox Code Playgroud)

预期

 {
      "firstName" : "foo",
      "lastName" : "bar",
      "parent" : {
        "firstName" : "baz",
        "lastName" : "bazz",
      }
    }
Run Code Online (Sandbox Code Playgroud)

如何转换json对象的所有键?

json scala circe

12
推荐指数
1
解决办法
3353
查看次数

scala 2.10.2调用泛型类型的"宏方法"不起作用

我定义了以下宏来将case字段转换为map

   import scala.language.experimental.macros
    import scala.reflect.macros.Context

    def asMap_impl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]) = {
      import c.universe._

      val mapApply = Select(reify(Map).tree, newTermName("apply"))

      val pairs = weakTypeOf[T].declarations.collect {
        case m: MethodSymbol if m.isCaseAccessor =>
          val name = c.literal(m.name.decoded)
          val value = c.Expr(Select(t.tree, m.name))
          reify(name.splice -> value.splice).tree
      }

      c.Expr[Map[String, Any]](Apply(mapApply, pairs.toList))
    }
Run Code Online (Sandbox Code Playgroud)

并且方法实现

def asMap[T](t: T) = macro asMap_impl[T]
Run Code Online (Sandbox Code Playgroud)

然后我定义一个案例类来测试它

case class User(name : String)
Run Code Online (Sandbox Code Playgroud)

它工作正常(使用scala repl):

 scala> asMap(User("foo")) res0:
 scala.collection.immutable.Map[String,String] = Map(name -> foo)
Run Code Online (Sandbox Code Playgroud)

但是当我用另一个泛型方法包装此方法时

def printlnMap[T](t: T) = println(asMap(t))
Run Code Online (Sandbox Code Playgroud)

此方法始终打印空地图:

scala> printlnMap(User("foo"))
Map() …
Run Code Online (Sandbox Code Playgroud)

generics scala scala-macros

10
推荐指数
1
解决办法
1347
查看次数

为什么tomcat默认的线程池大小如此之大?

我注意到默认的tomcat 7线程池大小似乎是200.

但正常的CPU似乎有16个核心.

因此只能执行16个线程并行执行

为什么tomcat使用这么多线程.

java multithreading tomcat

9
推荐指数
2
解决办法
5448
查看次数

光滑的动态更新字段

我从Play控制器那里得到一张表格

class CustomerTable(tag: Tag) extends Table[Customer]("customer", tag) {
   def id = column[Long]("id")
   ...
   def * = ...
}

case class Customer(
   id: Long,
   remarkName: String
   ...
)

case class CustomerUpdateForm(
  id: Long,
  remarkName: Option[String],
  realName: Option[String],
  birth: Option[Date],
  address: Option[String],
  phone: Option[String],
  qq: Option[String],
  email: Option[String])
Run Code Online (Sandbox Code Playgroud)

我想用nonEmpty表格的字段更新数据库,这是我的方式

def updateField(form: CustomerUpdateForm) = {
  def updateField0[T](
    field: CustomerTable => Column[T],
    value: T) = {
     customerTable
      .filer(_.id, form.id)
      .map(c => field(c) -> c.gmtModified)
      .update(value -> new Date)
  }
  var …
Run Code Online (Sandbox Code Playgroud)

scala playframework slick

9
推荐指数
0
解决办法
917
查看次数

scala 3 宏如何实现通用特征

我想实现proxy一些特征A(例如委托方法调用到一些 rpc 调用),像这样

   def clientProxy[A](using Type[A], Quotes): Expr[A] = {
    import quotes.reflect._
    val defTrees: List[Tree] = TypeRepr.of[A].typeSymbol.memberFields.collect {
      case mf if mf.isDefDef =>
        ???
    }

    val exprs = Expr.ofList(defTrees.map(_.asExpr))
    '{
      new A {
        $exprs
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

但是编译器抱怨

A is not a class type

Run Code Online (Sandbox Code Playgroud)

scala dotty scala-3

8
推荐指数
1
解决办法
165
查看次数

如何将sbteclipse插件添加到SBT 0.10.x.

我想查看akka的源代码,它似乎使用0.7.x版本的sbt.
我将项目配置转换为0.10.x版本.当我在libraray-dependencies中添加sbteclipse并运行eclipse create-src来生成eclipse项目时,它告诉eclipse不是命令.这是我的Build.scala.当我使用库依赖项列出库时,sbteclipse_2.8.1.jar实际上是存在的

我之前犯了一个愚蠢的错误.插件定义应在project/plugins/build.sbt文件中声明,而不是作为project/build.sbt中的库依赖项

import sbt._
import Keys._

object Settings {
  import Dependencies._
  import Resolvers._

  val buildScalaVersion = "2.9.0-1"

  val buildSettings = Defaults.defaultSettings ++ Seq(
    scalaVersion := buildScalaVersion,
    libraryDependencies := Depns,
    resolvers := Repos)
}
object Resolvers {
  /**
   * repos definition
   */
  lazy val Repos = Seq(
    AkkaRepo,
    CodehausRepo,
    GuiceyFruitRepo,
    JBossRepo,
    JavaNetRepo,
    SonatypeSnapshotRepo,
    GlassfishRepo,
    ScalaToolsRelRepo,
    ScalaToolsSnapshotRepo,
    TypeSafeRepo)
  lazy val AkkaRepo = "Akka Repository" at "http://akka.io/repository"
  lazy val CodehausRepo = "Codehaus Repo" at "http://repository.codehaus.org"
  lazy val GuiceyFruitRepo = "GuiceyFruit Repo" …
Run Code Online (Sandbox Code Playgroud)

eclipse scala sbt akka

7
推荐指数
1
解决办法
3778
查看次数

java.lang.String无法强制转换为scala.Serializable

我正在使用scala.Serializable,但是当我调用String.asInstanceOf [Serializable]时,抛出了强制转换异常.这是我的代码,非常简单.

arguments.map(_.asInstanceOf[Serializable])
Run Code Online (Sandbox Code Playgroud)

是的,参数是字符串数组当然
我用scala-ide运行应用程序eclipse与eclipse 3.7和scala 2.9.0-1

查看此文档scala doc

问题现在是"scala.Serializable的典型用例是什么"

serialization scala

7
推荐指数
2
解决办法
4629
查看次数

specs2 - 无法创建实例

testOnly play.api.weibo.StatusesShowBatchSpec
[error] Could not create an instance of play.api.weibo.StatusesShowBatchSpec
[error]   caused by java.lang.Exception: Could not instantiate class play.api.weibo.StatusesShowBatchSpec: null
[error]   org.specs2.reflect.Classes$class.tryToCreateObjectEither(Classes.scala:93)
[error]   org.specs2.reflect.Classes$.tryToCreateObjectEither(Classes.scala:211)
[error]   org.specs2.specification.SpecificationStructure$$anonfun$createSpecificationEither$2.apply(BaseSpecification.scala:119)
[error]   org.specs2.specification.SpecificationStructure$$anonfun$createSpecificationEither$2.apply(BaseSpecification.scala:119)
...
Run Code Online (Sandbox Code Playgroud)

规范

package play.api.weibo

import org.junit.runner.RunWith
import org.specs2.runner.JUnitRunner

class StatusesShowBatchSpec extends ApiSpec {

  "'statuses show batch' api" should {
    "read statuses" in {
      val api = StatusesShowBatch(
        accessToken = testAdvancedToken,
        ids = "3677163356078857")
      val res = awaitApi(api)
      res.statuses must have size (1)
    }
Run Code Online (Sandbox Code Playgroud)

}}

请在此处查看完整代码https://github.com/jilen/play-weibo/tree/spec2_error

完整的堆栈跟踪 https://gist.github.com/jilen/9050548

scala specs2

7
推荐指数
1
解决办法
3608
查看次数