-
Notifications
You must be signed in to change notification settings - Fork 98
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
base: master
Are you sure you want to change the base?
Changes from all commits
c8d6940
4af7d5f
88ff231
96d122a
89adb49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,15 @@ public String valueOf(String value) { | |||||||||
return value; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* NOTE: Duplicate implementation of method 'valueOf' to enable use in scripts started with another fixture containing the same method name (eg. BrowserTest) | ||||||||||
* Returns value. | ||||||||||
* @param value value to return | ||||||||||
*/ | ||||||||||
public String getValueOf(String value) { | ||||||||||
return value; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Determines length of string. | ||||||||||
* @param value value to determine length of | ||||||||||
|
@@ -33,13 +42,60 @@ public int lengthOf(String value) { | |||||||||
return length; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Checks if an input string is empty: null or length() = 0. | ||||||||||
* | ||||||||||
* @param value value to check. | ||||||||||
* @return {@code true} if empty, or {@code false} otherwise. | ||||||||||
*/ | ||||||||||
public boolean isEmpty(String value) { return StringUtils.isEmpty(value); } | ||||||||||
|
||||||||||
/** | ||||||||||
* Checks if a string is not empty: not null and length() != 0. | ||||||||||
* | ||||||||||
* @param value value to check. | ||||||||||
* @return {@code true} if filled (not empty), {@code false} otherwise. | ||||||||||
*/ | ||||||||||
public boolean isNotEmpty(String value) { return !isEmpty(value); } | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem |
||||||||||
|
||||||||||
/** | ||||||||||
* Checks if a value meets the symbol naming convention ('$xyz'). | ||||||||||
* This indicates an undefined FitNesse symbol. | ||||||||||
* http://fitnesse.org/FitNesse.SuiteAcceptanceTests.SuiteSlimTests.SlimSymbols.NamingConvention | ||||||||||
* | ||||||||||
* @param value value to check. | ||||||||||
* @return {@code true} if undefined (value is symbol name-like), {@code false} otherwise. | ||||||||||
*/ | ||||||||||
public boolean isUndefined(String value) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like an unreliable way to check for an undefined symbol. It will also match a string that happens to conform to the regular expression. Is there a better way to check whether a symbol is known in Slim? Maybe it can be checked by having a special Slim table... If this is a really important thing to check in your tests you could just check this regular expression using standard Slim regex matching and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a symbol in your tests that may or may not be assigned a value sounds like a code smell of your tests. If you worry a symbol may have been assigned a value in a previous test in a suite, just ensure you assign a known (empty, or otherwise not occurring value) in your SetUp. |
||||||||||
boolean result = false; | ||||||||||
if (getMatcher("\\$[a-zA-Z][a-zA-Z0-9_]*", value).matches()) { | ||||||||||
result = true; | ||||||||||
} | ||||||||||
return result; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Checks if a value is empty or has a value that meets the symbol naming convention ('$xyz'). | ||||||||||
* The latter indicates an undefined FitNesse symbol. | ||||||||||
* | ||||||||||
* @param value value to check. | ||||||||||
* @return {@code true} if empty or symbol name-like, {@code false} otherwise. | ||||||||||
*/ | ||||||||||
public boolean isEmptyOrUndefined(String value) { | ||||||||||
boolean result = false; | ||||||||||
if (isEmpty(value) || isUndefined(value)) { | ||||||||||
result = true; | ||||||||||
} | ||||||||||
return result; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* <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> | ||||||||||
|
@@ -54,7 +110,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> | ||||||||||
|
@@ -103,6 +159,19 @@ public String convertToLowerCase(String value) { | |||||||||
return result; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Capitalises the first character of a string. | ||||||||||
* @param value value to capitalise. | ||||||||||
* @return capitalised value. | ||||||||||
*/ | ||||||||||
public String capitalise (String value) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
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. | ||||||||||
|
@@ -205,4 +274,11 @@ public String convertLineEndingsToWindows(String input) { | |||||||||
public String convertLineEndingsToUnix(String input) { | ||||||||||
return getEnvironment().getLineEndingHelper().convertEndingsTo(input, LineEndingHelper.UNIX_LINE_ENDING); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Returns a null value. | ||||||||||
* | ||||||||||
* @return null value. | ||||||||||
*/ | ||||||||||
public String setNullValue() { return null;} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you use this method in your tests? Is there added value (over just assigning an empty string)? |
||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this really add value on top of a regular Slim regex check (possibly wrapped in a scenario)?