From c017bd4a365ae772f999371de5a4da7833f8c1c2 Mon Sep 17 00:00:00 2001 From: Max Weber Date: Tue, 15 Jan 2019 22:14:43 -0700 Subject: [PATCH] PatchImplementationTest: Don't immediately fail upon finding an error --- runelite-client/pom.xml | 6 ++++++ .../farming/FarmingWorldTest.java | 3 ++- .../farming/PatchImplementationTest.java | 21 ++++++++++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/runelite-client/pom.xml b/runelite-client/pom.xml index 04402f1295..632d00f943 100644 --- a/runelite-client/pom.xml +++ b/runelite-client/pom.xml @@ -220,6 +220,12 @@ 4.12 test + + org.hamcrest + hamcrest-library + 1.3 + test + org.mockito mockito-all diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/timetracking/farming/FarmingWorldTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/timetracking/farming/FarmingWorldTest.java index 05a45ffe52..78bf100c05 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/timetracking/farming/FarmingWorldTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/timetracking/farming/FarmingWorldTest.java @@ -21,7 +21,8 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */package net.runelite.client.plugins.timetracking.farming; + */ +package net.runelite.client.plugins.timetracking.farming; import org.junit.Test; diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/timetracking/farming/PatchImplementationTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/timetracking/farming/PatchImplementationTest.java index ef6f73b94f..6ed2f81f60 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/timetracking/farming/PatchImplementationTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/timetracking/farming/PatchImplementationTest.java @@ -26,11 +26,16 @@ package net.runelite.client.plugins.timetracking.farming; import java.util.HashMap; import java.util.Map; -import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ErrorCollector; +import static org.hamcrest.Matchers.*; public class PatchImplementationTest { + @Rule + public ErrorCollector collector = new ErrorCollector(); + @Test public void testRange() { @@ -43,20 +48,20 @@ public class PatchImplementationTest if (s != null) { String pfx = impl.name() + "[" + i + "]"; - Assert.assertNotNull(pfx + ": null cropState", s.getCropState()); - Assert.assertNotNull(pfx + ": null produce", s.getProduce()); - Assert.assertTrue(pfx + ": " + s.getStage() + " < 0", s.getStage() >= 0); + collector.checkThat(pfx + ": cropState", s.getCropState(), notNullValue()); + collector.checkThat(pfx + ": produce", s.getProduce(), notNullValue()); + collector.checkThat(pfx + ": negative stage", s.getStage(), greaterThanOrEqualTo(0)); int stages = s.getProduce().getStages(); if (s.getCropState() == CropState.HARVESTABLE) { stages = s.getProduce().getHarvestStages(); } - Assert.assertTrue(pfx + ": " + s.getStage() + " >= " + stages, s.getStage() < stages); + collector.checkThat(pfx + ": out of bounds stage", s.getStage(), lessThan(stages)); if (s.getCropState() == CropState.DEAD || s.getCropState() == CropState.DISEASED) { - Assert.assertTrue(pfx + ": dead seed", s.getStage() > 0); + collector.checkThat(pfx + ": dead seed", s.getStage(), greaterThan(0)); } - if (s.getCropState() == CropState.GROWING && s.getProduce() != Produce.WEEDS) + if (s.getCropState() == CropState.GROWING && s.getProduce() != Produce.WEEDS && s.getStage() < stages) { harvestStages.computeIfAbsent(s.getProduce(), k -> new boolean[s.getProduce().getStages()])[s.getStage()] = true; } @@ -69,7 +74,7 @@ public class PatchImplementationTest // Alot of time the final stage is not hit, because some plants do not have a "Check-health" stage for (int i = 0; i < states.length - 1; i++) { - Assert.assertTrue(produce.getKey().getName() + " stage " + i + " never found by varbit", states[i]); + collector.checkThat(produce.getKey().getName() + " stage " + i + " never found by varbit", states[i], is(true)); } } }