|
|
703857 |
From 210c8bae09fb9309519c8266b71635ef308872b3 Mon Sep 17 00:00:00 2001
|
|
|
703857 |
From: Michal Srb <msrb@redhat.com>
|
|
|
703857 |
Date: Fri, 9 Aug 2013 12:44:48 +0200
|
|
|
703857 |
Subject: [PATCH] Remove android support
|
|
|
703857 |
|
|
|
703857 |
---
|
|
|
703857 |
.../internal/AndroidClassProxyFactory.java | 101 ---------------------
|
|
|
703857 |
.../java/org/easymock/internal/AndroidSupport.java | 37 --------
|
|
|
703857 |
.../java/org/easymock/internal/MocksControl.java | 6 --
|
|
|
703857 |
.../easymock/tests2/ClassExtensionHelperTest.java | 12 +--
|
|
|
703857 |
4 files changed, 3 insertions(+), 153 deletions(-)
|
|
|
703857 |
delete mode 100644 easymock/src/main/java/org/easymock/internal/AndroidClassProxyFactory.java
|
|
|
703857 |
delete mode 100644 easymock/src/main/java/org/easymock/internal/AndroidSupport.java
|
|
|
703857 |
|
|
|
703857 |
diff --git a/easymock/src/main/java/org/easymock/internal/AndroidClassProxyFactory.java b/easymock/src/main/java/org/easymock/internal/AndroidClassProxyFactory.java
|
|
|
703857 |
deleted file mode 100644
|
|
|
703857 |
index da04042..0000000
|
|
|
703857 |
--- a/easymock/src/main/java/org/easymock/internal/AndroidClassProxyFactory.java
|
|
|
703857 |
+++ /dev/null
|
|
|
703857 |
@@ -1,101 +0,0 @@
|
|
|
703857 |
-/**
|
|
|
703857 |
- * Copyright 2001-2013 the original author or authors.
|
|
|
703857 |
- *
|
|
|
703857 |
- * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
703857 |
- * you may not use this file except in compliance with the License.
|
|
|
703857 |
- * You may obtain a copy of the License at
|
|
|
703857 |
- *
|
|
|
703857 |
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
703857 |
- *
|
|
|
703857 |
- * Unless required by applicable law or agreed to in writing, software
|
|
|
703857 |
- * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
703857 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
703857 |
- * See the License for the specific language governing permissions and
|
|
|
703857 |
- * limitations under the License.
|
|
|
703857 |
- */
|
|
|
703857 |
-package org.easymock.internal;
|
|
|
703857 |
-
|
|
|
703857 |
-import java.io.IOException;
|
|
|
703857 |
-import java.lang.reflect.Constructor;
|
|
|
703857 |
-import java.lang.reflect.InvocationHandler;
|
|
|
703857 |
-import java.lang.reflect.Method;
|
|
|
703857 |
-import java.lang.reflect.Modifier;
|
|
|
703857 |
-import java.util.Arrays;
|
|
|
703857 |
-import java.util.HashSet;
|
|
|
703857 |
-import java.util.Set;
|
|
|
703857 |
-
|
|
|
703857 |
-import org.easymock.ConstructorArgs;
|
|
|
703857 |
-
|
|
|
703857 |
-import com.google.dexmaker.stock.ProxyBuilder;
|
|
|
703857 |
-
|
|
|
703857 |
-// ///CLOVER:OFF (sadly not possible to test android with clover)
|
|
|
703857 |
-/**
|
|
|
703857 |
- * Mocks concrete classes for Android's runtime by generating dex files.
|
|
|
703857 |
- */
|
|
|
703857 |
-public final class AndroidClassProxyFactory implements IProxyFactory {
|
|
|
703857 |
- public <T> T createProxy(Class<T> toMock, InvocationHandler handler,
|
|
|
703857 |
- Method[] mockedMethods, ConstructorArgs constructorArgs) {
|
|
|
703857 |
- final MockHandler interceptor = new MockHandler(handler, mockedMethods);
|
|
|
703857 |
- try {
|
|
|
703857 |
- ProxyBuilder<T> builder = ProxyBuilder.forClass(toMock)
|
|
|
703857 |
- .handler(interceptor);
|
|
|
703857 |
- if (constructorArgs != null) {
|
|
|
703857 |
- builder.constructorArgTypes(constructorArgs.getConstructor().getParameterTypes())
|
|
|
703857 |
- .constructorArgValues(constructorArgs.getInitArgs());
|
|
|
703857 |
- } else {
|
|
|
703857 |
- try {
|
|
|
703857 |
- DefaultClassInstantiator instantiator = new DefaultClassInstantiator();
|
|
|
703857 |
- Constructor constructor = instantiator.getConstructorToUse(toMock);
|
|
|
703857 |
- Object[] params = instantiator.getArgsForTypes(constructor.getParameterTypes());
|
|
|
703857 |
- builder.constructorArgTypes(constructor.getParameterTypes())
|
|
|
703857 |
- .constructorArgValues(params);
|
|
|
703857 |
- } catch (InstantiationException e) {
|
|
|
703857 |
- throw new RuntimeException("Fail to instantiate mock for " + toMock);
|
|
|
703857 |
- }
|
|
|
703857 |
- }
|
|
|
703857 |
- return builder.build();
|
|
|
703857 |
- } catch (IOException e) {
|
|
|
703857 |
- throw new RuntimeException("Failed to mock " + toMock, e);
|
|
|
703857 |
- }
|
|
|
703857 |
- }
|
|
|
703857 |
-
|
|
|
703857 |
- public InvocationHandler getInvocationHandler(Object mock) {
|
|
|
703857 |
- MockHandler mockHandler = (MockHandler) ProxyBuilder.getInvocationHandler(mock);
|
|
|
703857 |
- return mockHandler.delegate;
|
|
|
703857 |
- }
|
|
|
703857 |
-
|
|
|
703857 |
- private static class MockHandler implements InvocationHandler {
|
|
|
703857 |
- private final InvocationHandler delegate;
|
|
|
703857 |
- private final Set<Method> mockedMethods;
|
|
|
703857 |
-
|
|
|
703857 |
- public MockHandler(InvocationHandler delegate, Method... mockedMethods) {
|
|
|
703857 |
- this.delegate = delegate;
|
|
|
703857 |
- this.mockedMethods = (mockedMethods != null)
|
|
|
703857 |
- ? new HashSet<Method>(Arrays.asList(mockedMethods))
|
|
|
703857 |
- : null;
|
|
|
703857 |
- }
|
|
|
703857 |
-
|
|
|
703857 |
- public Object invoke(Object obj, Method method, Object[] args) throws Throwable {
|
|
|
703857 |
- if (method.isBridge()) {
|
|
|
703857 |
- method = BridgeMethodResolver.findBridgedMethod(method);
|
|
|
703857 |
- }
|
|
|
703857 |
-
|
|
|
703857 |
- // Never intercept EasyMock's own calls to fillInStackTrace
|
|
|
703857 |
- boolean internalFillInStackTraceCall = obj instanceof Throwable
|
|
|
703857 |
- && method.getName().equals("fillInStackTrace")
|
|
|
703857 |
- && ClassProxyFactory.isCallerMockInvocationHandlerInvoke(new Throwable());
|
|
|
703857 |
-
|
|
|
703857 |
- if (internalFillInStackTraceCall
|
|
|
703857 |
- || isMocked(method) && !Modifier.isAbstract(method.getModifiers())) {
|
|
|
703857 |
- return ProxyBuilder.callSuper(obj, method, args);
|
|
|
703857 |
- }
|
|
|
703857 |
-
|
|
|
703857 |
- return delegate.invoke(obj, method, args);
|
|
|
703857 |
- }
|
|
|
703857 |
-
|
|
|
703857 |
- private boolean isMocked(Method method) {
|
|
|
703857 |
- return mockedMethods != null && !mockedMethods.contains(method);
|
|
|
703857 |
- }
|
|
|
703857 |
- }
|
|
|
703857 |
-}
|
|
|
703857 |
-// ///CLOVER:ON
|
|
|
703857 |
\ No newline at end of file
|
|
|
703857 |
diff --git a/easymock/src/main/java/org/easymock/internal/AndroidSupport.java b/easymock/src/main/java/org/easymock/internal/AndroidSupport.java
|
|
|
703857 |
deleted file mode 100644
|
|
|
703857 |
index 43c683e..0000000
|
|
|
703857 |
--- a/easymock/src/main/java/org/easymock/internal/AndroidSupport.java
|
|
|
703857 |
+++ /dev/null
|
|
|
703857 |
@@ -1,37 +0,0 @@
|
|
|
703857 |
-/**
|
|
|
703857 |
- * Copyright 2001-2013 the original author or authors.
|
|
|
703857 |
- *
|
|
|
703857 |
- * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
703857 |
- * you may not use this file except in compliance with the License.
|
|
|
703857 |
- * You may obtain a copy of the License at
|
|
|
703857 |
- *
|
|
|
703857 |
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
703857 |
- *
|
|
|
703857 |
- * Unless required by applicable law or agreed to in writing, software
|
|
|
703857 |
- * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
703857 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
703857 |
- * See the License for the specific language governing permissions and
|
|
|
703857 |
- * limitations under the License.
|
|
|
703857 |
- */
|
|
|
703857 |
-package org.easymock.internal;
|
|
|
703857 |
-
|
|
|
703857 |
-/**
|
|
|
703857 |
- * Android-specific support.
|
|
|
703857 |
- */
|
|
|
703857 |
-public final class AndroidSupport {
|
|
|
703857 |
- // ///CLOVER:OFF
|
|
|
703857 |
- private static boolean isAndroid;
|
|
|
703857 |
- static {
|
|
|
703857 |
- try {
|
|
|
703857 |
- Class.forName("dalvik.system.PathClassLoader");
|
|
|
703857 |
- isAndroid = true;
|
|
|
703857 |
- } catch (final ClassNotFoundException e) {
|
|
|
703857 |
- isAndroid = false;
|
|
|
703857 |
- }
|
|
|
703857 |
- }
|
|
|
703857 |
-
|
|
|
703857 |
- public static boolean isAndroid() {
|
|
|
703857 |
- return isAndroid;
|
|
|
703857 |
- }
|
|
|
703857 |
- // ///CLOVER:ON
|
|
|
703857 |
-}
|
|
|
703857 |
diff --git a/easymock/src/main/java/org/easymock/internal/MocksControl.java b/easymock/src/main/java/org/easymock/internal/MocksControl.java
|
|
|
703857 |
index e709dc4..cd9d5a9 100644
|
|
|
703857 |
--- a/easymock/src/main/java/org/easymock/internal/MocksControl.java
|
|
|
703857 |
+++ b/easymock/src/main/java/org/easymock/internal/MocksControl.java
|
|
|
703857 |
@@ -137,12 +137,6 @@ public class MocksControl implements IMocksControl, IExpectationSetters<Object>,
|
|
|
703857 |
return cached;
|
|
|
703857 |
}
|
|
|
703857 |
|
|
|
703857 |
- // ///CLOVER:OFF
|
|
|
703857 |
- if (AndroidSupport.isAndroid()) {
|
|
|
703857 |
- return classProxyFactory = new AndroidClassProxyFactory();
|
|
|
703857 |
- }
|
|
|
703857 |
- // ///CLOVER:ON
|
|
|
703857 |
-
|
|
|
703857 |
try {
|
|
|
703857 |
return classProxyFactory = new ClassProxyFactory();
|
|
|
703857 |
} catch (final NoClassDefFoundError e) {
|
|
|
703857 |
diff --git a/easymock/src/test/java/org/easymock/tests2/ClassExtensionHelperTest.java b/easymock/src/test/java/org/easymock/tests2/ClassExtensionHelperTest.java
|
|
|
703857 |
index b40466c..b0a7c69 100644
|
|
|
703857 |
--- a/easymock/src/test/java/org/easymock/tests2/ClassExtensionHelperTest.java
|
|
|
703857 |
+++ b/easymock/src/test/java/org/easymock/tests2/ClassExtensionHelperTest.java
|
|
|
703857 |
@@ -15,7 +15,6 @@
|
|
|
703857 |
*/
|
|
|
703857 |
package org.easymock.tests2;
|
|
|
703857 |
|
|
|
703857 |
-import com.google.dexmaker.stock.ProxyBuilder;
|
|
|
703857 |
import java.lang.reflect.InvocationHandler;
|
|
|
703857 |
import java.lang.reflect.Method;
|
|
|
703857 |
import java.lang.reflect.Proxy;
|
|
|
703857 |
@@ -25,7 +24,6 @@ import net.sf.cglib.proxy.Enhancer;
|
|
|
703857 |
import net.sf.cglib.proxy.NoOp;
|
|
|
703857 |
import org.easymock.EasyMock;
|
|
|
703857 |
import static org.easymock.EasyMock.createMock;
|
|
|
703857 |
-import org.easymock.internal.AndroidSupport;
|
|
|
703857 |
import static org.easymock.internal.MocksControl.getControl;
|
|
|
703857 |
import static org.easymock.internal.MocksControl.getMockedType;
|
|
|
703857 |
import org.easymock.internal.MocksControl;
|
|
|
703857 |
@@ -61,13 +59,9 @@ public class ClassExtensionHelperTest {
|
|
|
703857 |
@Test
|
|
|
703857 |
public void testGetControl_EnhancedButNotAMock() throws Exception {
|
|
|
703857 |
final Object o;
|
|
|
703857 |
- if (AndroidSupport.isAndroid()) {
|
|
|
703857 |
- o = ProxyBuilder.forClass(ArrayList.class)
|
|
|
703857 |
- .handler(NOOP_INVOCATION_HANDLER)
|
|
|
703857 |
- .build();
|
|
|
703857 |
- } else {
|
|
|
703857 |
- o = Enhancer.create(ArrayList.class, NoOp.INSTANCE);
|
|
|
703857 |
- }
|
|
|
703857 |
+
|
|
|
703857 |
+ o = Enhancer.create(ArrayList.class, NoOp.INSTANCE);
|
|
|
703857 |
+
|
|
|
703857 |
try {
|
|
|
703857 |
getControl(o);
|
|
|
703857 |
fail();
|
|
|
703857 |
--
|
|
|
703857 |
1.8.1.4
|
|
|
703857 |
|