为什么我不能@FunctionalInterface使用默认方法实现创建?
@FunctionalInterface
public interface MyInterface {
default boolean authorize(String value) {
return true;
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试mvn sonar:sonar在我的项目上运行命令时,经常出现以下错误:
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar (default-c
li) on project ProjectName: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-mav
en-plugin:3.2:sonar failed: Unable to load the mojo 'sonar' in the plugin 'org.sonarsource.scanner.m
aven:sonar-maven-plugin:3.2' due to an API incompatibility: org.codehaus.plexus.component.repository
.exception.ComponentLookupException: org/sonarsource/scanner/maven/SonarQubeMojo : Unsupported major
.minor version 52.0
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.codehaus.mojo:sonar-maven-plugin:3.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/U39/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-pl
ugin/3.2/sonar-maven-plugin-3.2.jar
[ERROR] urls[1] = file:/C:/Users/U39/.m2/repository/org/apache/maven/shared/maven-dependency-tre
e/2.2/maven-dependency-tree-2.2.jar
[ERROR] urls[2] = file:/C:/Users/U39/.m2/repository/org/codehaus/plexus/plexus-component-annotat
ions/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[3] = file:/C:/Users/U39/.m2/repository/org/eclipse/aether/aether-util/0.9.0.M2/aeth
er-util-0.9.0.M2.jar
[ERROR] urls[4] = …Run Code Online (Sandbox Code Playgroud) 我最近开始为现有项目开发 TDD 并面临几个问题,其中一个在下面提到
我有一个要在测试类中模拟的私有变量,该变量如下所示
private Class<XYZ> cls = XYZ.class;
Run Code Online (Sandbox Code Playgroud)
后来这个“cls”变量被用作类名方法之一的参数
private List create(Class className, Object objectTO, List<String> names)
Run Code Online (Sandbox Code Playgroud)
我知道可以模拟私有变量,并且我按照以下步骤模拟了测试用例中的私有变量
java.lang.reflect.Field;Field field = PowerMockito.field(XYZ.class,"cls");field.set(XYZ.class, "objectOfXYZClass");当我运行测试类时,出现以下错误
java.lang.IllegalArgumentException: Can not set java.lang.Class field com.tools.XYZ.cls to java.lang.Class
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:75)
at java.lang.reflect.Field.set(Field.java:680)
Run Code Online (Sandbox Code Playgroud)
请有人帮我解决这个问题,让我知道我错过了什么。
PS:我使用@preparefortest并提到了所有必需的类,并使用运行我的测试类@runwith(powermockrunner.class)