Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions src/main/java/scripteditor/AdvancedTrim.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@
package scripteditor;

/**
*
* @author Administrator
* Utility class for trimming Strings.
*/
public class AdvancedTrim {

public static String Trim(String temp) {
/**
* Returns a trimmed copy of a String containing (potentially among other characters) zero or
* more sequences of one or more space characters, such that those sequences instead each
* have exactly one space character.
*
* Returns unchanged copies of Strings containing no sequences of multiple space characters.
*
* @param temp non-null String
* @return a copy of temp, except trimming sequences of multiple spaces down to single spaces.
* @throws NullPointerException if temp is null
*/
public static String trim(String temp) {
String ret = "";
int i = 0;
while (i < temp.length()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/scripteditor/ImageNamingQuiz.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void Main(boolean showPrompt) {
break;
}
String completeAnswer = mSessionInfo.mImageCollection.getImageName();
completeAnswer = AdvancedTrim.Trim(completeAnswer);
completeAnswer = AdvancedTrim.trim(completeAnswer);
user_response = dlgQR.getResponse().trim();
actual_answer = getParsedName(completeAnswer.toLowerCase().trim());

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/scripteditor/ImageNamingQuiz2.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ private void test()
else{
tempPart = mSessionInfo.mImageCollection.getImageName().toLowerCase().trim();

String ans=AdvancedTrim.Trim(mSessionInfo.mImageCollection.getImageName());
String ans=AdvancedTrim.trim(mSessionInfo.mImageCollection.getImageName());

String answer=getParsedName(ans);

tempPart = AdvancedTrim.Trim(tempPart);
tempPart = AdvancedTrim.trim(tempPart);
//String completeAnswer = tempPart;//Commented by preethy on 11-04-2012
String completeAnswer = mSessionInfo.mImageCollection.getImageName();//Added by preethy on 11-04-2012
actual_answer = getParsedName(completeAnswer.toLowerCase().trim());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/scripteditor/ImageNamingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void RunTest(){
{
tempPart = mSessionInfo.mImageCollection.getImageName().toLowerCase().trim();

tempPart = AdvancedTrim.Trim(tempPart);
tempPart = AdvancedTrim.trim(tempPart);
// String completeAnswer = tempPart;//Commented by preethy on 11-04-2012
String completeAnswer = mSessionInfo.mImageCollection.getImageName();//Added by preethy on 11-04-2012
tempPart = getParsedName(tempPart);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/scripteditor/ImageNamingTest2.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void test()
{

tempPart = mSessionInfo.mImageCollection.getImageName().toLowerCase().trim();
tempPart = AdvancedTrim.Trim(tempPart);
tempPart = AdvancedTrim.trim(tempPart);
String completeAnswer = tempPart;
tempPart = getParsedName(tempPart);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/scripteditor/ImageNamingTestScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void RunScript(){
}
user_response = dlgQR.getResponse().trim();
tempPart = mSessionInfo.mImageCollection.getImageName().toLowerCase().trim();
tempPart = AdvancedTrim.Trim(tempPart);
tempPart = AdvancedTrim.trim(tempPart);
String completeAnswer = tempPart;
tempPart = getParsedName(tempPart);

Expand Down
81 changes: 81 additions & 0 deletions src/test/java/scripteditor/AdvancedTrimTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Licensed to Apereo under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Apereo licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at the following location:
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package scripteditor;

import junit.framework.TestCase;

/**
* This test case documents the behavior of AdvancedTrim.trim() as discovered.
*/
public class AdvancedTrimTest extends TestCase {

/**
* Test that trim() returns alphanumerics unchanged.
*/
public void testTrimIsANoOpOnAlphanumerics() {

final String alphanumeric = "abcABC123";

assertEquals(alphanumeric, AdvancedTrim.trim(alphanumeric));

}

/**
* Test that trim() trims a String with multiple trailing space characters down to one
* trailing space character.
*/
public void testTrimsToOneTrailingWhitespace() {

final String severalSpacesTrail = "whitespace-follows ";
final String justOneSpaceTrails = "whitespace-follows ";

assertEquals(justOneSpaceTrails, AdvancedTrim.trim(severalSpacesTrail));

}

/**
* Test that trim() trims a String with multiple leading space characters down to one leading
* space character.
*/
public void testTrimsToOneLeadingWhitespace() {

final String severalSpacesLead = " whitespace-led";
final String justOneSpaceLeads = " whitespace-led";

assertEquals(justOneSpaceLeads, AdvancedTrim.trim(severalSpacesLead));
}

/**
* Test that trim() trims a String containing multiple sequences of multiple space characters
* down to one space character in place of each such sequence.
*/
public void testTrimsToOneEmbeddedWhitespaceSequences() {

final String severalSequencesOfSeveralSpacesEmbedded =
"unit testing is good for the soul";

final String onlyIsolatedSpacesRemain =
"unit testing is good for the soul";

assertEquals(onlyIsolatedSpacesRemain,
AdvancedTrim.trim(severalSequencesOfSeveralSpacesEmbedded));
}

}