scalac:错误:要求失败:包存根(scalac: Error: requirement failed: package stubbing)
我正在使用scala 2.12。 这是我的build.sbt文件
libraryDependencies ++= Seq( "net.codingwell" %% "scala-guice" % "4.1.0", "org.scalatest" %% "scalatest" % "3.0.3" % "test", "org.scalamock" %% "scalamock-scalatest-support" % "3.5.0" % "test" )
我正在尝试为Guice编写一个测试模块,它也使用Mocking
我试过了
class TestModule extends ScalaModule with MockitoSugar{ val x = mock[TestPartialMock] override def configure(): Unit = { bind[Test1] bind[Test2] } }
我收到了错误
Error:scalac: Error: requirement failed: package stubbing java.lang.IllegalArgumentException: requirement failed: package stubbing at scala.reflect.internal.Types$ModuleTypeRef.<init>(Types.scala:1879) at scala.reflect.internal.Types$PackageTypeRef.<init>(Types.scala:1897) at scala.reflect.internal.Types$TypeRef$.apply(Types.scala:2401) at scala.reflect.internal.Types.typeRef(Types.scala:3553) at scala.reflect.internal.Types.typeRef$(Types.scala:3536) at scala.reflect.internal.SymbolTable.typeRef(SymbolTable.scala:16) at s
我也试过了
class TestModule extends AbstractModule with ScalaModule with MockitoSugar { override def configure() = { } }
但现在我得到了错误
Error:(14, 17) Symbol 'type <none>.stubbing.Answer' is missing from the classpath. This symbol is required by 'value org.scalatest.mockito.MockitoSugar.defaultAnswer'. Make sure that type Answer is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of <none>.stubbing. override def configure() = {
然后我试了一下
class TestModule extends AbstractModule with ScalaModule with MockFactory with MockitoSugar { override def configure() = { } }
但是我得到了这个错误
Error:(14, 17) Symbol 'type <none>.mockito.MockSettings' is missing from the classpath. This symbol is required by 'value org.scalatest.mockito.MockitoSugar.mockSettings'. Make sure that type MockSettings is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of <none>.mockito. override def configure() = {
在我看来,在同一个类中使用Guice AbstractFactory和MockitoSugar是不可能的。
I am using scala 2.12. This is my build.sbt file
libraryDependencies ++= Seq( "net.codingwell" %% "scala-guice" % "4.1.0", "org.scalatest" %% "scalatest" % "3.0.3" % "test", "org.scalamock" %% "scalamock-scalatest-support" % "3.5.0" % "test" )
I am trying to write a Test Module for Guice which also uses Mocking
I Tried
class TestModule extends ScalaModule with MockitoSugar{ val x = mock[TestPartialMock] override def configure(): Unit = { bind[Test1] bind[Test2] } }
I got the error
Error:scalac: Error: requirement failed: package stubbing java.lang.IllegalArgumentException: requirement failed: package stubbing at scala.reflect.internal.Types$ModuleTypeRef.<init>(Types.scala:1879) at scala.reflect.internal.Types$PackageTypeRef.<init>(Types.scala:1897) at scala.reflect.internal.Types$TypeRef$.apply(Types.scala:2401) at scala.reflect.internal.Types.typeRef(Types.scala:3553) at scala.reflect.internal.Types.typeRef$(Types.scala:3536) at scala.reflect.internal.SymbolTable.typeRef(SymbolTable.scala:16) at s
I also tried
class TestModule extends AbstractModule with ScalaModule with MockitoSugar { override def configure() = { } }
but now I get error
Error:(14, 17) Symbol 'type <none>.stubbing.Answer' is missing from the classpath. This symbol is required by 'value org.scalatest.mockito.MockitoSugar.defaultAnswer'. Make sure that type Answer is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of <none>.stubbing. override def configure() = {
Then I tried
class TestModule extends AbstractModule with ScalaModule with MockFactory with MockitoSugar { override def configure() = { } }
But I get this error
Error:(14, 17) Symbol 'type <none>.mockito.MockSettings' is missing from the classpath. This symbol is required by 'value org.scalatest.mockito.MockitoSugar.mockSettings'. Make sure that type MockSettings is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of <none>.mockito. override def configure() = {
It seems to me that its impossible to use the Guice AbstractFactory and the MockitoSugar in the same class.
原文:https://stackoverflow.com/questions/43696394
最满意答案
如果
?:
是关联的,那么声明finalgrade = (grade > 90) ? "high pass" : (grade < 60) ? "fail" : "pass";
将被视为
finalgrade = ((grade > 90) ? "high pass" : (grade < 60)) ? "fail" : "pass";
其中(在这种情况下)不会编译,因为
"high pass"
和(grade < 60)
具有不同的类型。由于它实际上是右关联的,因此该语句被视为
finalgrade = (grade > 90) ? "high pass" : ((grade < 60) ? "fail" : "pass");
If
?:
was left associative, the statementfinalgrade = (grade > 90) ? "high pass" : (grade < 60) ? "fail" : "pass";
would be treated as
finalgrade = ((grade > 90) ? "high pass" : (grade < 60)) ? "fail" : "pass";
which (in this case) would not compile, since
"high pass"
and(grade < 60)
have different types.Since it is actually right associative, the statement is treated as
finalgrade = (grade > 90) ? "high pass" : ((grade < 60) ? "fail" : "pass");
相关问答
更多-
这与关联性无关(这在表达式中发挥作用,如a == b == c )。 你问的是操作员操作数的评估顺序。 有一些明确列出的异常,这在C ++中是故意未指定的 。 这意味着不能保证a或b是否会首先在a == b进行评估。 例外(保证评估顺序)是: 函数调用的所有参数在函数调用之前进行评估(但是以未指定的顺序)。 内置运算符||的左侧 并且首先评估&& (如果需要,右侧仅进行评估)。 内置运算符的左侧在右侧之前进行评估。 运算符?:的条件在结果之前被评估,并且只有一个结果被评估。 注意&& , ||的特殊属性 , ...
-
a[i++] = a[i++]; 因为它是未定义的行为。 好阅读: 序列点 未定义的行为和序列点 a[i++] = a[i++]; Because it is Undefined Behavior. Good Read: Sequence Points Undefined Behavior and Sequence Points
-
如果?:是关联的,那么声明 finalgrade = (grade > 90) ? "high pass" : (grade < 60) ? "fail" : "pass"; 将被视为 finalgrade = ((grade > 90) ? "high pass" : (grade < 60)) ? "fail" : "pass"; 其中(在这种情况下)不会编译,因为"high pass"和(grade < 60)具有不同的类型。 由于它实际上是右关联的,因此该语句被视为 finalgrade = ( ...
-
你在结合性和秩序或评估之间感到困惑。 参数的评估顺序在C ++中是未指定的。 正如你所提到的那样, operator +关联性从左到右。 要理解这一点,请使用operator -尝试类似的代码片段operator - 从订单或评估 (重点我的) 除了下面指出的地方,在C ++中没有从左到右或从右到左的评估概念。 这不应与运算符的从左到右和从右到左的关联性相混淆 :表达式f1()+ f2()+ f3()被解析为(f1()+ f2())+ f3( )由于operator +的从左到右的关联性,但可以在运行时首先 ...
-
保证?:的评估顺序:首先计算第一个操作数,然后根据第一个操作数是否为真来计算第二个或第三个操作数。 您主要对运算符优先级/关联性与评估顺序之间的关系感到困惑。 他们扮演不同的角色。 前者决定运算符的分组方式,而后者决定首先计算哪个子表达式。 考虑表达式a * b + c * d ,优先规则意味着它等同于(a * b) + (c * d) 。 但是保证编译器会在c * d之前评估a * b吗? 答案是否定的,在本例中,运算符+不保证评估顺序。 条件运算符?:是具有指定评估顺序的少数运算符之一。 (其余的是&& ...
-
从c ++标准第5条, 重载运算符遵守第5章中规定的语法规则。 第5节规定了运算符的优先级和关联性。 From c++ standard clause 5, Overloaded operators obey the rules for syntax specified in Clause 5. Where clause 5 specifies operator precedence and associativity.
-
这可以做到......但需要付出一些努力。 基本思想是使用右移运算符来创建和更新推迟实际计算的新类型对象。 例如,假设您的变量如上:A,B,C,D和E都是Actual类型的对象。 我们将介绍一个新类Deferred,它是由一个实例的实例上的rshift操作产生的。 Deferred还实现了rshift运算符,它更新对象并返回自身。 (顺便说一下,对于这个答案的其余部分,我假设A,B,C,D和E是不可变的,并且rshift操作产生一个新对象。) F = A >> B >> C >> D >> E 计算如.. ...
-
优先级和关联性是不同的概念,但从技术上讲,C和C ++标准没有指定。 相反,他们给出语法规则来推断表达式的结构。 相关规则是: conditional-expression: logical-or-expression logical-or-expression ? expression : assignment-expression expression: assignment-expression expression , assignment-expression ...
-
这是一个gcc扩展。 x = a ? : b; 几乎是一样的 x = a ? a : b; 除了a只被评估一次这一事实,如果a有任何副作用或评价昂贵,这是有用的。 It's a gcc extension. x = a ? : b; is almost the same as x = a ? a : b; except for the fact that a is only evaluated once, which is useful if a has any side effects or is ...
-
从最新的公开草案 5.6乘法运算符[expr.mul] 1乘法运算符*,/和%组从左到右。 multiplicative-expression: pm-expression multiplicative-expression * pm-expression multiplicative-expression / pm-expression multiplicative-expression % pm-expression 所以解析会像这样: int res = x / y * z / t; int res ...