This is an automated email from the ASF dual-hosted git repository.

svenmeier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit d9275ce6f78ffe8ada321af480b66ddd8ca41f57
Author: Sven Meier <svenme...@apache.org>
AuthorDate: Mon Aug 23 14:04:22 2021 +0200

    WICKET-6913 move package private
    
    to trigger package access error
---
 .../wicket/proxy/LazyInitProxyFactoryTest.java     |  85 ++--------------
 .../PackagePrivateConcreteObject.java              |   4 +-
 .../proxy/packageprivate/PackagePrivateTest.java   | 109 +++++++++++++++++++++
 3 files changed, 120 insertions(+), 78 deletions(-)

diff --git 
a/wicket-ioc/src/test/java/org/apache/wicket/proxy/LazyInitProxyFactoryTest.java
 
b/wicket-ioc/src/test/java/org/apache/wicket/proxy/LazyInitProxyFactoryTest.java
index 6b907d2..60f4fc5 100644
--- 
a/wicket-ioc/src/test/java/org/apache/wicket/proxy/LazyInitProxyFactoryTest.java
+++ 
b/wicket-ioc/src/test/java/org/apache/wicket/proxy/LazyInitProxyFactoryTest.java
@@ -16,6 +16,15 @@
  */
 package org.apache.wicket.proxy;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.ObjectStreamException;
+import java.lang.reflect.Proxy;
+
 import org.apache.wicket.core.util.lang.WicketObjects;
 import org.apache.wicket.proxy.LazyInitProxyFactory.ProxyReplacement;
 import org.apache.wicket.proxy.util.ConcreteObject;
@@ -25,15 +34,6 @@ import org.apache.wicket.proxy.util.InterfaceObject;
 import org.apache.wicket.proxy.util.ObjectMethodTester;
 import org.junit.jupiter.api.Test;
 
-import java.io.ObjectStreamException;
-import java.lang.reflect.Proxy;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotSame;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
 /**
  * Tests lazy init proxy factory
  * 
@@ -46,8 +46,6 @@ class LazyInitProxyFactoryTest
 
        private static final ConcreteObject concreteObject = new 
ConcreteObject("concrete");
 
-       private static final PackagePrivateConcreteObject 
PACKAGE_PRIVATE_CONCRETE_OBJECT = new 
PackagePrivateConcreteObject("package-private-concrete");
-
        private static IProxyTargetLocator interfaceObjectLocator = new 
IProxyTargetLocator()
        {
                private static final long serialVersionUID = 1L;
@@ -75,17 +73,6 @@ class LazyInitProxyFactoryTest
                }
        };
 
-       private final static IProxyTargetLocator 
PACKAGE_PRIVATE_CONCRETE_OBJECT_LOCATOR = new IProxyTargetLocator()
-       {
-               private static final long serialVersionUID = 1L;
-
-               @Override
-               public Object locateProxyTarget()
-               {
-                       return 
LazyInitProxyFactoryTest.PACKAGE_PRIVATE_CONCRETE_OBJECT;
-               }
-       };
-
        private static IProxyTargetLocator stringObjectLocator = new 
IProxyTargetLocator()
        {
                private static final long serialVersionUID = 1L;
@@ -199,60 +186,6 @@ class LazyInitProxyFactoryTest
        }
 
        /**
-        * Tests lazy init proxy to represent package private concrete objects
-        *
-        * https://issues.apache.org/jira/browse/WICKET-4324
-        */
-       @Test
-       void testPackagePrivateConcreteProxy()
-       {
-               PackagePrivateConcreteObject proxy = 
(PackagePrivateConcreteObject)LazyInitProxyFactory.createProxy(
-                               PackagePrivateConcreteObject.class, 
PACKAGE_PRIVATE_CONCRETE_OBJECT_LOCATOR);
-
-               // test proxy implements ILazyInitProxy
-               assertTrue(proxy instanceof ILazyInitProxy);
-               assertSame(((ILazyInitProxy)proxy).getObjectLocator(), 
PACKAGE_PRIVATE_CONCRETE_OBJECT_LOCATOR);
-
-               // test we do not have a jdk dynamic proxy
-               assertFalse(Proxy.isProxyClass(proxy.getClass()));
-
-               // test method invocation
-               assertEquals("package-private-concrete", proxy.getMessage());
-
-               // test serialization
-               PackagePrivateConcreteObject proxy2 = 
WicketObjects.cloneObject(proxy);
-               assertNotSame(proxy, proxy2);
-               assertEquals("package-private-concrete", proxy2.getMessage());
-
-               // test equals/hashcode method interception
-               final IObjectMethodTester tester = new ObjectMethodTester();
-               assertTrue(tester.isValid());
-
-               // test only a single class is generated,
-               // otherwise permgen space will fill up with each proxy
-               assertSame(proxy.getClass(), LazyInitProxyFactory.createProxy(
-                               PackagePrivateConcreteObject.class, 
PACKAGE_PRIVATE_CONCRETE_OBJECT_LOCATOR).getClass());
-
-               IProxyTargetLocator testerLocator = new IProxyTargetLocator()
-               {
-                       private static final long serialVersionUID = 1L;
-
-                       @Override
-                       public Object locateProxyTarget()
-                       {
-                               return tester;
-                       }
-               };
-
-               ObjectMethodTester testerProxy = 
(ObjectMethodTester)LazyInitProxyFactory.createProxy(
-                               ObjectMethodTester.class, testerLocator);
-               testerProxy.equals(this);
-               testerProxy.hashCode();
-               testerProxy.toString();
-               assertTrue(tester.isValid());
-       }
-
-       /**
         * Tests lazy init concrete replacement
         */
        @Test
diff --git 
a/wicket-ioc/src/test/java/org/apache/wicket/proxy/PackagePrivateConcreteObject.java
 
b/wicket-ioc/src/test/java/org/apache/wicket/proxy/packageprivate/PackagePrivateConcreteObject.java
similarity index 91%
rename from 
wicket-ioc/src/test/java/org/apache/wicket/proxy/PackagePrivateConcreteObject.java
rename to 
wicket-ioc/src/test/java/org/apache/wicket/proxy/packageprivate/PackagePrivateConcreteObject.java
index 5f87e29..bc27e03 100644
--- 
a/wicket-ioc/src/test/java/org/apache/wicket/proxy/PackagePrivateConcreteObject.java
+++ 
b/wicket-ioc/src/test/java/org/apache/wicket/proxy/packageprivate/PackagePrivateConcreteObject.java
@@ -14,11 +14,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.wicket.proxy;
+package org.apache.wicket.proxy.packageprivate;
 
 /**
  * Mock dependency that does not implement an interface.
- * Its visibility is package private (to {@link LazyInitProxyFactoryTest}) to 
test a bug
+ * Its visibility is package private (to {@link PackagePrivateTest}) to test a 
bug
  * described at https://issues.apache.org/jira/browse/WICKET-4324
  */
 class PackagePrivateConcreteObject
diff --git 
a/wicket-ioc/src/test/java/org/apache/wicket/proxy/packageprivate/PackagePrivateTest.java
 
b/wicket-ioc/src/test/java/org/apache/wicket/proxy/packageprivate/PackagePrivateTest.java
new file mode 100644
index 0000000..f7c82dc
--- /dev/null
+++ 
b/wicket-ioc/src/test/java/org/apache/wicket/proxy/packageprivate/PackagePrivateTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.wicket.proxy.packageprivate;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.lang.reflect.Proxy;
+
+import org.apache.wicket.core.util.lang.WicketObjects;
+import org.apache.wicket.proxy.ILazyInitProxy;
+import org.apache.wicket.proxy.IProxyTargetLocator;
+import org.apache.wicket.proxy.LazyInitProxyFactory;
+import org.apache.wicket.proxy.util.IObjectMethodTester;
+import org.apache.wicket.proxy.util.ObjectMethodTester;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests lazy init proxy factory
+ * 
+ * @author Igor Vaynberg (ivaynberg)
+ * 
+ */
+class PackagePrivateTest
+{
+       private static final PackagePrivateConcreteObject 
PACKAGE_PRIVATE_CONCRETE_OBJECT = new 
PackagePrivateConcreteObject("package-private-concrete");
+
+       private final static IProxyTargetLocator 
PACKAGE_PRIVATE_CONCRETE_OBJECT_LOCATOR = new IProxyTargetLocator()
+       {
+               private static final long serialVersionUID = 1L;
+
+               @Override
+               public Object locateProxyTarget()
+               {
+                       return 
PackagePrivateTest.PACKAGE_PRIVATE_CONCRETE_OBJECT;
+               }
+       };
+
+       /**
+        * Tests lazy init proxy to represent package private concrete objects
+        *
+        * https://issues.apache.org/jira/browse/WICKET-4324
+        */
+       @Test
+       void testPackagePrivateConcreteProxy()
+       {
+               PackagePrivateConcreteObject proxy = 
(PackagePrivateConcreteObject)LazyInitProxyFactory.createProxy(
+                               PackagePrivateConcreteObject.class, 
PACKAGE_PRIVATE_CONCRETE_OBJECT_LOCATOR);
+
+               // test proxy implements ILazyInitProxy
+               assertTrue(proxy instanceof ILazyInitProxy);
+               assertSame(((ILazyInitProxy)proxy).getObjectLocator(), 
PACKAGE_PRIVATE_CONCRETE_OBJECT_LOCATOR);
+
+               // test we do not have a jdk dynamic proxy
+               assertFalse(Proxy.isProxyClass(proxy.getClass()));
+
+               // test method invocation
+               assertEquals("package-private-concrete", proxy.getMessage());
+
+               // test serialization
+               PackagePrivateConcreteObject proxy2 = 
WicketObjects.cloneObject(proxy);
+               assertNotSame(proxy, proxy2);
+               assertEquals("package-private-concrete", proxy2.getMessage());
+
+               // test equals/hashcode method interception
+               final IObjectMethodTester tester = new ObjectMethodTester();
+               assertTrue(tester.isValid());
+
+               // test only a single class is generated,
+               // otherwise permgen space will fill up with each proxy
+               assertSame(proxy.getClass(), LazyInitProxyFactory.createProxy(
+                               PackagePrivateConcreteObject.class, 
PACKAGE_PRIVATE_CONCRETE_OBJECT_LOCATOR).getClass());
+
+               IProxyTargetLocator testerLocator = new IProxyTargetLocator()
+               {
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       public Object locateProxyTarget()
+                       {
+                               return tester;
+                       }
+               };
+
+               ObjectMethodTester testerProxy = 
(ObjectMethodTester)LazyInitProxyFactory.createProxy(
+                               ObjectMethodTester.class, testerLocator);
+               testerProxy.equals(this);
+               testerProxy.hashCode();
+               testerProxy.toString();
+               assertTrue(tester.isValid());
+       }
+}

Reply via email to