james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject [1/5] james-project git commit: MAILBOX-269 modernize unit tests of capabilities
Date Tue, 07 Jun 2016 06:51:57 GMT
Repository: james-project
Updated Branches:
  refs/heads/master f6cfad601 -> 81f7f3a4c


MAILBOX-269 modernize unit tests of capabilities


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/22bd669a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/22bd669a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/22bd669a

Branch: refs/heads/master
Commit: 22bd669a573a246847522ef0d123f5da440f3887
Parents: 7dc4243
Author: Matthieu Baechler <matthieu.baechler@linagora.com>
Authored: Tue May 31 18:42:59 2016 +0200
Committer: Matthieu Baechler <matthieu.baechler@linagora.com>
Committed: Tue Jun 7 08:50:57 2016 +0200

----------------------------------------------------------------------
 .../james/JamesCapabilitiesServerTest.java      | 20 +++++++++++++-------
 .../java/org/apache/james/GuiceJamesServer.java |  6 ++++--
 2 files changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/22bd669a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index 5451747..2e07a4f 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -29,6 +30,7 @@ import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
 import org.apache.james.modules.TestElasticSearchModule;
 import org.apache.james.modules.TestFilesystemModule;
 import org.apache.james.modules.TestJMAPServerModule;
+import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.RuleChain;
@@ -37,6 +39,7 @@ import org.junit.rules.TemporaryFolder;
 import com.datastax.driver.core.Session;
 import com.google.common.collect.ImmutableList;
 import com.google.inject.AbstractModule;
+import com.google.inject.Module;
 import com.google.inject.Provides;
 import com.google.inject.Singleton;
 
@@ -49,17 +52,14 @@ public class JamesCapabilitiesServerTest {
     @Rule
     public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
 
-    @Test(expected=IllegalArgumentException.class)
+    @Test
     public void startShouldFailWhenNoMoveCapability() throws Exception {
         MailboxManager mailboxManager = mock(MailboxManager.class);
         when(mailboxManager.getSupportedCapabilities())
             .thenReturn(ImmutableList.of(MailboxManager.Capabilities.Basic));
         server = createCassandraJamesServer(mailboxManager);
 
-        server.start();
-
-        // In case of non-failure
-        server.stop();
+        assertThatThrownBy(() -> server.start()).isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
@@ -70,21 +70,26 @@ public class JamesCapabilitiesServerTest {
         server = createCassandraJamesServer(mailboxManager);
 
         server.start();
+    }
 
+    @After
+    public void teardown() {
         server.stop();
     }
-
+    
     private GuiceJamesServer createCassandraJamesServer(final MailboxManager mailboxManager)
{
+        Module mockMailboxManager = (binder) -> binder.bind(MailboxManager.class).toInstance(mailboxManager);
+        
         return new GuiceJamesServer()
             .combineWith(CassandraJamesServerMain.cassandraServerModule)
             .overrideWith(new TestElasticSearchModule(embeddedElasticSearch),
                 new TestFilesystemModule(temporaryFolder),
                 new TestJMAPServerModule(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT),
+                mockMailboxManager,
                 new AbstractModule() {
 
                     @Override
                     protected void configure() {
-                        bind(MailboxManager.class).toInstance(mailboxManager);
                     }
 
                     @Provides
@@ -93,6 +98,7 @@ public class JamesCapabilitiesServerTest {
                         CassandraCluster cassandra = CassandraCluster.create(cassandraModule);
                         return cassandra.getConf();
                     }
+
                 });
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/22bd669a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
index c7c3121..1283147 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
@@ -68,14 +68,16 @@ public class GuiceJamesServer {
     
     public void start() throws Exception {
         Injector injector = Guice.createInjector(module);
-        injector.getInstance(ConfigurationsPerformer.class).initModules();
         preDestroy = injector.getInstance(Key.get(new TypeLiteral<Stager<PreDestroy>>()
{}));
+        injector.getInstance(ConfigurationsPerformer.class).initModules();
         serverProbe = injector.getInstance(GuiceServerProbe.class);
         jmapPort = injector.getInstance(JMAPServer.class).getPort();
     }
 
     public void stop() {
-        preDestroy.stage();
+        if (preDestroy != null) {
+            preDestroy.stage();
+        }
     }
 
     public ExtendedServerProbe serverProbe() {


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message