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.
This commit is contained in:
Paul Campbell 2017-08-26 18:06:42 +01:00
parent 49fb39d297
commit 767b966d1a

View file

@ -1,5 +1,6 @@
package net.kemitix.conditional; package net.kemitix.conditional;
import lombok.val;
import org.junit.Test; import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -16,205 +17,196 @@ public class ValueTest {
@Test @Test
public void valueWhereTrueIsTrue() { public void valueWhereTrueIsTrue() {
//when //when
final String result = Value.<String>where(true).then(() -> TRUE) val result = Value.<String>where(true).then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereFalseIsFalse() { public void valueWhereFalseIsFalse() {
//when //when
final String result = Value.<String>where(false).then(() -> TRUE) val result = Value.<String>where(false).then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereTrueAndTrueIsTrue() { public void valueWhereTrueAndTrueIsTrue() {
//when //when
final String result = Value.<String>where(true).and(true) val result = Value.<String>where(true).and(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereTrueAndFalseIsFalse() { public void valueWhereTrueAndFalseIsFalse() {
//when //when
final String result = Value.<String>where(true).and(false) val result = Value.<String>where(true).and(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereFalseAndTrueIsFalse() { public void valueWhereFalseAndTrueIsFalse() {
//when //when
final String result = Value.<String>where(false).and(true) val result = Value.<String>where(false).and(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereFalseAndFalseIsFalse() { public void valueWhereFalseAndFalseIsFalse() {
//when //when
final String result = Value.<String>where(false).and(false) val result = Value.<String>where(false).and(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereTrueOrTrueIsTrue() { public void valueWhereTrueOrTrueIsTrue() {
//when //when
final String result = Value.<String>where(true).or(true) val result = Value.<String>where(true).or(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereTrueOrFalseIsTrue() { public void valueWhereTrueOrFalseIsTrue() {
//when //when
final String result = Value.<String>where(true).or(false) val result = Value.<String>where(true).or(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereFalseOrTrueIsTrue() { public void valueWhereFalseOrTrueIsTrue() {
//when //when
final String result = Value.<String>where(false).or(true) val result = Value.<String>where(false).or(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereFalseOrFalseIsFalse() { public void valueWhereFalseOrFalseIsFalse() {
//when //when
final String result = Value.<String>where(false).or(false) val result = Value.<String>where(false).or(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereNotTrueIsFalse() { public void valueWhereNotTrueIsFalse() {
//when //when
final String result = Value.<String>whereNot(true).then(() -> TRUE) val result = Value.<String>whereNot(true).then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereNotFalseIsTrue() { public void valueWhereNotFalseIsTrue() {
//when //when
final String result = Value.<String>whereNot(false).then(() -> TRUE) val result = Value.<String>whereNot(false).then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereTrueAndNotTrueIsFalse() { public void valueWhereTrueAndNotTrueIsFalse() {
//when //when
final String result = Value.<String>where(true).andNot(true) val result = Value.<String>where(true).andNot(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereTrueAndNotFalseIsTrue() { public void valueWhereTrueAndNotFalseIsTrue() {
//when //when
final String result = Value.<String>where(true).andNot(false) val result = Value.<String>where(true).andNot(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereFalseAndNotTrueIsFalse() { public void valueWhereFalseAndNotTrueIsFalse() {
//when //when
final String result = Value.<String>where(false).andNot(true) val result = Value.<String>where(false).andNot(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereFalseAndNotFalseIsFalse() { public void valueWhereFalseAndNotFalseIsFalse() {
//when //when
final String result = Value.<String>where(false).andNot(false) val result = Value.<String>where(false).andNot(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereTrueOrNotTrueIsTrue() { public void valueWhereTrueOrNotTrueIsTrue() {
//when //when
final String result = Value.<String>where(true).orNot(true) val result = Value.<String>where(true).orNot(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereTrueOrNotFalseIsTrue() { public void valueWhereTrueOrNotFalseIsTrue() {
//when //when
final String result = Value.<String>where(true).orNot(false) val result = Value.<String>where(true).orNot(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereFalseOrNotTrueIsFalse() { public void valueWhereFalseOrNotTrueIsFalse() {
//when //when
final String result = Value.<String>where(false).orNot(true) val result = Value.<String>where(false).orNot(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereFalseOrNotFalseIsTrue() { public void valueWhereFalseOrNotFalseIsTrue() {
//when //when
final String result = Value.<String>where(false).orNot(false) val result = Value.<String>where(false).orNot(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result);
}
private void thenIsFalse(final String result) {
assertThat(result).isEqualTo(FALSE);
}
private void thenIsTrue(final String result) {
assertThat(result).isEqualTo(TRUE); assertThat(result).isEqualTo(TRUE);
} }
} }