JUnit4でdoubleを返すメソッドのテストを行う場合、assertThat(is(actual, expected))では誤差でテスト失敗になることがあります。その場合、closeToを使います。closeToは、org.hamcrest.Matchersのクラスメソッドで、ライブラリを導入する必要があります。Eclipseで、mavenプロジェクトのPOMエディタでは、次のように設定をします。
テストコードでは、
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.Matchers.closeTo; import static org.junit.Assert.*; public class FooTest { ... @Test public void some_test() { ... assertThat(actual, is(closeTo(expected, delta))); } }
と書きます。