Adding unit tests.
diff --git a/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF
index e91d7d6..464e915 100644
--- a/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF
+++ b/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF
@@ -11,4 +11,5 @@
org.eclipse.xtext.junit;bundle-version="2.0.0",
org.eclipse.xtext.junit4;bundle-version="2.0.0",
org.eclipse.xtext.ui.junit;bundle-version="2.0.0",
- com.google.eclipse.protobuf.junit;bundle-version="1.0.0"
+ com.google.eclipse.protobuf.junit;bundle-version="1.0.0",
+ org.mockito;bundle-version="1.8.5"
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtocOutputParser_parseAndAddMarkerIfNecessary_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtocOutputParser_parseAndAddMarkerIfNecessary_Test.java
new file mode 100644
index 0000000..5a37962
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtocOutputParser_parseAndAddMarkerIfNecessary_Test.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.builder;
+
+import static org.mockito.Mockito.*;
+
+import org.eclipse.core.runtime.CoreException;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for <code>{@link ProtocOutputParser#parseAndAddMarkerIfNecessary(String, ProtocMarkerFactory)}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtocOutputParser_parseAndAddMarkerIfNecessary_Test {
+
+ private ProtocMarkerFactory markerFactory;
+ private ProtocOutputParser outputParser;
+
+ @Before public void setUp() {
+ markerFactory = mock(ProtocMarkerFactory.class);
+ outputParser = new ProtocOutputParser();
+ }
+
+ @Test public void should_not_create_IMarker_if_line_does_not_match_error_pattern() throws CoreException {
+ String line = "person.proto: File not found.";
+ outputParser.parseAndAddMarkerIfNecessary(line, markerFactory);
+ verifyZeroInteractions(markerFactory);
+ }
+
+ @Test public void should_attempt_to_create_IMarker_if_line_matches_error_pattern() throws CoreException {
+ String line = "test.proto:23:21: Expected field name";
+ outputParser.parseAndAddMarkerIfNecessary(line, markerFactory);
+ verify(markerFactory).createErrorIfNecessary("Expected field name", 23);
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
index fe1066b..2c62ee8 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
@@ -80,7 +80,6 @@
private void generateSingleProto(IFile source, String protocPath, TargetLanguage language, String outputFolderPath) {
String command = commandFactory.protocCommand(source, protocPath, language, outputFolderPath);
try {
- source.deleteMarkers(ProtocOutputParser.MARKER_ID, true, DEPTH_INFINITE);
Process process = Runtime.getRuntime().exec(command);
processStream(process.getErrorStream(), source);
process.destroy();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory.java
index f67be7c..f62fd06 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory.java
@@ -23,19 +23,20 @@
*/
class ProtocMarkerFactory {
- static final String MARKER_ID = "com.google.eclipse.protobuf.ui.protocMarker";
+ static final String PROTOC = "com.google.eclipse.protobuf.ui.protocMarker";
private final IFile file;
private final IMarker[] markers;
ProtocMarkerFactory(IFile file) throws CoreException {
this.file = file;
- markers = this.file.findMarkers(FAST_VALIDATION, true, DEPTH_INFINITE);
+ file.deleteMarkers(PROTOC, true, DEPTH_INFINITE);
+ markers = file.findMarkers(FAST_VALIDATION, true, DEPTH_INFINITE);
}
void createErrorIfNecessary(String description, int lineNumber) throws CoreException {
if (containsMarker(description, lineNumber)) return;
- IMarker marker = file.createMarker(MARKER_ID);
+ IMarker marker = file.createMarker(PROTOC);
marker.setAttribute(SEVERITY, SEVERITY_ERROR);
marker.setAttribute(MESSAGE, description);
marker.setAttribute(LINE_NUMBER, lineNumber);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocOutputParser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocOutputParser.java
index 8ce8bc5..f7ba1c6 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocOutputParser.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocOutputParser.java
@@ -22,8 +22,6 @@
*/
class ProtocOutputParser {
- static final String MARKER_ID = "com.google.eclipse.protobuf.ui.protocMarker";
-
/*
* (.*):(\\d+):(\\d+):\\s*(.*)
* --1- ---2-- ---3-- -*- --4-