Commits

Sam Adams  committed 05019dc

Simplifying configuration injection

  • Participants
  • Parent commits 5cda004

Comments (0)

Files changed (2)

File crystallography-test-harness/src/test/java/net/chempound/crystal/CrystalIntegrationTest.java

 package net.chempound.crystal;
 
-import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.Module;
 import com.hp.hpl.jena.rdf.model.Statement;
 import com.hp.hpl.jena.xmloutput.RDFXMLWriterI;
 import com.hp.hpl.jena.xmloutput.impl.Abbreviated;
+import net.chempound.ChempoundConfigurationModule;
 import net.chempound.DefaultChempoundModule;
 import net.chempound.chemistry.ImageGenerator;
 import net.chempound.chemistry.InChIGenerator;
-import net.chempound.config.BaseUri;
 import net.chempound.config.ChempoundConfiguration;
 import net.chempound.config.DefaultChempoundConfiguration;
 import net.chempound.content.DepositRequest;
         workspace = createWorkspace();
 
         Injector injector = Guice.createInjector(
-                createConfigurationModule(),
+                new ChempoundConfigurationModule(initConfiguration()),
                 new DefaultChempoundModule(),
                 new DefaultChempoundWebModule(),
                 new CrystallographyModule()
         return workspace;
     }
 
-    protected Module createConfigurationModule() {
-        return new AbstractModule() {
-            @Override
-            protected void configure() {
-                try {
-                    URI uri = URI.create("http://localhost:8714/");
-                    ChempoundConfiguration config = DefaultChempoundConfiguration.load(uri, workspace);
-                    bind(ChempoundConfiguration.class).toInstance(config);
-                    bind(URI.class).annotatedWith(BaseUri.class).toInstance(uri);
-                } catch (IOException e) {
-                    throw new RuntimeException(e);
-                }
-            }
-        };
+    protected ChempoundConfiguration initConfiguration() throws IOException {
+        URI uri = URI.create("http://localhost:8714/");
+        return DefaultChempoundConfiguration.load(uri, workspace);
     }
 
 

File crystallography-test-harness/src/test/java/net/chempound/crystal/CrystalSearchIntegrationTest.java

 package net.chempound.crystal;
 
-import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.Module;
+import net.chempound.ChempoundConfigurationModule;
 import net.chempound.DefaultChempoundModule;
 import net.chempound.chemistry.ImageGenerator;
 import net.chempound.chemistry.InChIGenerator;
 import net.chempound.client.SwordUtil;
-import net.chempound.config.BaseUri;
 import net.chempound.config.ChempoundConfiguration;
 import net.chempound.config.DefaultChempoundConfiguration;
 import net.chempound.content.DepositRequest;
         workspace = createWorkspace();
 
         Injector injector = Guice.createInjector(
-                createConfigurationModule(),
+                new ChempoundConfigurationModule(initConfiguration()),
                 new DefaultChempoundModule(),
                 new DefaultChempoundWebModule(),
                 new CrystallographyModule()
         return workspace;
     }
 
-    protected static Module createConfigurationModule() {
-        return new AbstractModule() {
-            @Override
-            protected void configure() {
-                try {
-                    URI uri = URI.create("http://localhost:8715/");
-                    ChempoundConfiguration config = DefaultChempoundConfiguration.load(uri, workspace);
-                    bind(ChempoundConfiguration.class).toInstance(config);
-                    bind(URI.class).annotatedWith(BaseUri.class).toInstance(uri);
-                } catch (IOException e) {
-                    throw new RuntimeException(e);
-                }
-            }
-        };
+    protected static ChempoundConfiguration initConfiguration() throws IOException {
+        URI uri = URI.create("http://localhost:8715/");
+        return DefaultChempoundConfiguration.load(uri, workspace);
     }