Make SearchPattern test case more readable

* fix typos and grammar
* ending pattern with " " or "<" should have the same results, therefore
test these in the same way in order to avoid confusion
* fix assertEquals() parameters order
* make identifiers more self-explaining

Signed-off-by: Petr Bodnar <p.bodnar@centrum.cz>
Change-Id: Id6605422b939f201e8a4fe7852e1bf725e0dd8dd
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/192602
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Mickael Istria <mistria@redhat.com>
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/SearchPatternAuto.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/SearchPatternAuto.java
index 391cab5..71da081 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/SearchPatternAuto.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dialogs/SearchPatternAuto.java
@@ -26,18 +26,20 @@
 import org.junit.Test;
 
 /**
- * Test case for tests SearchPattern match functionality
+ * Tests of the SearchPattern's match functionality.
  *
  * @since 3.3
- *
  */
 public class SearchPatternAuto {
 
+	/**
+	 * Items to be filtered.
+	 */
 	private static List<String> resources = new ArrayList<>();
 
 	static {
-		generateRescourcesTestCases('A', 'C', 8, "");
-		generateRescourcesTestCases('A', 'C', 4, "");
+		generateResourcesTestCases('A', 'C', 8, "");
+		generateResourcesTestCases('A', 'C', 4, "");
 	}
 
 	/**
@@ -45,44 +47,39 @@
 	 *
 	 * @param startChar
 	 * @param endChar
-	 * @param lenght
+	 * @param length
 	 * @param resource
 	 */
-	private static void generateRescourcesTestCases(char startChar, char endChar, int lenght, String resource){
+	private static void generateResourcesTestCases(char startChar, char endChar, int length, String resource) {
 		for (char ch = startChar; ch <= endChar; ch++) {
 			String res = resource + ch;
-			if (lenght == res.length()) {
+			if (length == res.length()) {
 				resources.add(res);
 			} else if ((res.trim().length() % 2) == 0) {
-				generateRescourcesTestCases(Character.toUpperCase((char)(startChar + 1)), Character.toUpperCase((char)(endChar + 1)), lenght, res);
+				generateResourcesTestCases(Character.toUpperCase((char)(startChar + 1)), Character.toUpperCase((char)(endChar + 1)), length, res);
 			} else {
-				generateRescourcesTestCases(Character.toLowerCase((char)(startChar + 1)), Character.toLowerCase((char)(endChar + 1)), lenght, res);
+				generateResourcesTestCases(Character.toLowerCase((char)(startChar + 1)), Character.toLowerCase((char)(endChar + 1)), length, res);
 			}
 		}
 	}
 
 	/**
-	 * Tests exact match functionality. If we camelCase rule is enable, Pattern should starts with lowerCase character.
+	 * Tests exact match functionality.
+	 * If camelCase rule is enabled, Pattern should start with lowerCase character.
 	 * Result for "abcd " pattern should be similar to regexp pattern "abcd" with case insensitive.
 	 */
 	@Test
-	public void testExactMatch1() {
+	public void testExactMatch() {
 		Pattern pattern = Pattern.compile("abcd", Pattern.CASE_INSENSITIVE);
 		assertMatches("abcd ", SearchPattern.RULE_EXACT_MATCH, pattern);
+		// alternative ending character:
+		assertMatches("abcd<", SearchPattern.RULE_EXACT_MATCH, pattern);
 	}
 
-	/**
-	 * Tests exact match functionality. If we camelCase rule is enable, Pattern should starts with lowerCase character.
-	 * Result for "abcdefgh&lt;" pattern should be similar to regexp pattern "abcdefgh" with case insensitive.
-	 */
-	@Test
-	public void testExactMatch2() {
-		Pattern pattern = Pattern.compile("abcdefgh", Pattern.CASE_INSENSITIVE);
-		assertMatches("abcdefgh<", SearchPattern.RULE_EXACT_MATCH, pattern);
-	}
 
 	/**
-	 * Tests prefix match functionality. If we camelCase rule is enable, Pattern should starts with lowerCase character.
+	 * Tests prefix match functionality.
+	 * If camelCase rule is enabled, Pattern should start with lowerCase character.
 	 * Result for "ab" pattern should be similar to regexp pattern "ab.*" with case insensitive.
 	 */
 	@Test
@@ -93,32 +90,34 @@
 
 	/**
 	 * Tests pattern match functionality. It's similar to regexp patterns.
-	 * Result for "**cDe" pattern should be similar to regexp pattern ".*cde.*" with case insensitive.
+	 * Result for "*cDe" pattern should be similar to regexp pattern ".*cde.*" with case insensitive.
 	 */
 	@Test
 	public void testPatternMatch1() {
 		Pattern pattern = Pattern.compile(".*cde.*", Pattern.CASE_INSENSITIVE);
+		assertMatches("*cDe", SearchPattern.RULE_PATTERN_MATCH, pattern);
+		// 1 or more consecutive '*' has to be the same as 1 '*'
 		assertMatches("**cDe", SearchPattern.RULE_PATTERN_MATCH, pattern);
 	}
 
 	/**
 	 * Tests pattern match functionality. It's similar to regexp patterns.
-	 * Result for "**c*e*i" pattern should be similar to regexp pattern ".*c.*e.*i.*" with case insensitive.
+	 * Result for "*c*e*i" pattern should be similar to regexp pattern ".*c.*e.*i.*" with case insensitive.
 	 */
 	@Test
 	public void testPatternMatch2() {
 		Pattern pattern = Pattern.compile(".*c.*e.*i.*", Pattern.CASE_INSENSITIVE);
-		assertMatches("**c*e*i", SearchPattern.RULE_PATTERN_MATCH, pattern);
+		assertMatches("*c*e*i", SearchPattern.RULE_PATTERN_MATCH, pattern);
 	}
 
 	/**
 	 * Tests camelCase match functionality.
-	 * Every string starts with upperCase characters should be recognize as camelCase pattern match rule.
-	 * Result for "CD" SearchPattern should be similar to regexp pattern "C[^A-Z]*D.*" or "CD.*"
-	 * If pattern contains only upperCase characters result contains all prefix match elements.
+	 * Every string starting with an upperCase character should be recognized as camelCase pattern match rule.
+	 * Result for "CD" SearchPattern should be similar to regexp pattern "C[^A-Z]*D.*".
+	 * If pattern contains only upperCase characters, result also contains all prefix match elements.
 	 */
 	@Test
-	public void testCamelCaseMatch1() {
+	public void testCamelCaseMatch() {
 		Pattern pattern = Pattern.compile("C[^A-Z]*D.*");
 		Pattern pattern2 = Pattern.compile("CD.*", Pattern.CASE_INSENSITIVE);
 		assertMatches("CD", SearchPattern.RULE_CAMELCASE_MATCH, pattern, pattern2);
@@ -126,29 +125,20 @@
 
 	/**
 	 * Tests camelCase match functionality.
-	 * Every string starts with upperCase characters should be recognize as camelCase pattern match rule.
-	 * Result for "AbCd " SearchPattern should be similar to regexp pattern "C[^A-Z]*D.*" or "CD.*"
+	 * Every string starting with an upperCase character should be recognized as camelCase pattern match rule.
+	 * Result for "AbCd " SearchPattern should be similar to regexp pattern "Ab[^A-Z]*Cd[^A-Z]*".
 	 */
 	@Test
-	public void testCamelCaseMatch2() {
+	public void testCamelCaseForcedEndMatch() {
 		Pattern pattern = Pattern.compile("Ab[^A-Z]*Cd[^A-Z]*");
 		assertMatches("AbCd ", SearchPattern.RULE_CAMELCASE_MATCH, pattern);
-	}
-
-	/**
-	 * Tests camelCase match functionality.
-	 * Every string starts with upperCase characters should be recognize as camelCase pattern match rule.
-	 * Result for "AbCdE&lt;" SearchPattern should be similar to regexp pattern "Ab[^A-Z]*Cd[^A-Z]*E[^A-Z]*"
-	 */
-	@Test
-	public void testCamelCaseMatch3() {
-		Pattern pattern = Pattern.compile("Ab[^A-Z]*Cd[^A-Z]*E[^A-Z]*");
-		assertMatches("AbCdE<", SearchPattern.RULE_CAMELCASE_MATCH, pattern);
+		// alternative ending character:
+		assertMatches("AbCd<", SearchPattern.RULE_CAMELCASE_MATCH, pattern);
 	}
 
 	/**
 	 * Tests blank match functionality.
-	 * Blank string should be recognize as blank pattern match rule.
+	 * Blank string should be recognized as a blank pattern match rule.
 	 * It should match with all resources.
 	 * Result for SearchPattern should be similar to regexp pattern ".*"
 	 */
@@ -158,28 +148,29 @@
 		assertMatches("", SearchPattern.RULE_BLANK_MATCH, pattern);
 	}
 
-	private void assertMatches(String patternText, int searchPattern, Pattern... patterns) {
+	private void assertMatches(String patternText, int expectedMatchRule, Pattern... matchingPatterns) {
 		SearchPattern patternMatcher = new SearchPattern();
 		patternMatcher.setPattern(patternText);
-		assertEquals(patternMatcher.getMatchRule(), searchPattern);
+		assertEquals(expectedMatchRule, patternMatcher.getMatchRule());
 		for (String res : resources) {
-			boolean anyMatches = anyMatches(res, patterns);
+			boolean anyMatches = anyMatches(res, matchingPatterns);
 			boolean patternMatches = patternMatcher.matches(res);
 			if (patternMatches) {
-				assertTrue("Pattern '" + patternText + "' matches '" + res + "' but other patterns don't.", anyMatches);
+				assertTrue("Pattern '" + patternText + "' matches '" + res + "', but it shouldn't.", anyMatches);
 			} else {
-				assertFalse("Pattern '" + patternText + "' doesn't match '" + res + "' but other patterns do.",
+				assertFalse("Pattern '" + patternText + "' doesn't match '" + res + "', but it should.",
 						anyMatches);
 			}
 		}
 	}
 
 	private static boolean anyMatches(String res, Pattern... patterns) {
-		boolean result = false;
 		for (Pattern pattern : patterns) {
-			result |= pattern.matcher(res).matches();
+			if (pattern.matcher(res).matches()) {
+				return true;
+			}
 		}
-		return result;
+		return false;
 	}
 
 }