From 767b966d1a8446f9142b5b6f317ae1b75911fa05 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 26 Aug 2017 18:06:42 +0100 Subject: [PATCH] ValueTest: use val and have assertions in tests Codacy's PMD check 'JUnit tests should include assert() or fail()' insists on the assert being in the actual test method itself. --- .../net/kemitix/conditional/ValueTest.java | 160 +++++++++--------- 1 file changed, 76 insertions(+), 84 deletions(-) diff --git a/src/test/java/net/kemitix/conditional/ValueTest.java b/src/test/java/net/kemitix/conditional/ValueTest.java index 6971115..2b7b790 100644 --- a/src/test/java/net/kemitix/conditional/ValueTest.java +++ b/src/test/java/net/kemitix/conditional/ValueTest.java @@ -1,5 +1,6 @@ package net.kemitix.conditional; +import lombok.val; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -16,205 +17,196 @@ public class ValueTest { @Test public void valueWhereTrueIsTrue() { //when - final String result = Value.where(true).then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(true).then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsTrue(result); + assertThat(result).isEqualTo(TRUE); } @Test public void valueWhereFalseIsFalse() { //when - final String result = Value.where(false).then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(false).then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsFalse(result); + assertThat(result).isEqualTo(FALSE); } @Test public void valueWhereTrueAndTrueIsTrue() { //when - final String result = Value.where(true).and(true) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(true).and(true) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsTrue(result); + assertThat(result).isEqualTo(TRUE); } @Test public void valueWhereTrueAndFalseIsFalse() { //when - final String result = Value.where(true).and(false) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(true).and(false) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsFalse(result); + assertThat(result).isEqualTo(FALSE); } @Test public void valueWhereFalseAndTrueIsFalse() { //when - final String result = Value.where(false).and(true) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(false).and(true) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsFalse(result); + assertThat(result).isEqualTo(FALSE); } @Test public void valueWhereFalseAndFalseIsFalse() { //when - final String result = Value.where(false).and(false) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(false).and(false) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsFalse(result); + assertThat(result).isEqualTo(FALSE); } @Test public void valueWhereTrueOrTrueIsTrue() { //when - final String result = Value.where(true).or(true) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(true).or(true) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsTrue(result); + assertThat(result).isEqualTo(TRUE); } @Test public void valueWhereTrueOrFalseIsTrue() { //when - final String result = Value.where(true).or(false) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(true).or(false) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsTrue(result); + assertThat(result).isEqualTo(TRUE); } @Test public void valueWhereFalseOrTrueIsTrue() { //when - final String result = Value.where(false).or(true) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(false).or(true) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsTrue(result); + assertThat(result).isEqualTo(TRUE); } @Test public void valueWhereFalseOrFalseIsFalse() { //when - final String result = Value.where(false).or(false) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(false).or(false) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsFalse(result); + assertThat(result).isEqualTo(FALSE); } @Test public void valueWhereNotTrueIsFalse() { //when - final String result = Value.whereNot(true).then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.whereNot(true).then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsFalse(result); + assertThat(result).isEqualTo(FALSE); } @Test public void valueWhereNotFalseIsTrue() { //when - final String result = Value.whereNot(false).then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.whereNot(false).then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsTrue(result); + assertThat(result).isEqualTo(TRUE); } @Test public void valueWhereTrueAndNotTrueIsFalse() { //when - final String result = Value.where(true).andNot(true) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(true).andNot(true) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsFalse(result); + assertThat(result).isEqualTo(FALSE); } @Test public void valueWhereTrueAndNotFalseIsTrue() { //when - final String result = Value.where(true).andNot(false) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(true).andNot(false) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsTrue(result); + assertThat(result).isEqualTo(TRUE); } @Test public void valueWhereFalseAndNotTrueIsFalse() { //when - final String result = Value.where(false).andNot(true) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(false).andNot(true) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsFalse(result); + assertThat(result).isEqualTo(FALSE); } @Test public void valueWhereFalseAndNotFalseIsFalse() { //when - final String result = Value.where(false).andNot(false) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(false).andNot(false) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsFalse(result); + assertThat(result).isEqualTo(FALSE); } @Test public void valueWhereTrueOrNotTrueIsTrue() { //when - final String result = Value.where(true).orNot(true) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(true).orNot(true) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsTrue(result); + assertThat(result).isEqualTo(TRUE); } @Test public void valueWhereTrueOrNotFalseIsTrue() { //when - final String result = Value.where(true).orNot(false) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(true).orNot(false) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsTrue(result); + assertThat(result).isEqualTo(TRUE); } @Test public void valueWhereFalseOrNotTrueIsFalse() { //when - final String result = Value.where(false).orNot(true) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(false).orNot(true) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsFalse(result); + assertThat(result).isEqualTo(FALSE); } @Test public void valueWhereFalseOrNotFalseIsTrue() { //when - final String result = Value.where(false).orNot(false) - .then(() -> TRUE) - .otherwise(() -> FALSE); + val result = Value.where(false).orNot(false) + .then(() -> TRUE) + .otherwise(() -> FALSE); //then - thenIsTrue(result); - } - - private void thenIsFalse(final String result) { - assertThat(result).isEqualTo(FALSE); - } - - private void thenIsTrue(final String result) { assertThat(result).isEqualTo(TRUE); } - }