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

New methods copyValueOf, is(Not)Empty and capitalise #323

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 42 additions & 2 deletions src/main/java/nl/hsac/fitnesse/fixture/slim/StringFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public String valueOf(String value) {
return value;
}

/**
* NOTE: Duplicate implementation of method 'valueOf' to prevent unintended calls to Browser Test method with the same name
* Returns value.
* @param value value to return
*/
public String copyValueOf(String value) {
return value;
}

/**
* Determines length of string.
* @param value value to determine length of
Expand All @@ -33,13 +42,31 @@ public int lengthOf(String value) {
return length;
}

/**
* Checks if an input String is null or empty (length() = 0).
* @param inputString An input String to check.
* @return {@code true} if empty, or {@code false} otherwise.
*/
public boolean isEmpty (String inputString) {
jtenkate marked this conversation as resolved.
Show resolved Hide resolved
return StringUtils.isEmpty(inputString);
}

/**
* Checks if an input String is not null or not empty (length() != 0).
* @param inputString An input String to check.
* @return {@code true} if filled (not empty), or {@code false} otherwise.
*/
public boolean isNotEmpty (String inputString) {
return !isEmpty(inputString);
}

/**
* <p>Compares two Strings, returning <code>false</code> if they are equal.</p>
*
* <p><code>null</code>s are handled without exceptions. Two <code>null</code>
* references are considered to be equal. The comparison is case sensitive.</p>
*
* @see org.apache.commons.lang3.StringUtils#equals(CharSequence, CharSequence)
* @see StringUtils#equals(CharSequence, CharSequence)
* @param value1 the first String, may be null
* @param value2 the second String, may be null
* @return <code>false</code> if the Strings are equal, or both <code>null</code>
Expand All @@ -54,7 +81,7 @@ public boolean valueDiffersFrom(String value1, String value2) {
* <p><code>null</code>s are handled without exceptions. Two <code>null</code>
* references are considered to be equal. The comparison is case sensitive.</p>
*
* @see org.apache.commons.lang3.StringUtils#equals(CharSequence, CharSequence)
* @see StringUtils#equals(CharSequence, CharSequence)
* @param value1 the first String, may be null
* @param value2 the second String, may be null
* @return <code>true</code> if the Strings are equal, or both <code>null</code>
Expand Down Expand Up @@ -103,6 +130,19 @@ public String convertToLowerCase(String value) {
return result;
}

/**
* Capitalise first character of a string.
* @param value value to capitalise.
* @return value capitalised.
*/
public String capitalise (String value) {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
public String capitalise (String value) {
public String capitalise(String value) {

String result = null;
if (value != null) {
result = StringUtils.capitalize(value);
}
return result;
}

/**
* Determines integer value of String (so relative checks can be done).
* @param value string to convert to integer.
Expand Down
34 changes: 28 additions & 6 deletions src/test/java/nl/hsac/fitnesse/fixture/slim/StringFixtureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
jtenkate marked this conversation as resolved.
Show resolved Hide resolved

/**
* Tests StringFixture.
Expand All @@ -20,12 +16,32 @@ public void testLength() {
assertEquals("hello", 5, fixture.lengthOf("hello"));
}

@Test
public void testIsEmpty() {
assertTrue("null", fixture.isEmpty(null));
assertTrue("", fixture.isEmpty(""));
assertFalse("hello", fixture.isEmpty("hello"));
}

@Test
public void testIsNotEmpty() {
assertFalse("null", fixture.isNotEmpty(null));
assertFalse("", fixture.isNotEmpty(""));
assertTrue("hello", fixture.isNotEmpty("hello"));
}

@Test
public void testValue() {
assertEquals("null", null, fixture.valueOf(null));
assertNull("null", fixture.valueOf(null));
assertEquals("hello", "hello", fixture.valueOf("hello"));
}

@Test
public void testCopyValue() {
assertNull("null", fixture.copyValueOf(null));
assertEquals("hello", "hello", fixture.copyValueOf("hello"));
}

@Test
public void testValueDiffersFrom() {
assertFalse("null - null", fixture.valueDiffersFrom(null, null));
Expand Down Expand Up @@ -100,4 +116,10 @@ public void testConvertToLowerCase() {
assertNull("null", fixture.convertToLowerCase(null));
assertEquals("abC1", "abc1", fixture.convertToLowerCase("abC1"));
}

@Test
public void testCapitalise() {
assertNull("null", fixture.capitalise(null));
assertEquals("abc1", "Abc1", fixture.capitalise("abc1"));
}
}