2016-04-06 7 views
1

は、我々は、Eclipseでの輸入問題を抱えているときStricAssertionsとアサーションを置き換える:Eclipseの整理輸入

輸入を整理するには、Ctrl + Shiftキー+ Oを押すと、テストクラスは

Assertions.assertThat使用して、Eclipseはアサーションを交換してください。

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); 
    } 
} 
: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); 
    } 
} 

が置き換えられてassertThat

Assertions(リストの場合のみ)に特定のアサーションがある場合、EclipseはStrictAssertionsをインポートに追加します。

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; 
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(); 
    } 
} 

アサーションがStrictAssertionsを拡張し、そうStrictAssertionsを使用しても問題は彼らではありませんが、なぜEclipseは拡張したクラスを使用していないようですか? assertThat(int actual)StrictAssertionsで定義され、Assertionsによって隠されていない、EclipseはStrictAssertionsからインポートすることを決定しているため

答えて

1

は、のように見えます。

また、インポートを整理するために、Eclipseは無視するようです。タイプフィルタ - そうでも役立たないでしょう。

アサーションがStrictAssertionsを拡張しているようですので、StrictAssertions現在のセットアップのため

ない

を使用しても問題は彼らではありませんが、 StrictAssertionsAssertJ 3.2.0で削除されました。したがって、 AssertJ StrictAssertionsの新しいバージョンにアップグレードすると、あなたの方法で取得します。

プロジェクトで可能な場合は、3.2.0以降のにアップグレードすることをお勧めします。

+0

さて、それは使用してテストすると思われる assertThat(file).hasSameContentAs(refFile); これ以上は通過しません... 2ダミーファイルをチェックしようとしているとき、それは動作しています... – GaspardP

+0

@GaspardPhmm、私のテストで動作します。ファイルのエンコーディングを設定/チェックしましたか? – nyname00

+0

さて、我々は道を見つけた: hasSameContentはV3.2.0で2つの文字列を比較し、V3.1.0のバイナリファイルと比較していました。 と私たちのテストではバイナリファイルを比較する必要がありました。 – GaspardP