我正在尝试进行测试,检查某个列表是否有项目,而我不关心订单.
我希望能够做到这一点的方法是通过测试项具有某个具有特定值的属性.
我用以下代码隔离了senario:
我正在使用的类别:
public class A {
private String propA;
public A (final String propA) {
this.propA = propA;
}
public String getPropA() {
return propA;
}
public void setPropA(final String propA) {
this.propA = propA;
}
}
Run Code Online (Sandbox Code Playgroud)
识别TestClass
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.beans.HasPropertyWithValue.hasProperty;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
public class HamcrestCollectionTest {
@Test
public void testContainsInAnyOrder() {
List<A> list = new ArrayList<A>();
list.add(new A("a"));
list.add(new A("b"));
assertThat(list, containsInAnyOrder(hasProperty("propA", equalTo("b")), hasProperty("propA", …Run Code Online (Sandbox Code Playgroud) 我正在尝试使maven-checkstyle-plugin对我们所有的项目使用相同的配置文件.
我尝试了几种方法,但没有一种方法是有效的.
唯一似乎有用的是当我将配置文件放在我的maven项目的根目录,然后在pom.xml中使用名称作为configLocation配置参数
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<configuration>
<configLocation>my-checkstyle-checker.xml</configLocation>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我已经尝试指定绝对磁盘路径,但这似乎不起作用.(考虑到endgoal是让jenkins做checkstyle,如果文件位于指定位置的jenkins服务器上,这似乎是一个有效的选项)
我还尝试制作一个只包含xml文件的单独jar文件,然后将其用作依赖项.(这也会将配置集中在一个位置,并防止项目特定的偏差.)不幸的是,这也不起作用.
[错误]无法在项目jenkins-sandbox-project上执行目标org.apache.maven.plugins:maven-checkstyle-plugin:2.10:checkstyle(default-cli):Checkstyle报告生成中发生错误.在checkstyle执行期间失败:无法在位置找到配置文件my-checkstyle-checker.xml:找不到资源'my-checkstyle-checker.xml'. - > [帮助1]
有没有人可以告诉我这里我做错了什么?
它似乎只知道与maven命令启动位置相同的文件.