[jboss-cvs] JBossAS SVN: r107545 - in projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors: javassist and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 11 23:01:04 EDT 2010


Author: marius.bogoevici
Date: 2010-08-11 23:01:04 -0400 (Wed, 11 Aug 2010)
New Revision: 107545

Added:
   projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/
   projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/Bar.java
   projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/Foo.java
   projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/TestCovariants.java
Log:
Added test for covariant types

Added: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/Bar.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/Bar.java	                        (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/Bar.java	2010-08-12 03:01:04 UTC (rev 107545)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.interceptors.javassist;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class Bar extends Foo
+{
+   @Override
+   public Bar produce()
+   {
+      return new Bar();
+   }
+}

Added: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/Foo.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/Foo.java	                        (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/Foo.java	2010-08-12 03:01:04 UTC (rev 107545)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.interceptors.javassist;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class Foo
+{   
+   public void other()
+   {
+   }
+
+   public Foo produce()
+   {
+      return new Foo();
+   }
+}

Added: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/TestCovariants.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/TestCovariants.java	                        (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/javassist/TestCovariants.java	2010-08-12 03:01:04 UTC (rev 107545)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.interceptors.javassist;
+
+import java.lang.reflect.Method;
+
+import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class TestCovariants
+{
+
+   @Test
+   public void testCovariants() throws Exception
+   {
+      MyMethodHandler.produceInvoked = false;
+      MyMethodHandler.otherInvoked = false;
+      ProxyFactory proxyFactory = new ProxyFactory();
+      proxyFactory.setSuperclass(Bar.class);
+      proxyFactory.setUseWriteReplace(false);
+      Class<Bar> clazz = proxyFactory.createClass();
+      Bar bar = clazz.newInstance();
+      ((ProxyObject)bar).setHandler(new MyMethodHandler());
+      bar.produce();
+      bar.other();
+      Assert.assertTrue(MyMethodHandler.otherInvoked);
+      Assert.assertTrue(MyMethodHandler.produceInvoked);
+   }
+
+   static class MyMethodHandler implements MethodHandler
+   {
+      static boolean produceInvoked;
+
+      static boolean otherInvoked;
+
+      public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
+      {
+         if (thisMethod.getName().equals("produce"))
+         {
+            produceInvoked = true;
+         }
+         if (thisMethod.getName().equals("other"))
+         {
+            otherInvoked = true;
+         }
+         return proceed.invoke(self,args);
+      }
+   }
+}



More information about the jboss-cvs-commits mailing list