public class ObjectFactoryTest4
{
@Test public void testNothing() throws Exception
{
Assert.assertTrue(true);
}
public static interface _XY
{ int _fun();
int fun1(int x);
int fun2(int x, int z);
int fun3(int w, int x, int z);
}
public static class XY implements _XY
{ private final int y; public XY(int y)
{ this.y = y;
}
@Override public int _fun()
{ return y + 5;
}
public int fun1(int x)
{ return x + y + 10;
}
public int fun2(int x, int z)
{ return x + y + z + 20;
}
public int fun3(int w, int x, int z)
{ return w + x + y + z + 30;
}
}
public static class XY2
{ private final int y; public XY2(int y)
{ this.y = y;
}
public int fun2(int x, int z)
{ return x + y + z + 20;
}
public final int fun3(int w, int x, int z)
{ return w + x + y + z + 30;
}
}
public static class XY3 implements _XY
{ private final int y; public XY3(int y)
{ this.y = y;
}
public int _fun()
{ return y + 5;
}
final public int fun1(int x)
{ return x + y + 10;
}
public int fun2(int x, int z)
{ return x + y + z + 20;
}
public int fun3(int w, int x, int z)
{ return w + x + y + z + 30;
}
public int fun4(int v, int w, int x, int z)
{ return v + w + x + y + z + 40;
}
}
private static int c1 = 0; private static int c2 = 0; private static int c3 = 0; public static class XMonitor implements ObjectMonitor
{
@Override public void onMethodCannotBeMonitored(Method m)
{
c1 ++;
}
@Override public void onClassCannotBeMonitored(Class> clz)
{
c2 ++;
}
@WatchMethods(clz=@Classes(pattern="com.logntw.eva.ioc.ObjectFactoryTest4\\S*"), method=@Methods()) public void onMethodInvoked(Advice advice, int a)
{
c3 ++;
}
}
private static int c4 = 0; private static int c5 = 0; private static int c6 = 0; public static class YMonitor implements ObjectMonitor
{
@Override public void onMethodCannotBeMonitored(Method m)
{
c4++;
}
@Override public void onClassCannotBeMonitored(Class> clz)
{
c5++;
}
@WatchMethods(clz=@Classes(pattern="com.logntw.eva.ioc.ObjectFactoryTest4\\S*"), method=@Methods()) public void onMethodInvoked(Advice advice)
{
c6++;
}
};
private static int c7 = 0; private static int c8 = 0; private static int c9 = 0; public static class ZMonitor implements ObjectMonitor
{
@Override public void onMethodCannotBeMonitored(Method m)
{
c7++;
}
@Override public void onClassCannotBeMonitored(Class> clz)
{
c8++;
}
@WatchMethods(clz=@Classes(pattern="com.logntw.eva.ioc.ObjectFactoryTest4\\S*"), method=@Methods()) public void onMethodInvoked(Advice advice, Object... a)
{
c9++;
}
};
private static int c10 = 0; private static int c11 = 0; private static int c12 = 0; public static class WMonitor implements ObjectMonitor
{
@Override public void onMethodCannotBeMonitored(Method m)
{
c10++;
}
@Override public void onClassCannotBeMonitored(Class> clz)
{
c11++;
}
@WatchMethods(clz=@Classes(pattern="com.logntw.eva.ioc.ObjectFactoryTest4\\S*"), method=@Methods()) public void onMethodInvoked(Advice advice, int a, Object... b)
{
c12++;
for(int i = 0 ; i < b.length; i++)
Assert.assertTrue(b[i] instanceof Integer);
}
};
@Test public void testObjectFactory() throws Exception
{
ObjectFactory objectFactory = DefoObjectFactory.getInstance();
objectFactory.addObjectMonitor(new XMonitor(), new YMonitor(), new ZMonitor(), new WMonitor());