Reformatted PreConditions test
This commit is contained in:
parent
e3c1e6986b
commit
e44c72f727
@ -11,7 +11,10 @@ public class GuavaPreConditionsTest {
|
|||||||
public void whenCheckArgumentEvaluatesFalse_throwsException() {
|
public void whenCheckArgumentEvaluatesFalse_throwsException() {
|
||||||
int age = -18;
|
int age = -18;
|
||||||
|
|
||||||
assertThatThrownBy(() -> checkArgument(age > 0)).isInstanceOf(IllegalArgumentException.class).hasMessage(null).hasNoCause();
|
assertThatThrownBy(() -> checkArgument(age > 0))
|
||||||
|
.isInstanceOf(IllegalArgumentException.class)
|
||||||
|
.hasMessage(null)
|
||||||
|
.hasNoCause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -19,7 +22,10 @@ public class GuavaPreConditionsTest {
|
|||||||
final int age = -18;
|
final int age = -18;
|
||||||
final String message = "Age can't be zero or less than zero";
|
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
|
@Test
|
||||||
@ -27,14 +33,19 @@ public class GuavaPreConditionsTest {
|
|||||||
final int age = -18;
|
final int age = -18;
|
||||||
final String message = "Age can't be zero or less than zero, you supplied %s.";
|
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
|
@Test
|
||||||
public void givenArrayOfIntegers_whenCheckElementIndexEvaluatesFalse_throwsException() {
|
public void givenArrayOfIntegers_whenCheckElementIndexEvaluatesFalse_throwsException() {
|
||||||
final int[] numbers = { 1, 2, 3, 4, 5 };
|
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
|
@Test
|
||||||
@ -42,14 +53,20 @@ public class GuavaPreConditionsTest {
|
|||||||
final int[] numbers = { 1, 2, 3, 4, 5 };
|
final int[] numbers = { 1, 2, 3, 4, 5 };
|
||||||
final String message = "Please check the bound of an array and retry";
|
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
|
@Test
|
||||||
public void givenNullString_whenCheckNotNullCalled_throwsException() {
|
public void givenNullString_whenCheckNotNullCalled_throwsException() {
|
||||||
final String nullObject = null;
|
final String nullObject = null;
|
||||||
|
|
||||||
assertThatThrownBy(() -> checkNotNull(nullObject)).isInstanceOf(NullPointerException.class).hasMessage(null).hasNoCause();
|
assertThatThrownBy(() -> checkNotNull(nullObject))
|
||||||
|
.isInstanceOf(NullPointerException.class)
|
||||||
|
.hasMessage(null)
|
||||||
|
.hasNoCause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -57,7 +74,10 @@ public class GuavaPreConditionsTest {
|
|||||||
final String nullObject = null;
|
final String nullObject = null;
|
||||||
final String message = "Please check the Object supplied, its 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
|
@Test
|
||||||
@ -65,14 +85,19 @@ public class GuavaPreConditionsTest {
|
|||||||
final String nullObject = null;
|
final String nullObject = null;
|
||||||
final String message = "Please check the Object supplied, its %s!";
|
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
|
@Test
|
||||||
public void givenArrayOfIntegers_whenCheckPositionIndexEvaluatesFalse_throwsException() {
|
public void givenArrayOfIntegers_whenCheckPositionIndexEvaluatesFalse_throwsException() {
|
||||||
final int[] numbers = { 1, 2, 3, 4, 5 };
|
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
|
@Test
|
||||||
@ -80,14 +105,19 @@ public class GuavaPreConditionsTest {
|
|||||||
final int[] numbers = { 1, 2, 3, 4, 5 };
|
final int[] numbers = { 1, 2, 3, 4, 5 };
|
||||||
final String message = "Please check the bound of an array and retry";
|
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
|
@Test
|
||||||
public void givenArrayOfIntegers_whenCheckPositionIndexesEvaluatesFalse_throwsException() {
|
public void givenArrayOfIntegers_whenCheckPositionIndexesEvaluatesFalse_throwsException() {
|
||||||
final int[] numbers = { 1, 2, 3, 4, 5 };
|
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
|
@Test
|
||||||
@ -95,7 +125,10 @@ public class GuavaPreConditionsTest {
|
|||||||
final int[] validStates = { -1, 0, 1 };
|
final int[] validStates = { -1, 0, 1 };
|
||||||
final int givenState = 10;
|
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
|
@Test
|
||||||
@ -104,7 +137,10 @@ public class GuavaPreConditionsTest {
|
|||||||
final int givenState = 10;
|
final int givenState = 10;
|
||||||
final String message = "You have entered an invalid state";
|
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
|
@Test
|
||||||
@ -113,7 +149,9 @@ public class GuavaPreConditionsTest {
|
|||||||
final int givenState = 10;
|
final int givenState = 10;
|
||||||
final String message = "State can't be %s, It can be one of %s.";
|
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();
|
.hasNoCause();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user