Java Eclipse在组织导入时将断言替换为StricAssertions

Java Eclipse在组织导入时将断言替换为StricAssertions,java,eclipse,import,assertions,Java,Eclipse,Import,Assertions,Eclipse存在导入问题: 测试类使用断言。assertThat import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; public class TheTest { @Test public void testName() { assertThat(2).isEqualTo(2); } } 当按下Ctrl+Shift+O组合键来组织导入时,

Eclipse存在导入问题:

测试类使用断言。assertThat

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

import org.junit.Test;

public class TheTest {

    @Test
    public void testName() {
        assertThat(2).isEqualTo(2);
    }
}
当按下Ctrl+Shift+O组合键来组织导入时,Eclipse将Assertions.assertThat替换为StrictAssertions.assertThat

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

import org.junit.Test;

public class TheTest {

    @Test
    public void testName() {
        assertThat(2).isEqualTo(2);
    }
}
替换为:

import static org.assertj.core.api.StrictAssertions.assertThat;  // change here !

import org.junit.Test;

public class TheTest {

    @Test
    public void testName() {
        assertThat(2).isEqualTo(2);
    }
}
当我们有一些仅在断言(对于列表)中的特定断言时,Eclipse会向导入添加StrictAssertion

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

import java.util.ArrayList;

import org.junit.Test;

public class TheTest {

    @Test
    public void testName() {
        assertThat(2).isEqualTo(2);
        assertThat(new ArrayList<>()).isEmpty();
    }
}
import static org.assertj.core.api.Assertions.assertThat;
导入java.util.ArrayList;
导入org.junit.Test;
公开考试{
@试验
public void testName(){
资产(2)isEqualTo(2);
assertThat(newarraylist()).isEmpty();
}
}
更改为:

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.StrictAssertions.assertThat;  // this import was added 

import java.util.ArrayList;

import org.junit.Test;

public class TheTest {

    @Test
    public void testName() {
        assertThat(2).isEqualTo(2);
        assertThat(new ArrayList<>()).isEmpty();
    }
}
import static org.assertj.core.api.Assertions.assertThat;
导入静态org.assertj.core.api.StrictAssertions.assertThat;//此导入已添加
导入java.util.ArrayList;
导入org.junit.Test;
公开考试{
@试验
public void testName(){
资产(2)isEqualTo(2);
assertThat(newarraylist()).isEmpty();
}
}

断言似乎扩展了StrictAssertions,因此使用StrictAssertions没有问题,但是为什么Eclipse不使用扩展类呢?

看起来像,因为
assertThat(int-actual)
是在
StrictAssertions
中定义的,并且不被
断言所隐藏,Eclipse决定从
StrictAssertions
导入

此外,对于组织导入,Eclipse似乎忽略了类型过滤器——所以即使这样也无济于事

断言似乎扩展了StrictAssertion,因此使用StrictAssertion并没有问题

不适用于您当前的设置,但已使用删除
StrictAssertions
。因此,当升级到较新版本的
AssertJ
StrictAssertions
时,将妨碍您


如果您的项目可能的话,我建议您升级到3.2.0或更高版本。

好吧,似乎使用assertThat(文件)进行测试;你不再路过。。。但是当尝试检查2个虚拟文件时,它起作用了…@GaspardP-hmm,在我的测试中起作用。您是否设置/检查了文件编码?我们找到了一种方法:比较V3.2.0中的2个字符串,并与V3.1.0中的二进制文件进行比较。在我们的测试中,我们需要比较二进制文件;assertThat(file).hasBinaryContent(expectedContent);而且它也在起作用。