我想要一個簡單的Hamcrest匹配器,用於查找List<String>
中某個對象的重複項。這就是我寫的Hamcrest Matcher在字符串列表中沒有重複項?
for (QuizEntity quiz : quizzes)
for (QuestionEntity question : quiz.getQuestions())
Assert.assertThat("There should be no duplicate questions", 1, Matchers.equalTo(Collections.frequency(questions, question.getQuestion())));
不幸的是我得到這個輸出,這是不夠描述。任何
java.lang.AssertionError: There should be no duplicate questions
Expected: <20>
but: was <1>