通过assertThat(Assertj)列出断言

时间:2018-04-11 04:44:19

标签: java list selenium automation assertions

通常当我们发送期望值和实际值的List类型时,assertThat将对这些值执行提到的断言类型。但是,因为我将Java升级到8,那些断言或显示编译错误。以下是关于断言的示例测试代码:

import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class VerificationTest {


    public void listTest(List<?> expectedList, List<?> actualList){
        Iterable<?> actualIterable = actualList;
        Iterable<?> expectedIterable = expectedList;
        assertThat(actualIterable).describedAs("List Test").containsAll(expectedIterable);
    }

    public static void main(String args[]){
        List<String> listOne = new ArrayList<>();
        listOne.add("A");
        listOne.add("B");
        listOne.add("C");

        List<String> listTwo = new ArrayList<>();
        listTwo.add("A");
        listTwo.add("B");
        listTwo.add("C");
        listTwo.add("D");

        VerificationTest verificationTest = new VerificationTest();
        verificationTest.listTest(listOne, listTwo);
    }
}

以下是我得到的错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The method hasSameElementsAs(Iterable<? extends capture#1-of ?>) in the type AbstractIterableAssert<capture#2-of ?,capture#3-of ? extends List<? extends capture#1-of ?>,capture#1-of ?> is not applicable for the arguments (List<capture#5-of ?>)

这是什么问题?这是因为Java 8吗?

谢谢

0 个答案:

没有答案