From e44c72f727f1c7a5b43f7e48d52a2af3ab748f00 Mon Sep 17 00:00:00 2001 From: Zeger Hendrikse Date: Mon, 30 Jan 2017 20:33:02 +0100 Subject: [PATCH] Reformatted PreConditions test --- .../guava/GuavaPreConditionsTest.java | 70 ++++++++++++++----- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/guava/src/test/java/org/baeldung/guava/GuavaPreConditionsTest.java b/guava/src/test/java/org/baeldung/guava/GuavaPreConditionsTest.java index 1611bec672..55e3c7db00 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaPreConditionsTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaPreConditionsTest.java @@ -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)) - .hasNoCause(); + assertThatThrownBy(() -> checkState(Arrays.binarySearch(validStates, givenState) > 0, message, givenState, Arrays.toString(validStates))) + .isInstanceOf(IllegalStateException.class) + .hasMessage(message, givenState, Arrays.toString(validStates)) + .hasNoCause(); } -} \ No newline at end of file +}