Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrbrooks2010-09-21 14:38:52 -0400
committerRyan D. Brooks2010-09-21 14:38:52 -0400
commitfc19091da28ea99a661148e8ba677d6bb01dba10 (patch)
treef31879136a66ff62ab1c2ba082d7359ad0405542 /plugins
parent73a2f3612528f15ba50c82a46c85354cc2335e64 (diff)
downloadorg.eclipse.osee-fc19091da28ea99a661148e8ba677d6bb01dba10.tar.gz
org.eclipse.osee-fc19091da28ea99a661148e8ba677d6bb01dba10.tar.xz
org.eclipse.osee-fc19091da28ea99a661148e8ba677d6bb01dba10.zip
refinement: Create junit test TestStringFormatMessages and fix detected defects
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/merge/MergeImportManager.java4
-rw-r--r--plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VectorCastAdaCoverageImporter.java2
-rw-r--r--plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCache.java2
-rw-r--r--plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/FrameworkCoreTestSuite.java4
-rw-r--r--plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/exception/OseeCoreExceptionTest.java2
-rw-r--r--plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/exception/TestStringFormatMessages.java113
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ConflictStatus.java2
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ConflictType.java2
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/StorageState.java2
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/workflow/DefaultAttributeXWidgetProvider.java2
10 files changed, 125 insertions, 10 deletions
diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/merge/MergeImportManager.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/merge/MergeImportManager.java
index e17a53b0c2..08cbc75ed9 100644
--- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/merge/MergeImportManager.java
+++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/merge/MergeImportManager.java
@@ -215,8 +215,8 @@ public class MergeImportManager {
((CoverageItem) packageCoverage).setOrderNumber(((CoverageItem) importCoverage).getOrderNumber());
updateFileContents((CoverageItem) packageCoverage, (CoverageItem) importCoverage);
} else {
- rd.logError(String.format("[%s] doesn't support merge item [%s] (1)", mergeItem.getClass().getSimpleName(),
- MergeType.Add_With_Moves.toString(), mergeItem));
+ rd.logError(String.format("[%s] doesn't support merge type [%s] for item [%s] (1)",
+ mergeItem.getClass().getSimpleName(), MergeType.Add_With_Moves, mergeItem));
}
}
diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VectorCastAdaCoverageImporter.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VectorCastAdaCoverageImporter.java
index c15be2d7b1..df6fcf75fc 100644
--- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VectorCastAdaCoverageImporter.java
+++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VectorCastAdaCoverageImporter.java
@@ -172,7 +172,7 @@ public class VectorCastAdaCoverageImporter implements ICoverageImporter {
coverageItem.setName(m.group(1));
} else {
coverageImport.getLog().logError(
- String.format("Coverage line doesn't match \"n n <line>\" [%s]. " + sourceLine));
+ String.format("Coverage line doesn't match \"n n <line>\" [%s]. ", sourceLine));
continue;
}
if (vectorCastCoverageImportProvider.isResolveExceptionHandling() && lineData.getSecond()) {
diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCache.java
index 8a4a30a875..d7468cc490 100644
--- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCache.java
+++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/AbstractOseeCache.java
@@ -166,7 +166,7 @@ public abstract class AbstractOseeCache<T extends AbstractOseeType> implements I
// }
// }
if (cachedTypes.size() > 1) {
- throw new OseeStateException("Item [%s:%s] does not have a unique name. Matching types - ", type.getName(),
+ throw new OseeStateException("Item [%s:%s] does not have a unique name. Matching types [%s]", type.getName(),
type.getGuid(), itemsFound);
}
}
diff --git a/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/FrameworkCoreTestSuite.java b/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/FrameworkCoreTestSuite.java
index 7c319289d5..1f88c493df 100644
--- a/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/FrameworkCoreTestSuite.java
+++ b/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/FrameworkCoreTestSuite.java
@@ -20,9 +20,9 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
EnumsTestSuite.class,
+ ExceptionTestSuite.class,
InternalCoreTestSuite.class,
- UtilCoreTestSuite.class,
- ExceptionTestSuite.class})
+ UtilCoreTestSuite.class})
/**
* @author Roberto E. Escobar
*/
diff --git a/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/exception/OseeCoreExceptionTest.java b/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/exception/OseeCoreExceptionTest.java
index 0540c4e723..30cedabb10 100644
--- a/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/exception/OseeCoreExceptionTest.java
+++ b/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/exception/OseeCoreExceptionTest.java
@@ -15,6 +15,8 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.junit.Test;
/**
+ * Test Case for {@link OseeCoreException}
+ *
* @author Ryan D. Brooks
*/
public class OseeCoreExceptionTest {
diff --git a/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/exception/TestStringFormatMessages.java b/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/exception/TestStringFormatMessages.java
new file mode 100644
index 0000000000..2fa8a0768c
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.test/src/org/eclipse/osee/framework/core/test/exception/TestStringFormatMessages.java
@@ -0,0 +1,113 @@
+/*
+ * Created on Sep 20, 2010
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.core.test.exception;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.jdk.core.text.tool.Find;
+import org.eclipse.osee.framework.jdk.core.text.tool.FindResultsIterator;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.junit.Test;
+
+public class TestStringFormatMessages {
+ private static final String formatSuffix = "\\s*\\(\".*?%.*?\"(?<!\\\\\")[^;]+;";
+ private static final String throwPattern = "throw new\\s*\\w+" + formatSuffix;
+ private static final String formatPattern = "String.format" + formatSuffix;
+ private static final Pattern outerPattern = Pattern.compile("\"(.*?)\"(?<!\\\\\")([^;]+);");
+ private static final Pattern specifierPattern = Pattern.compile("%-?[\\d.]*(\\w)");
+
+ private FindResultsIterator getResultsIterator() {
+ List<String> patterns = new ArrayList<String>(2);
+ patterns.add(throwPattern);
+ patterns.add(formatPattern);
+
+ File rootSrcDir = new File("c:/UserData/git");
+ List<File> files = Lib.recursivelyListFiles(rootSrcDir, Pattern.compile(".+\\.java"));
+ Find app = new Find(patterns, files);
+ app.find(999999, true);
+ return app.getResults().iterator();
+ }
+
+ @Test
+ public void testFormatMessages() {
+ FindResultsIterator iterator = getResultsIterator();
+ while (iterator.hasNext()) {
+ Matcher matcher = outerPattern.matcher(iterator.currentRegion);
+ if (matcher.find()) {
+ examineArgs(matcher);
+ } else {
+ Assert.fail(iterator.currentRegion);
+ }
+ }
+ }
+
+ private void examineArgs(Matcher matcher) {
+ String formatMessage = matcher.group(1);
+ int argCount = countArguments(matcher.group(2));
+ Object[] args = new Object[argCount];
+
+ Matcher specifierMatcher = specifierPattern.matcher(formatMessage);
+ int index = 0;
+ while (specifierMatcher.find()) {
+ if (index >= argCount) {
+ Assert.fail(formatMessage);
+ }
+ String specifier = specifierMatcher.group(1);
+ if (specifier.equals("d")) {
+ args[index++] = 0;
+ } else if (specifier.equals("f")) {
+ args[index++] = 0.0f;
+ } else if (specifier.equalsIgnoreCase("s")) {
+ args[index++] = new Object();
+ } else if (specifier.equalsIgnoreCase("x")) {
+ args[index++] = Byte.valueOf((byte) 0);
+ } else if (specifier.equalsIgnoreCase("b")) {
+ args[index++] = true;
+ } else if (specifier.equalsIgnoreCase("c")) {
+ args[index++] = 'x';
+ } else if (specifier.equalsIgnoreCase("t")) {
+ args[index++] = new Date();
+ } else {
+ Assert.fail(String.format("[%s] has unknown format specifier [%s]", formatMessage, specifier));
+ }
+ }
+ if (argCount != index) {
+ Assert.assertEquals(formatMessage, index, argCount);
+ }
+
+ try {
+ String.format(formatMessage, args);
+ } catch (RuntimeException ex) {
+ Assert.fail(ex.toString());
+ }
+ }
+
+ private int countArguments(String argString) {
+ int argCount = 0;
+ int balance = 1;
+ char[] chars = argString.toCharArray();
+
+ for (int i = 0; i < chars.length; i++) {
+ char c = chars[i];
+ if (c == '(') {
+ balance++;
+ } else if (c == ')') {
+ balance--;
+ } else if (c == ',' && balance == 1) {
+ argCount++;
+ }
+ if (balance == 0) {
+ break;
+ }
+ }
+ return argCount;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ConflictStatus.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ConflictStatus.java
index c3ba4d2327..bec38db592 100644
--- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ConflictStatus.java
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ConflictStatus.java
@@ -46,7 +46,7 @@ public enum ConflictStatus {
return type;
}
}
- throw new OseeArgumentException("[%s] is not a valid ConflictStatus");
+ throw new OseeArgumentException("%d is not a valid ConflictStatus", value);
}
public boolean isConflict() {
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ConflictType.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ConflictType.java
index 917cdb65eb..8597fd8684 100644
--- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ConflictType.java
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ConflictType.java
@@ -37,6 +37,6 @@ public enum ConflictType {
return type;
}
}
- throw new OseeArgumentException("[%s] is not a valid ConflictType");
+ throw new OseeArgumentException("%d is not a valid ConflictType", value);
}
}
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/StorageState.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/StorageState.java
index 467079dc85..16ade79174 100644
--- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/StorageState.java
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/StorageState.java
@@ -39,6 +39,6 @@ public enum StorageState {
return type;
}
}
- throw new OseeArgumentException("[%s] is not a valid StorageState");
+ throw new OseeArgumentException("%d is not a valid StorageState", value);
}
}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/workflow/DefaultAttributeXWidgetProvider.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/workflow/DefaultAttributeXWidgetProvider.java
index e3dfe8b784..d91aea4c0e 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/workflow/DefaultAttributeXWidgetProvider.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/workflow/DefaultAttributeXWidgetProvider.java
@@ -63,7 +63,7 @@ public class DefaultAttributeXWidgetProvider implements IAttributeXWidgetProvide
xWidgetName = "XTextDam";
StringBuilder builder = new StringBuilder();
builder.append("Unable to determine base type for attribute type");
- builder.append(String.format("[%]", attributeType.getName()));
+ builder.append(String.format("[%s]", attributeType));
builder.append(Lib.exceptionToString(ex));
defaultData.setDefaultValue(builder.toString());
}

Back to the top