Skip to content
Snippets Groups Projects
Commit 94ea184e authored by kaloyane's avatar kaloyane
Browse files

minor: unit test clean-up

SVN: 19801
parent cde25fc9
No related branches found
No related tags found
No related merge requests found
...@@ -38,10 +38,10 @@ class PropertiesBatchEvaluationErrors ...@@ -38,10 +38,10 @@ class PropertiesBatchEvaluationErrors
* limitation on the number of ErrorDetails objects kept in memory. This guards us from * limitation on the number of ErrorDetails objects kept in memory. This guards us from
* scripts generating unique error messages for excessively large batches. * scripts generating unique error messages for excessively large batches.
*/ */
private static final int MAX_ERROR_DETAILS_KEPT = 10; static final int MAX_ERROR_DETAILS_KEPT = 10;
/** the maximum number of errors displayed to the user. */ /** the maximum number of errors displayed to the user. */
private static final int MAX_ERROR_IN_USER_MESSAGE = 2; static final int MAX_ERRORS_IN_USER_MESSAGE = 2;
private class ErrorDetail private class ErrorDetail
{ {
...@@ -118,7 +118,7 @@ class PropertiesBatchEvaluationErrors ...@@ -118,7 +118,7 @@ class PropertiesBatchEvaluationErrors
message.append(totalRowsNumber); message.append(totalRowsNumber);
message.append(" rows."); message.append(" rows.");
int numDisplayErrors = Math.min(errorDetails.size(), MAX_ERROR_IN_USER_MESSAGE); int numDisplayErrors = Math.min(errorDetails.size(), MAX_ERRORS_IN_USER_MESSAGE);
List<ErrorDetail> formatDetails = sortErrorDetailsByRow().subList(0, numDisplayErrors); List<ErrorDetail> formatDetails = sortErrorDetailsByRow().subList(0, numDisplayErrors);
for (ErrorDetail errDetail : formatDetails) for (ErrorDetail errDetail : formatDetails)
{ {
......
...@@ -16,12 +16,10 @@ ...@@ -16,12 +16,10 @@
package ch.systemsx.cisd.openbis.generic.server.business; package ch.systemsx.cisd.openbis.generic.server.business;
import static ch.systemsx.cisd.openbis.generic.server.business.PropertiesBatchEvaluationErrors.MAX_ERRORS_IN_USER_MESSAGE;
import static ch.systemsx.cisd.openbis.generic.server.business.PropertiesBatchEvaluationErrors.MAX_ERROR_DETAILS_KEPT; import static ch.systemsx.cisd.openbis.generic.server.business.PropertiesBatchEvaluationErrors.MAX_ERROR_DETAILS_KEPT;
import static ch.systemsx.cisd.openbis.generic.server.business.PropertiesBatchEvaluationErrors.MAX_ERROR_IN_USER_MESSAGE;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.testng.AssertJUnit; import org.testng.AssertJUnit;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -72,10 +70,11 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit ...@@ -72,10 +70,11 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit
String email = errors.constructErrorReportEmail(); String email = errors.constructErrorReportEmail();
// exactly one stack trace shown // exactly one stack trace shown
assertOccurences(ERROR_TEXT, 1, email); assertEquals(1, StringUtils.countMatches(email, ERROR_TEXT));
assertOccurences(
"100 rows including \\[1, 2, 3] have failed due to the property 'propcode' causing a malfuction", String pattern =
1, email); "100 rows including [1, 2, 3] have failed due to the property 'propcode' causing a malfuction";
assertEquals(1, StringUtils.countMatches(email, pattern));
} }
@Test @Test
...@@ -90,28 +89,13 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit ...@@ -90,28 +89,13 @@ public class PropertiesBatchEvaluationErrorsTest extends AssertJUnit
String errorMessage = errors.constructUserFailureMessage(); String errorMessage = errors.constructUserFailureMessage();
// not more than 3 messages shown to the user // not more than 3 messages shown to the user
assertOccurences(ERROR_TEXT, MAX_ERROR_IN_USER_MESSAGE, assertEquals(MAX_ERRORS_IN_USER_MESSAGE, StringUtils.countMatches(errorMessage, ERROR_TEXT));
errorMessage);
String email = errors.constructErrorReportEmail(); String email = errors.constructErrorReportEmail();
// only the first 10 stack traces are included // only the first 10 stack traces are included
assertOccurences(ERROR_TEXT, MAX_ERROR_DETAILS_KEPT, email); assertEquals(MAX_ERROR_DETAILS_KEPT, StringUtils.countMatches(email, ERROR_TEXT));
assertOccurences("Row 1 has failed due to the property 'propcode' causing a malfuction", 1, assertEquals(1, StringUtils.countMatches(email,
email); "Row 1 has failed due to the property 'propcode' causing a malfuction"));
}
private void assertOccurences(String pattern, int times, String string)
{
Pattern pat = Pattern.compile(pattern);
Matcher matcher = pat.matcher(string);
int actualCount = 0;
while (matcher.find())
{
actualCount++;
}
String errFormat =
String.format("Invalid number of occurences of '%s' in '%s'", pattern, string);
assertEquals(errFormat, times, actualCount);
} }
private PropertiesBatchEvaluationErrors createErrorsObject() private PropertiesBatchEvaluationErrors createErrorsObject()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment