Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvladt2011-01-25 00:28:27 +0000
committervladt2011-01-25 00:28:27 +0000
commit31afc6f29908721f06c564c4e10785193ba2b09f (patch)
tree6dad5274380e9e48bfb4ed535980bf6537f9c057
parent98db1ee036cf59ae6136c49013e8114e13bd0a4c (diff)
downloadm2e-core-31afc6f29908721f06c564c4e10785193ba2b09f.tar.gz
m2e-core-31afc6f29908721f06c564c4e10785193ba2b09f.tar.xz
m2e-core-31afc6f29908721f06c564c4e10785193ba2b09f.zip
Simplified some unit tests
-rw-r--r--org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/WorkspaceHelpers.java51
1 files changed, 44 insertions, 7 deletions
diff --git a/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/WorkspaceHelpers.java b/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/WorkspaceHelpers.java
index 414dd690..8cfbdddd 100644
--- a/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/WorkspaceHelpers.java
+++ b/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/WorkspaceHelpers.java
@@ -188,11 +188,6 @@ public class WorkspaceHelpers {
Assert.assertEquals("Unexpected warning markers " + toString(markers), 0, markers.size());
}
- public static IMarker assertErrorMarker(String type, String message, Integer lineNumber, IProject project)
- throws Exception {
- return assertErrorMarker(type, message, lineNumber, project, "pom.xml");
- }
-
public static IMarker assertErrorMarker(String type, String message, Integer lineNumber, IProject project,
String resourceRelativePath) throws Exception {
List<IMarker> errorMarkers = WorkspaceHelpers.findErrorMarkers(project);
@@ -210,9 +205,51 @@ public class WorkspaceHelpers {
return assertErrorMarker(type, message, lineNumber, resourceRelativePath, errorMarkers.get(0));
}
- public static IMarker assertErrorMarker(String type, String message, Integer lineNumber, IMarker actual)
+ private static IMarker findMarker(String type, String message, Integer lineNumber, String resourceRelativePath,
+ List<IMarker> markers) throws Exception {
+ for(IMarker marker : markers) {
+ if(type != null && !type.equals(marker.getType())) {
+ continue;
+ }
+ if(!marker.getAttribute(IMarker.MESSAGE, "").startsWith(message)) {
+ continue;
+ }
+ if(lineNumber != null && !lineNumber.equals(marker.getAttribute(IMarker.LINE_NUMBER))) {
+ continue;
+ }
+ if(type != null && type.startsWith(IMavenConstants.MARKER_ID)) {
+ Assert.assertEquals("Marker not persistent:" + toString(marker), false, marker.getAttribute(IMarker.TRANSIENT));
+ }
+
+ if(resourceRelativePath == null) {
+ resourceRelativePath = "";
+ }
+ Assert.assertEquals("Marker not on the expected resource:" + toString(marker), resourceRelativePath, marker
+ .getResource().getProjectRelativePath().toString());
+
+ return marker;
+ }
+ return null;
+ }
+
+ public static IMarker assertErrorMarker(String type, String message, Integer lineNumber, IProject project)
+ throws Exception {
+ return assertMarker(type, IMarker.SEVERITY_ERROR, message, lineNumber, "pom.xml", project);
+ }
+
+ public static IMarker assertWarningMarker(String type, String message, Integer lineNumber, IProject project)
throws Exception {
- return assertErrorMarker(type, message, lineNumber, "pom.xml", actual);
+ return assertMarker(type, IMarker.SEVERITY_WARNING, message, lineNumber, "pom.xml", project);
+ }
+
+ public static IMarker assertMarker(String type, int severity, String message, Integer lineNumber,
+ String resourceRelativePath, IProject project) throws Exception {
+ List<IMarker> markers = findMarkers(project, severity);
+ IMarker marker = findMarker(type, message, lineNumber, resourceRelativePath, markers);
+ if(marker == null) {
+ Assert.fail("Marker not found. Found markers:" + toString(markers));
+ }
+ return marker;
}
public static IMarker assertErrorMarker(String type, String message, Integer lineNumber, String resourceRelativePath,

Back to the top