@@ -0,0 +1,2980 @@
+/**%0A *  Copyright 2009 Martin Traverso%0A *%0A *  Licensed under the Apache License, Version 2.0 (the %22License%22);%0A *  you may not use this file except in compliance with the License.%0A *  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A *  Unless required by applicable law or agreed to in writing, software%0A *  distributed under the License is distributed on an %22AS IS%22 BASIS,%0A *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A *  See the License for the specific language governing permissions and%0A *  limitations under the License.%0A */%0Apackage org.weakref.jmx.guice;%0A%0Aimport javax.management.MBeanServer;%0Aimport javax.management.ObjectName;%0A%0Aimport org.testng.Assert;%0Aimport org.testng.annotations.Test;%0Aimport org.weakref.jmx.Managed;%0Aimport org.weakref.jmx.testing.TestingMBeanServer;%0A%0Aimport com.google.inject.AbstractModule;%0Aimport com.google.inject.Guice;%0Aimport com.google.inject.Injector;%0Aimport com.google.inject.Key;%0Aimport com.google.inject.Module;%0Aimport com.google.inject.Stage;%0Aimport com.google.inject.name.Named;%0Aimport com.google.inject.name.Names;%0A%0Apublic class TestModuleSubclassing%0A%7B%0A    @Test%0A    public void testSubclassing()%0A        throws Exception%0A    %7B%0A        final Named name1 = Names.named(%22bean1%22);%0A        final Named name2 = Names.named(%22bean2%22);%0A%0A        final TestingMBeanServer tms = new TestingMBeanServer();%0A%0A        final Module m1 = new MBeanModule() %7B%0A            @Override%0A            protected void configureMBeans() %7B%0A                export(Key.get(Bean.class, name1)).as(%22bean1:name=bean1%22);%0A            %7D%0A        %7D;%0A%0A        final Module m2 = new MBeanModule() %7B%0A            @Override%0A            protected void configureMBeans() %7B%0A                export(Key.get(Bean.class, name2)).as(%22bean2:name=bean2%22);%0A            %7D%0A        %7D;%0A%0A        Guice.createInjector(Stage.PRODUCTION,%0A                             m1,%0A                             m2,%0A                             new AbstractModule() %7B%0A                                 @Override%0A                                 public void configure() %7B%0A                                     bind(MBeanServer.class).toInstance(tms);%0A                                     bind(Bean.class).annotatedWith(name1).toInstance(new Bean(%22name1%22));%0A                                     bind(Bean.class).annotatedWith(name2).toInstance(new Bean(%22name2%22));%0A                                 %7D%0A                             %7D);%0A%0A        Assert.assertEquals(2, tms.getMBeanCount().intValue());%0A        Assert.assertNotNull(tms.getMBeanInfo(new ObjectName(%22bean1:name=bean1%22)));%0A        Assert.assertNotNull(tms.getMBeanInfo(new ObjectName(%22bean2:name=bean2%22)));%0A    %7D%0A%0A    public static final class Bean%0A    %7B%0A        private final String name;%0A%0A        Bean(final String name)%0A        %7B%0A            this.name = name;%0A        %7D%0A%0A        @Managed%0A        public String getName()%0A        %7B%0A            return name;%0A        %7D%0A    %7D;%0A%7D%0A%0A

add MBeanModule subclassing test that used to pass in 1.12