Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for class feign.Util #844

Merged
merged 1 commit into from
Nov 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions core/src/test/java/feign/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*/
package feign;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.Test;
import java.io.Reader;
import java.lang.reflect.Type;
Expand All @@ -31,6 +34,9 @@

public class UtilTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void removesEmptyStrings() {
String[] values = new String[] {"", null};
Expand Down Expand Up @@ -122,6 +128,114 @@ public void unboundWildcardIsObject() throws Exception {
assertEquals(Object.class, last);
}

@Test
public void checkArgumentInputFalseNotNullNullOutputIllegalArgumentException() {
// Arrange
final boolean expression = false;
final String errorMessageTemplate = "";
final Object[] errorMessageArgs = null;
// Act
thrown.expect(IllegalArgumentException.class);
Util.checkArgument(expression, errorMessageTemplate, errorMessageArgs);
// Method is not expected to return due to exception thrown
}

@Test
public void checkNotNullInputNullNotNullNullOutputNullPointerException() {
Copy link
Contributor

@rage-shadowman rage-shadowman Nov 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, these would make a lot more sense if there was more separation of terms. All of this "NullNotNullNull" stuff makes zero sense to new eyes on the project (kindoflikereadingasentencewithoutanyspacesinit - kinda like reading a sentence without spaces), but "checkNotNull_referenceNull_messageNotNull_messageArgsNull_nullPointerExceptionThrown" is a lot easier to read and understand the coder's intentions without looking at the code in the test (then when looking at the code, you can more easily tell if it really tests what was intended).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rage-shadowman thanks for your feedback. Much appreciated.

// Arrange
final Object reference = null;
final String errorMessageTemplate = "";
final Object[] errorMessageArgs = null;
// Act
thrown.expect(NullPointerException.class);
Util.checkNotNull(reference, errorMessageTemplate, errorMessageArgs);
// Method is not expected to return due to exception thrown
}

@Test
public void checkNotNullInputZeroNotNull0OutputZero() {
// Arrange
final Object reference = 0;
final String errorMessageTemplate = " ";
final Object[] errorMessageArgs = {};
// Act
final Object retval = Util.checkNotNull(reference, errorMessageTemplate, errorMessageArgs);
// Assert result
Assert.assertEquals(new Integer(0), retval);
}

@Test
public void checkStateInputFalseNotNullNullOutputIllegalStateException() {
// Arrange
final boolean expression = false;
final String errorMessageTemplate = "";
final Object[] errorMessageArgs = null;
// Act
thrown.expect(IllegalStateException.class);
Util.checkState(expression, errorMessageTemplate, errorMessageArgs);
// Method is not expected to return due to exception thrown
}

@Test
public void emptyToNullInputNotNullOutputNotNull() {
// Arrange
final String string = "AAAAAAAA";
// Act
final String retval = Util.emptyToNull(string);
// Assert result
Assert.assertEquals("AAAAAAAA", retval);
}

@Test
public void emptyToNullInputNullOutputNull() {
// Arrange
final String string = null;
// Act
final String retval = Util.emptyToNull(string);
// Assert result
Assert.assertNull(retval);
}

@Test
public void isBlankInputNotNullOutputFalse() {
// Arrange
final String value = "AAAAAAAA";
// Act
final boolean retval = Util.isBlank(value);
// Assert result
Assert.assertEquals(false, retval);
}

@Test
public void isBlankInputNullOutputTrue() {
// Arrange
final String value = null;
// Act
final boolean retval = Util.isBlank(value);
// Assert result
Assert.assertEquals(true, retval);
}

@Test
public void isNotBlankInputNotNullOutputFalse() {
// Arrange
final String value = "";
// Act
final boolean retval = Util.isNotBlank(value);
// Assert result
Assert.assertEquals(false, retval);
}

@Test
public void isNotBlankInputNotNullOutputTrue() {
// Arrange
final String value = "AAAAAAAA";
// Act
final boolean retval = Util.isNotBlank(value);
// Assert result
Assert.assertEquals(true, retval);
}

interface LastTypeParameter {
final List<String> LIST_STRING = null;
final Parameterized<List<String>> PARAMETERIZED_LIST_STRING = null;
Expand Down