Reformatted PreConditions test

This commit is contained in:
Zeger Hendrikse 2017-01-30 20:33:02 +01:00
parent e3c1e6986b
commit e44c72f727
1 changed files with 54 additions and 16 deletions

View File

@ -11,7 +11,10 @@ public class GuavaPreConditionsTest {
public void whenCheckArgumentEvaluatesFalse_throwsException() {
int age = -18;
assertThatThrownBy(() -> checkArgument(age > 0)).isInstanceOf(IllegalArgumentException.class).hasMessage(null).hasNoCause();
assertThatThrownBy(() -> checkArgument(age > 0))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(null)
.hasNoCause();
}
@Test
@ -19,7 +22,10 @@ public class GuavaPreConditionsTest {
final int age = -18;
final String message = "Age can't be zero or less than zero";
assertThatThrownBy(() -> checkArgument(age > 0, message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message).hasNoCause();
assertThatThrownBy(() -> checkArgument(age > 0, message))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(message)
.hasNoCause();
}
@Test
@ -27,14 +33,19 @@ public class GuavaPreConditionsTest {
final int age = -18;
final String message = "Age can't be zero or less than zero, you supplied %s.";
assertThatThrownBy(() -> checkArgument(age > 0, message, age)).isInstanceOf(IllegalArgumentException.class).hasMessage(message, age).hasNoCause();
assertThatThrownBy(() -> checkArgument(age > 0, message, age))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(message, age)
.hasNoCause();
}
@Test
public void givenArrayOfIntegers_whenCheckElementIndexEvaluatesFalse_throwsException() {
final int[] numbers = { 1, 2, 3, 4, 5 };
assertThatThrownBy(() -> checkElementIndex(6, numbers.length - 1)).isInstanceOf(IndexOutOfBoundsException.class).hasNoCause();
assertThatThrownBy(() -> checkElementIndex(6, numbers.length - 1))
.isInstanceOf(IndexOutOfBoundsException.class)
.hasNoCause();
}
@Test
@ -42,14 +53,20 @@ public class GuavaPreConditionsTest {
final int[] numbers = { 1, 2, 3, 4, 5 };
final String message = "Please check the bound of an array and retry";
assertThatThrownBy(() -> checkElementIndex(6, numbers.length - 1, message)).isInstanceOf(IndexOutOfBoundsException.class).hasMessageStartingWith(message).hasNoCause();
assertThatThrownBy(() -> checkElementIndex(6, numbers.length - 1, message))
.isInstanceOf(IndexOutOfBoundsException.class)
.hasMessageStartingWith(message)
.hasNoCause();
}
@Test
public void givenNullString_whenCheckNotNullCalled_throwsException() {
final String nullObject = null;
assertThatThrownBy(() -> checkNotNull(nullObject)).isInstanceOf(NullPointerException.class).hasMessage(null).hasNoCause();
assertThatThrownBy(() -> checkNotNull(nullObject))
.isInstanceOf(NullPointerException.class)
.hasMessage(null)
.hasNoCause();
}
@Test
@ -57,7 +74,10 @@ public class GuavaPreConditionsTest {
final String nullObject = null;
final String message = "Please check the Object supplied, its null!";
assertThatThrownBy(() -> checkNotNull(nullObject, message)).isInstanceOf(NullPointerException.class).hasMessage(message).hasNoCause();
assertThatThrownBy(() -> checkNotNull(nullObject, message))
.isInstanceOf(NullPointerException.class)
.hasMessage(message)
.hasNoCause();
}
@Test
@ -65,14 +85,19 @@ public class GuavaPreConditionsTest {
final String nullObject = null;
final String message = "Please check the Object supplied, its %s!";
assertThatThrownBy(() -> checkNotNull(nullObject, message, nullObject)).isInstanceOf(NullPointerException.class).hasMessage(message, nullObject).hasNoCause();
assertThatThrownBy(() -> checkNotNull(nullObject, message, nullObject))
.isInstanceOf(NullPointerException.class)
.hasMessage(message, nullObject)
.hasNoCause();
}
@Test
public void givenArrayOfIntegers_whenCheckPositionIndexEvaluatesFalse_throwsException() {
final int[] numbers = { 1, 2, 3, 4, 5 };
assertThatThrownBy(() -> checkPositionIndex(6, numbers.length - 1)).isInstanceOf(IndexOutOfBoundsException.class).hasNoCause();
assertThatThrownBy(() -> checkPositionIndex(6, numbers.length - 1))
.isInstanceOf(IndexOutOfBoundsException.class)
.hasNoCause();
}
@Test
@ -80,14 +105,19 @@ public class GuavaPreConditionsTest {
final int[] numbers = { 1, 2, 3, 4, 5 };
final String message = "Please check the bound of an array and retry";
assertThatThrownBy(() -> checkPositionIndex(6, numbers.length - 1, message)).isInstanceOf(IndexOutOfBoundsException.class).hasMessageStartingWith(message).hasNoCause();
assertThatThrownBy(() -> checkPositionIndex(6, numbers.length - 1, message))
.isInstanceOf(IndexOutOfBoundsException.class)
.hasMessageStartingWith(message)
.hasNoCause();
}
@Test
public void givenArrayOfIntegers_whenCheckPositionIndexesEvaluatesFalse_throwsException() {
final int[] numbers = { 1, 2, 3, 4, 5 };
assertThatThrownBy(() -> checkPositionIndexes(6, 0, numbers.length - 1)).isInstanceOf(IndexOutOfBoundsException.class).hasNoCause();
assertThatThrownBy(() -> checkPositionIndexes(6, 0, numbers.length - 1))
.isInstanceOf(IndexOutOfBoundsException.class)
.hasNoCause();
}
@Test
@ -95,7 +125,10 @@ public class GuavaPreConditionsTest {
final int[] validStates = { -1, 0, 1 };
final int givenState = 10;
assertThatThrownBy(() -> checkState(Arrays.binarySearch(validStates, givenState) > 0)).isInstanceOf(IllegalStateException.class).hasMessage(null).hasNoCause();
assertThatThrownBy(() -> checkState(Arrays.binarySearch(validStates, givenState) > 0))
.isInstanceOf(IllegalStateException.class)
.hasMessage(null)
.hasNoCause();
}
@Test
@ -104,7 +137,10 @@ public class GuavaPreConditionsTest {
final int givenState = 10;
final String message = "You have entered an invalid state";
assertThatThrownBy(() -> checkState(Arrays.binarySearch(validStates, givenState) > 0, message)).isInstanceOf(IllegalStateException.class).hasMessageStartingWith(message).hasNoCause();
assertThatThrownBy(() -> checkState(Arrays.binarySearch(validStates, givenState) > 0, message))
.isInstanceOf(IllegalStateException.class)
.hasMessageStartingWith(message)
.hasNoCause();
}
@Test
@ -113,7 +149,9 @@ public class GuavaPreConditionsTest {
final int givenState = 10;
final String message = "State can't be %s, It can be one of %s.";
assertThatThrownBy(() -> checkState(Arrays.binarySearch(validStates, givenState) > 0, message, givenState, Arrays.toString(validStates))).isInstanceOf(IllegalStateException.class).hasMessage(message, givenState, Arrays.toString(validStates))
assertThatThrownBy(() -> checkState(Arrays.binarySearch(validStates, givenState) > 0, message, givenState, Arrays.toString(validStates)))
.isInstanceOf(IllegalStateException.class)
.hasMessage(message, givenState, Arrays.toString(validStates))
.hasNoCause();
}
}