From bce01cfff54e2e081d90277c30db6945585b6dd7 Mon Sep 17 00:00:00 2001 From: Magdalena Krause Date: Sat, 10 Mar 2018 12:51:37 -0300 Subject: [PATCH] Bael 1580 2 (#3787) * BAEL-1580: Changing hamcrest dependency. * BAEL-1580: Adding test scope. * BAEL-1580: Adding comparesEqualTo and notANumber matchers. --- testing-modules/mockito/pom.xml | 7 +++-- .../hamcrest/HamcrestNumberUnitTest.java | 28 ++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/testing-modules/mockito/pom.xml b/testing-modules/mockito/pom.xml index 1ec1ffe7bd..cdd73e6efe 100644 --- a/testing-modules/mockito/pom.xml +++ b/testing-modules/mockito/pom.xml @@ -46,14 +46,14 @@ ${powermock.version} test - + org.hamcrest java-hamcrest - 2.0.0.0 + ${hamcrest.version} test - + @@ -74,6 +74,7 @@ 1.7.0 + 2.0.0.0 diff --git a/testing-modules/mockito/src/test/java/org/baeldung/hamcrest/HamcrestNumberUnitTest.java b/testing-modules/mockito/src/test/java/org/baeldung/hamcrest/HamcrestNumberUnitTest.java index 21606afd79..fbba6b94d2 100644 --- a/testing-modules/mockito/src/test/java/org/baeldung/hamcrest/HamcrestNumberUnitTest.java +++ b/testing-modules/mockito/src/test/java/org/baeldung/hamcrest/HamcrestNumberUnitTest.java @@ -6,8 +6,15 @@ import java.math.BigDecimal; import java.time.LocalDate; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.comparesEqualTo; +import static org.hamcrest.Matchers.notANumber; public class HamcrestNumberUnitTest { @@ -43,6 +50,19 @@ public class HamcrestNumberUnitTest { assertThat(actual, is(not(closeTo(operand, error)))); } + @Test + public void given5_whenComparesEqualTo5_thenCorrect() { + Integer five = 5; + assertThat(five, comparesEqualTo(five)); + } + + @Test + public void given5_whenNotComparesEqualTo7_thenCorrect() { + Integer seven = 7; + Integer five = 5; + assertThat(five, not(comparesEqualTo(seven))); + } + @Test public void given7_whenGreaterThan5_thenCorrect() { Integer seven = 7; @@ -149,4 +169,10 @@ public class HamcrestNumberUnitTest { else return -1; } } + + @Test + public void givenNaN_whenIsNotANumber_thenCorrect() { + double zero = 0d; + assertThat(zero / zero, is(notANumber())); + } }