Adding common JUnit infrastructure.
diff --git a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/XtextRule.java b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/XtextRule.java
index 35c78f4..c33160c 100644
--- a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/XtextRule.java
+++ b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/XtextRule.java
@@ -22,7 +22,7 @@
import com.google.inject.Injector;
/**
- * Understands SOMETHING DUMMY.
+ * Xtext rule that performs basic configuration of an Xtext environment.
*
* @author alruiz@google.com (Alex Ruiz)
*/
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 308f6c5..9e92650 100644
--- a/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF
+++ b/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF
@@ -10,4 +10,5 @@
org.junit.source;bundle-version="4.8.1",
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"
+ org.eclipse.xtext.ui.junit;bundle-version="2.0.0",
+ com.google.eclipse.protobuf.junit;bundle-version="1.0.0"
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
index 0473781..43eb726 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
@@ -12,19 +12,13 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import java.io.InputStreamReader;
import java.util.List;
-import org.eclipse.xtext.parser.IParseResult;
-import org.eclipse.xtext.util.StringInputStream;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.*;
-import com.google.eclipse.protobuf.ProtobufStandaloneSetup;
-import com.google.eclipse.protobuf.parser.antlr.ProtobufParser;
+import com.google.eclipse.protobuf.junit.XtextRule;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
-import com.google.inject.Injector;
/**
* Tests for <code>{@link Literals#calculateIndexOf(Literal)}</code>.
@@ -33,25 +27,25 @@
*/
public class Literals_calculateIndexOf_Test {
- private Injector injector;
+ @Rule public XtextRule xtext = new XtextRule();
+
private Literals literals;
-
+
@Before public void setUp() {
- injector = new ProtobufStandaloneSetup().createInjectorAndDoEMFRegistration();
- literals = injector.getInstance(Literals.class);
+ literals = xtext.getInstanceOf(Literals.class);
}
-
+
@Test public void should_return_zero_for_first_and_only_literal() {
StringBuilder proto = new StringBuilder();
proto.append("enum PhoneType {");
proto.append(" MOBILE = 0; ");
proto.append("} ");
- Protobuf root = parse(proto.toString());
+ Protobuf root = xtext.parse(proto.toString());
Literal firstLiteral = allLiteralsInFirstEnum(root).get(0);
int index = literals.calculateIndexOf(firstLiteral);
assertThat(index, equalTo(0));
}
-
+
@Test public void should_return_max_index_value_plus_one_for_new_literal() {
StringBuilder proto = new StringBuilder();
proto.append("enum PhoneType {");
@@ -59,18 +53,12 @@
proto.append(" HOME = 1; ");
proto.append(" WORK = 2; ");
proto.append("} ");
- Protobuf root = parse(proto.toString());
+ Protobuf root = xtext.parse(proto.toString());
Literal lastLiteral = allLiteralsInFirstEnum(root).get(2);
int index = literals.calculateIndexOf(lastLiteral);
assertThat(index, equalTo(2));
}
- private Protobuf parse(String text) {
- ProtobufParser parser = injector.getInstance(ProtobufParser.class);
- IParseResult parseResult = parser.parse(new InputStreamReader(new StringInputStream(text)));
- return (Protobuf) parseResult.getRootASTElement();
- }
-
private List<Literal> allLiteralsInFirstEnum(Protobuf root) {
List<Enum> allEnums = getAllContentsOfType(root, Enum.class);
return allEnums.get(0).getLiterals();