package com.maxifier.guice.mbean;

import org.testng.annotations.Test;

import static org.testng.Assert.assertTrue;

/**
 * Created by: Aleksey Didik
 * Date: 5/26/11
 * Time: 9:55 PM
 * <p/>
 * Copyright (c) 1999-2011 Maxifier Ltd. All Rights Reserved.
 * Code proprietary and confidential.
 * Use is subject to license terms.
 *
 * @author Aleksey Didik
 */
public class CGLIBMBeanGeneratorTest {

    @Test
    public void testNameCompliance() throws Exception {
        CGLIBMBeanGenerator cglibmBeanGenerator = new CGLIBMBeanGenerator();
        Foo mbeanPretender = new Foo();
        Object mbean = cglibmBeanGenerator.makeMBean(mbeanPretender);
        MBeanManagerImpl.checkCompliantion(mbean);
    }

    @Test
    public void testMethodDelegation() throws Exception {
        CGLIBMBeanGenerator cglibmBeanGenerator = new CGLIBMBeanGenerator();
        Foo mbeanPretender = new Foo();
        Object mbean = cglibmBeanGenerator.makeMBean(mbeanPretender);
        mbean.getClass().getMethod("hello").invoke(mbean);
        assertTrue(mbeanPretender.called, "mbeanPretender method have to be called");
    }

    public static class Foo {

        boolean called;

        @MBeanMethod
        public void hello() {
            called = true;
        }

    }
}

@@ -565,35 +565,49 @@
 ender = new Foo(
+false%0A        
 );%0A
-
         Object m
@@ -900,16 +900,21 @@
 new Foo(
+false
 );%0A     
@@ -1157,24 +1157,24 @@
 lass Foo %7B%0A%0A
-
         bool
@@ -1186,16 +1186,98 @@
 alled;%0A%0A
+        public Foo(boolean called) %7B%0A            this.called = called;%0A        %7D%0A%0A
         

fix Mbeans generation