This is an automated email from the ASF dual-hosted git repository.
svenmeier pushed a commit to branch wicket-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/wicket-9.x by this push:
new eb42b15 WICKET-6913 move package private
eb42b15 is described below
commit eb42b157a0f856b9e6a37b82a0102cd0f1c5cf7b
Author: Sven Meier <[email protected]>
AuthorDate: Mon Aug 23 14:04:22 2021 +0200
WICKET-6913 move package private
works fine with cglib already
---
.../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 5483ce4..ff6c96a 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,14 +34,6 @@ import org.apache.wicket.proxy.util.InterfaceObject;
import org.apache.wicket.proxy.util.ObjectMethodTester;
import org.junit.jupiter.api.Test;
-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
*
@@ -45,8 +46,6 @@ public class LazyInitProxyFactoryTest
private static 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;
@@ -69,17 +68,6 @@ public 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;
@@ -192,61 +180,6 @@ public class LazyInitProxyFactoryTest
}
/**
- * Tests lazy init proxy to represent package private concrete objects
- *
- * https://issues.apache.org/jira/browse/WICKET-4324
- */
- @Test
- public void testPackagePrivateConcreteProxy()
- {
- PackagePrivateConcreteObject proxy =
(PackagePrivateConcreteObject)LazyInitProxyFactory.createProxy(
- PackagePrivateConcreteObject.class,
PACKAGE_PRIVATE_CONCRETE_OBJECT_LOCATOR);
-
- // test proxy implements ILazyInitProxy
- assertTrue(proxy instanceof ILazyInitProxy);
- assertTrue(((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(proxy.getMessage(), "package-private-concrete");
-
- // test serialization
- PackagePrivateConcreteObject proxy2 =
WicketObjects.cloneObject(proxy);
- assertTrue(proxy != proxy2);
- assertEquals(proxy2.getMessage(), "package-private-concrete");
-
- // 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 replacement
*/
@Test
public void testCGLibInterceptorReplacement()
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 3b31e63..e11dc58 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());
+ }
+}