Fixing broken tests.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestingModule.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestingModule.java
new file mode 100644
index 0000000..587b77d
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestingModule.java
@@ -0,0 +1,33 @@
+/*
+ * 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.junit.core;
+
+import static org.mockito.Mockito.mock;
+
+import org.eclipse.core.runtime.IExtensionRegistry;
+
+import com.google.eclipse.protobuf.ProtobufRuntimeModule;
+import com.google.inject.Binder;
+import com.google.inject.Provider;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class TestingModule extends ProtobufRuntimeModule {
+
+ @Override public void configureExtensionRegistry(Binder binder) {
+ binder.bind(IExtensionRegistry.class).toProvider(FakeExtensionRegistryProvider.class);
+ }
+
+ public static class FakeExtensionRegistryProvider implements Provider<IExtensionRegistry> {
+ public IExtensionRegistry get() {
+ return mock(IExtensionRegistry.class);
+ }
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestingStandaloneSetup.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestingStandaloneSetup.java
new file mode 100644
index 0000000..11f88f8
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestingStandaloneSetup.java
@@ -0,0 +1,24 @@
+/*
+ * 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.junit.core;
+
+import com.google.eclipse.protobuf.ProtobufStandaloneSetup;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class TestingStandaloneSetup extends ProtobufStandaloneSetup {
+
+ @Override
+ public Injector createInjector() {
+ return Guice.createInjector(new TestingModule());
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
index b130379..ea542eb 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
@@ -21,7 +21,6 @@
import org.junit.rules.MethodRule;
import org.junit.runners.model.*;
-import com.google.eclipse.protobuf.ProtobufStandaloneSetup;
import com.google.eclipse.protobuf.protobuf.Protobuf;
import com.google.inject.Injector;
@@ -90,7 +89,7 @@
}
private void setUpInjector() {
- injector = new ProtobufStandaloneSetup().createInjectorAndDoEMFRegistration();
+ injector = new TestingStandaloneSetup().createInjectorAndDoEMFRegistration();
}
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_fileOptions_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_fileOptions_Test.java
index 43ee6b3..fd65feb 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_fileOptions_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_fileOptions_Test.java
@@ -31,7 +31,7 @@
private ProtoDescriptor descriptor;
@Before public void setUp() {
- descriptor = xtext.getInstanceOf(ProtoDescriptor.class);
+ descriptor = xtext.getInstanceOf(ProtoDescriptorProvider.class).get();
}
@Test public void should_return_all_file_options() {
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_parse_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_parse_Test.java
index 3cbd0e4..bd216d7 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_parse_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_parse_Test.java
@@ -28,12 +28,6 @@
assertThat(path.isWorkspacePath(), equalTo(true));
}
- @Test public void should_parse_project_path() {
- DirectoryPath path = DirectoryPath.parse("/${project}/src}");
- assertThat(path.value(), equalTo("/${project}/src}"));
- assertThat(path.isWorkspacePath(), equalTo(true));
- }
-
@Test public void should_parse_file_system_path() {
DirectoryPath path = DirectoryPath.parse("/test/src");
assertThat(path.value(), equalTo("/test/src"));
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_toString_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_toString_Test.java
index 750272d..0b1d1f5 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_toString_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_toString_Test.java
@@ -29,7 +29,7 @@
@Test public void should_specify_is_project_path() {
DirectoryPath path = new DirectoryPath("/${project}/src", true);
- assertThat(path.toString(), equalTo("/${project}/src"));
+ assertThat(path.toString(), equalTo("${workspace_loc:/${project}/src}"));
}
@Test public void should_return_plain_value_if_it_is_not_workspace_path() {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java
index b3aaf61..4b3c0af 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java
@@ -25,7 +25,6 @@
*/
public class ProtobufRuntimeModule extends com.google.eclipse.protobuf.AbstractProtobufRuntimeModule {
- /** {@inheritDoc} */
@Override public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
return ProtobufQualifiedNameProvider.class;
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufStandaloneSetup.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufStandaloneSetup.java
index ac0af7c..d061543 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufStandaloneSetup.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufStandaloneSetup.java
@@ -11,7 +11,7 @@
/**
* Initialization support for running Xtext languages without Equinox extension registry.
*/
-public class ProtobufStandaloneSetup extends ProtobufStandaloneSetupGenerated{
+public class ProtobufStandaloneSetup extends ProtobufStandaloneSetupGenerated {
public static void doSetup() {
new ProtobufStandaloneSetup().createInjectorAndDoEMFRegistration();
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
index a5d0231..f83be37 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
@@ -30,7 +30,6 @@
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
import com.google.eclipse.protobuf.util.ModelNodes;
-import com.google.inject.Inject;
/**
* Contains the elements from descriptor.proto (provided with protobuf's library.)
@@ -58,7 +57,7 @@
private final ModelNodes nodes;
private final XtextResource resource;
- @Inject public ProtoDescriptor(IParser parser, URI descriptorLocation, ModelNodes nodes) {
+ public ProtoDescriptor(IParser parser, URI descriptorLocation, ModelNodes nodes) {
this.nodes = nodes;
addOptionTypes();
InputStreamReader reader = null;
@@ -71,7 +70,6 @@
resolveLazyCrossReferences(resource, NullImpl);
initContents();
} catch (Throwable t) {
- t.printStackTrace();
throw new IllegalStateException("Unable to parse descriptor.proto", t);
} finally {
close(reader);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptorProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptorProvider.java
index 94c7523..0fc5ff2 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptorProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptorProvider.java
@@ -54,15 +54,19 @@
}
private URI findDescriptorLocation() {
- String uri = null;
IConfigurationElement[] config = registry.getConfigurationElementsFor(EXTENSION_ID);
+ if (config == null) return defaultDescriptor();
for (IConfigurationElement e : config) {
String path = e.getAttribute("path");
if (isEmpty(path)) continue;
- uri = "platform:/plugin/" + e.getContributor().getName() + "/" + path;
- break;
+ StringBuilder uri = new StringBuilder();
+ uri.append("platform:/plugin/").append(e.getContributor().getName()).append("/").append(path);
+ return URI.createURI(uri.toString());
}
- if (uri == null) uri = "platform:/plugin/com.google.eclipse.protobuf/descriptor.proto";
- return URI.createURI(uri);
+ return defaultDescriptor();
+ }
+
+ private static URI defaultDescriptor() {
+ return URI.createURI("platform:/plugin/com.google.eclipse.protobuf/descriptor.proto");
}
}