Repository: james-project Updated Branches: refs/heads/master def919909 -> 52153c42f
JAMES-1732 Introducing the problem Expected behaviour: Configure A Configure B configured But getting: Configure B java.lang.NullPointerException Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0978270d Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0978270d Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0978270d Branch: refs/heads/master Commit: 0978270d57a46016dc141430dac25801fbd34c68 Parents: def9199 Author: Antoine Duprat <adup...@linagora.com> Authored: Tue May 3 10:36:26 2016 +0200 Committer: Antoine Duprat <antdup...@gmail.com> Committed: Fri May 13 16:20:58 2016 +0200 ---------------------------------------------------------------------- .../src/test/java/org/apache/james/A.java | 48 ++++++++++++ .../src/test/java/org/apache/james/B.java | 46 +++++++++++ .../src/test/java/org/apache/james/C.java | 24 ++++++ .../org/apache/james/MemoryJamesServerTest.java | 3 +- .../test/java/org/apache/james/TestModule.java | 81 ++++++++++++++++++++ 5 files changed, 201 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/0978270d/server/container/guice/memory-guice/src/test/java/org/apache/james/A.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/A.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/A.java new file mode 100644 index 0000000..d234d92 --- /dev/null +++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/A.java @@ -0,0 +1,48 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james; + +import javax.inject.Inject; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.james.lifecycle.api.Configurable; + +public class A implements Configurable { + + @SuppressWarnings("unused") + private final C c; + private String domain; + + @Inject + private A(C c) { + this.c = c; + } + + @Override + public void configure(HierarchicalConfiguration config) throws ConfigurationException { + System.out.println("Configure A"); + domain = "configured"; + } + + public String getDomain() { + return domain.toLowerCase(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/0978270d/server/container/guice/memory-guice/src/test/java/org/apache/james/B.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/B.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/B.java new file mode 100644 index 0000000..2576d43 --- /dev/null +++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/B.java @@ -0,0 +1,46 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james; + +import javax.inject.Inject; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.james.lifecycle.api.Configurable; + +public class B implements Configurable { + + private final A a; + @SuppressWarnings("unused") + private final C c; + + @Inject + private B(A a, C c) { + this.a = a; + this.c = c; + } + + @Override + public void configure(HierarchicalConfiguration config) throws ConfigurationException { + System.out.println("Configure B"); + System.out.println(a.getDomain()); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/0978270d/server/container/guice/memory-guice/src/test/java/org/apache/james/C.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/C.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/C.java new file mode 100644 index 0000000..c6f20df --- /dev/null +++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/C.java @@ -0,0 +1,24 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james; + +public class C { + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/0978270d/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java index 2926711..3ebd55d 100644 --- a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java +++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java @@ -38,7 +38,8 @@ public class MemoryJamesServerTest extends AbstractJamesServerTest<InMemoryId> { return new GuiceJamesServer<>(new TypeLiteral<InMemoryId>(){}) .combineWith(MemoryJamesServerMain.inMemoryServerModule) .overrideWith(new TestFilesystemModule(temporaryFolder), - new TestJMAPServerModule(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT)); + new TestJMAPServerModule(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT), + new TestModule()); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/0978270d/server/container/guice/memory-guice/src/test/java/org/apache/james/TestModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/TestModule.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/TestModule.java new file mode 100644 index 0000000..1a8f4a8 --- /dev/null +++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/TestModule.java @@ -0,0 +1,81 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james; + +import javax.inject.Inject; + +import org.apache.james.utils.ConfigurationPerformer; + +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; +import com.google.inject.multibindings.Multibinder; + +public class TestModule extends AbstractModule { + + @Override + protected void configure() { + bind(B.class).in(Scopes.SINGLETON); + bind(A.class).in(Scopes.SINGLETON); + bind(C.class).in(Scopes.SINGLETON); + + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(BConfigurationPerformer.class); + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(AConfigurationPerformer.class); + } + + public static class AConfigurationPerformer implements ConfigurationPerformer<A> { + + private A a; + + @Inject + private AConfigurationPerformer(A a) { + this.a = a; + } + + @Override + public void initModule() throws Exception { + a.configure(null); + } + + @Override + public Class<A> forClass() { + return A.class; + } + } + + public static class BConfigurationPerformer implements ConfigurationPerformer<B> { + + private B b; + + @Inject + private BConfigurationPerformer(B b) { + this.b = b; + } + + @Override + public void initModule() throws Exception { + b.configure(null); + } + + @Override + public Class<B> forClass() { + return B.class; + } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org