Code cleanup. Added more tests.
diff --git a/com.google.eclipse.protobuf.integration.test/.classpath b/com.google.eclipse.protobuf.integration.test/.classpath
new file mode 100644
index 0000000..1013bd4
--- /dev/null
+++ b/com.google.eclipse.protobuf.integration.test/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/com.google.eclipse.protobuf.test"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/com.google.eclipse.protobuf.integration.test/.project b/com.google.eclipse.protobuf.integration.test/.project
new file mode 100644
index 0000000..8125cae
--- /dev/null
+++ b/com.google.eclipse.protobuf.integration.test/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>com.google.eclipse.protobuf.integration.test</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/com.google.eclipse.protobuf.integration.test/.settings/org.eclipse.jdt.core.prefs b/com.google.eclipse.protobuf.integration.test/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..63279bd
--- /dev/null
+++ b/com.google.eclipse.protobuf.integration.test/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Sat Oct 01 14:48:05 PDT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/com.google.eclipse.protobuf.integration.test/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.integration.test/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..1f4ef9b
--- /dev/null
+++ b/com.google.eclipse.protobuf.integration.test/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Integration tests for com.google.eclipse.protobuf
+Bundle-SymbolicName: com.google.eclipse.protobuf.integration.test
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: Google Inc.
+Fragment-Host: com.google.eclipse.protobuf.ui;bundle-version="1.0.9"
+Require-Bundle: org.junit;bundle-version="4.8.1",
+ org.eclipse.xtext.junit;bundle-version="2.0.0",
+ org.eclipse.xtext.junit4;bundle-version="2.0.0",
+ org.mockito;bundle-version="1.8.5",
+ org.eclipse.core.resources;bundle-version="3.7.100"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/com.google.eclipse.protobuf.integration.test/build.properties b/com.google.eclipse.protobuf.integration.test/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/com.google.eclipse.protobuf.integration.test/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_availableOptionsFor_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Descriptor_availableOptionsFor_Test.java
similarity index 82%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_availableOptionsFor_Test.java
rename to com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Descriptor_availableOptionsFor_Test.java
index 339a54d..99909ce 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/Descriptor_availableOptionsFor_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/Descriptor_availableOptionsFor_Test.java
@@ -9,6 +9,7 @@
 package com.google.eclipse.protobuf.scoping;
 
 import static com.google.eclipse.protobuf.junit.matchers.PropertyHasType.hasType;
+import static com.google.eclipse.protobuf.ui.Internals.injector;
 import static org.hamcrest.core.IsEqual.equalTo;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
@@ -18,7 +19,6 @@
 import org.eclipse.emf.ecore.EObject;
 import org.junit.*;
 
-import com.google.eclipse.protobuf.junit.core.XtextRule;
 import com.google.eclipse.protobuf.protobuf.*;
 
 /**
@@ -26,15 +26,13 @@
  *
  * @author alruiz@google.com (Alex Ruiz)
  */
-@Ignore("This test requires to be executed as a 'JUnit plug-in test'. I haven't found a way to register PlatformURLHandler with the JVM")
 public class Descriptor_availableOptionsFor_Test {
 
-  @Rule public XtextRule xtext = new XtextRule();
+  private static ProtoDescriptor descriptor;
 
-  private ProtoDescriptor descriptor;
-  
-  @Before public void setUp() {
-    descriptor = xtext.getInstanceOf(ProtoDescriptorProvider.class).primaryDescriptor();
+  @BeforeClass public static void setUpOnce() {
+    ProtoDescriptorProvider descriptorProvider = injector().getInstance(ProtoDescriptorProvider.class);
+    descriptor = descriptorProvider.primaryDescriptor();
   }
 
   @Test public void should_return_all_file_options() {
diff --git a/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
index 72b3f49..f9e6122 100644
--- a/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
+++ b/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@
 Bundle-Name: Tests for com.google.eclipse.protobuf
 Bundle-SymbolicName: com.google.eclipse.protobuf.test
 Bundle-Version: 1.0.0
-Bundle-Vendor: Google
+Bundle-Vendor: Google Inc.
 Fragment-Host: com.google.eclipse.protobuf;bundle-version="1.0.0"
 Require-Bundle: org.junit;bundle-version="4.8.1",
  org.eclipse.xtext.junit;bundle-version="2.0.0",
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 4b49046..ac83685 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
@@ -13,11 +13,10 @@
 import static org.eclipse.emf.ecore.util.EcoreUtil.resolveAll;
 import static org.eclipse.xtext.util.CancelIndicator.NullImpl;
 
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
-import com.google.eclipse.protobuf.protobuf.Protobuf;
-import com.google.inject.Injector;
+import java.io.*;
 
 import org.eclipse.emf.common.util.URI;
+import org.eclipse.xtext.ISetup;
 import org.eclipse.xtext.linking.lazy.LazyLinkingResource;
 import org.eclipse.xtext.nodemodel.INode;
 import org.eclipse.xtext.parser.IParseResult;
@@ -26,7 +25,9 @@
 import org.junit.rules.MethodRule;
 import org.junit.runners.model.*;
 
-import java.io.*;
+import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
+import com.google.eclipse.protobuf.protobuf.Protobuf;
+import com.google.inject.Injector;
 
 /**
  * Rule that performs configuration of a standalone Xtext environment.
@@ -35,8 +36,17 @@
  */
 public class XtextRule implements MethodRule {
 
+  private final ISetup setup;
   private Injector injector;
 
+  public XtextRule() {
+    this(new TestingStandaloneSetup());
+  }
+
+  public XtextRule(ISetup setup) {
+    this.setup = setup;
+  }
+
   public Statement apply(Statement base, FrameworkMethod method, Object target) {
     return new XtextStatement(base);
   }
@@ -55,7 +65,7 @@
     if (!parseResult.hasSyntaxErrors()) return (Protobuf) parseResult.getRootASTElement();
     StringBuilder builder = new StringBuilder();
     builder.append("Syntax errors:");
-    for (INode error : parseResult.getSyntaxErrors()) 
+    for (INode error : parseResult.getSyntaxErrors())
       builder.append(lineSeparator()).append("- ").append(error.getSyntaxErrorMessage());
     throw new IllegalStateException(builder.toString());
   }
@@ -99,7 +109,7 @@
     }
 
     private void setUpInjector() {
-      injector = new TestingStandaloneSetup().createInjectorAndDoEMFRegistration();
+      injector = setup.createInjectorAndDoEMFRegistration();
     }
   }
 }
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Closeables_closeQuietly_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Closeables_closeQuietly_Test.java
new file mode 100644
index 0000000..7f3c153
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/util/Closeables_closeQuietly_Test.java
@@ -0,0 +1,49 @@
+/*
+ * 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.util;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.*;
+
+import java.io.*;
+
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link Closeables#closeQuietly(Closeable)}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class Closeables_closeQuietly_Test {
+
+  private Closeable closeable;
+
+  @Before public void setUp() {
+    closeable = mock(Closeable.class);
+  }
+
+  @Test public void should_ignore_null_Closeable() {
+    boolean result = Closeables.closeQuietly(null);
+    assertThat(result, equalTo(false));
+  }
+
+  @Test public void should_close_Closeable() throws IOException {
+    boolean result = Closeables.closeQuietly(closeable);
+    verify(closeable).close();
+    assertThat(result, equalTo(true));
+  }
+
+  @Test public void should_ignore_exceptions_thrown_when_closing_Closeable() throws IOException {
+    doThrow(new RuntimeException()).when(closeable).close();
+    boolean result = Closeables.closeQuietly(closeable);
+    verify(closeable).close();
+    assertThat(result, equalTo(true));
+  }
+}
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 f28c3ab..37847c9 100644
--- a/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF
+++ b/com.google.eclipse.protobuf.ui.test/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@
 Bundle-Name: Tests for com.google.eclipse.protobuf.ui
 Bundle-SymbolicName: com.google.eclipse.protobuf.ui.test
 Bundle-Version: 1.0.0
-Bundle-Vendor: Google
+Bundle-Vendor: Google Inc.
 Fragment-Host: com.google.eclipse.protobuf.ui;bundle-version="1.0.0"
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Require-Bundle: org.junit;bundle-version="4.8.1",
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/Internals.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/Internals.java
new file mode 100644
index 0000000..452ca2d
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/Internals.java
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+import com.google.eclipse.protobuf.ui.internal.ProtobufActivator;
+import com.google.inject.Injector;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public final class Internals {
+
+  private static final String LANGUAGE_NAME = "com.google.eclipse.protobuf.Protobuf";
+
+  public static Injector injector() {
+    return ProtobufActivator.getInstance().getInjector(languageName());
+  }
+
+  public static String languageName() {
+    return LANGUAGE_NAME;
+  }
+
+  private Internals() {}
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidateOnActivation.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidateOnActivation.java
index f4df0b7..7fe4185 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidateOnActivation.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidateOnActivation.java
@@ -9,7 +9,8 @@
  */
 package com.google.eclipse.protobuf.ui.validation;
 
-import static com.google.eclipse.protobuf.ui.validation.Validation.*;
+import static com.google.eclipse.protobuf.ui.Internals.injector;
+import static com.google.eclipse.protobuf.ui.validation.Validation.validate;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.ui.*;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/Validation.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/Validation.java
index 39901c3..255e62f 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/Validation.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/Validation.java
@@ -9,6 +9,7 @@
 package com.google.eclipse.protobuf.ui.validation;
 
 import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.IMPORT__IMPORT_URI;
+import static com.google.eclipse.protobuf.ui.Internals.*;
 import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
 
 import java.util.List;
@@ -25,17 +26,13 @@
 
 import com.google.eclipse.protobuf.conversion.STRINGValueConverter;
 import com.google.eclipse.protobuf.protobuf.Import;
-import com.google.eclipse.protobuf.ui.internal.ProtobufActivator;
 import com.google.eclipse.protobuf.util.ModelNodes;
-import com.google.inject.Injector;
 
 /**
  * @author alruiz@google.com (Alex Ruiz)
  */
 final class Validation {
 
-  private static final String LANGUAGE_NAME = "com.google.eclipse.protobuf.Protobuf";
-
   static void validate(IEditorPart editor) {
     XtextEditor protoEditor = asProtoEditor(editor);
     if (protoEditor == null) return;
@@ -45,7 +42,7 @@
   private static XtextEditor asProtoEditor(IEditorPart editor) {
     XtextEditor xtextEditor = asXtextEditor(editor);
     if (xtextEditor == null) return null;
-    if (!LANGUAGE_NAME.equals(xtextEditor.getLanguageName())) return null;
+    if (!languageName().equals(xtextEditor.getLanguageName())) return null;
     return xtextEditor;
   }
 
@@ -101,9 +98,5 @@
     return injector().getInstance(ModelNodes.class);
   }
 
-  static Injector injector() {
-    return ProtobufActivator.getInstance().getInjector(LANGUAGE_NAME);
-  }
-
   private Validation() {}
 }
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 0009c7d..f7e70e8 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
@@ -11,14 +11,13 @@
 import static java.util.Collections.unmodifiableCollection;
 import static org.eclipse.xtext.util.Strings.isEmpty;
 
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.xtext.parser.IParser;
-
 import java.util.*;
 import java.util.Map.Entry;
 
+import org.eclipse.core.runtime.*;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.xtext.parser.IParser;
+
 import com.google.eclipse.protobuf.util.ModelNodes;
 import com.google.inject.*;
 
@@ -39,13 +38,14 @@
   private Map<String, URI> descriptorInfos;
   private Map<String, ProtoDescriptor> descriptors;
   private String primaryImportUri;
-  
+
   private final Object lock = new Object();
 
   public ProtoDescriptor primaryDescriptor() {
+    ensureProtoDescriptorsAreCreated();
     return descriptor(primaryImportUri);
   }
-  
+
   public ProtoDescriptor descriptor(String importUri) {
     ensureProtoDescriptorsAreCreated();
     return descriptors.get(importUri);
@@ -64,16 +64,16 @@
       }
     }
   }
-  
+
   public Collection<URI> allDescriptorLocations() {
     ensureProtoDescriptorInfosAreCreated();
     return unmodifiableCollection(descriptorInfos.values());
   }
-  
+
   public URI primaryDescriptorLocation() {
     return descriptorLocation(primaryImportUri);
   }
-  
+
   public URI descriptorLocation(String importUri) {
     ensureProtoDescriptorInfosAreCreated();
     return descriptorInfos.get(importUri);
@@ -88,12 +88,12 @@
       }
     }
   }
-  
+
   private static ProtoDescriptorInfo defaultDescriptorInfo() {
     URI location = URI.createURI("platform:/plugin/com.google.eclipse.protobuf/descriptor.proto");
     return new ProtoDescriptorInfo("google/protobuf/descriptor.proto", location);
   }
-  
+
   private ProtoDescriptorInfo additionalDescriptorInfo() {
     IConfigurationElement[] config = registry.getConfigurationElementsFor(EXTENSION_ID);
     if (config == null) return defaultDescriptorInfo();
@@ -103,7 +103,7 @@
     }
     return null;
   }
-  
+
   private static ProtoDescriptorInfo descriptorInfo(IConfigurationElement e) {
     String importUri = e.getAttribute("importUri");
     if (isEmpty(importUri)) return null;
@@ -121,13 +121,13 @@
        .append(path);
     return URI.createURI(uri.toString());
   }
-  
+
   private void add(ProtoDescriptorInfo descriptorInfo) {
     if (descriptorInfo == null) return;
     primaryImportUri = descriptorInfo.importUri;
     descriptorInfos.put(primaryImportUri, descriptorInfo.location);
   }
-  
+
   private static class ProtoDescriptorInfo {
     final String importUri;
     final URI location;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java
index 0e4d490..62f539d 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java
@@ -8,15 +8,15 @@
  */
 package com.google.eclipse.protobuf.util;
 
-import java.io.*;
+import java.io.Closeable;
 
 /**
  * Utility methods related to <code>{@link Closeable}</code>s.
- * 
+ *
  * @author alruiz@google.com (Alex Ruiz)
  */
 public class Closeables {
-  
+
   /**
    * Invokes {@code close()} on the given <code>{@link Closeable}</code>, ignoring any thrown exceptions.
    * @param c the given {@code Closeable}.
@@ -26,7 +26,7 @@
     if (c == null) return false;
     try {
       c.close();
-    } catch (IOException ignored) {}
+    } catch (Throwable ignored) {}
     return true;
   }