Permalink
Browse files

Revert "Fixes #839 Removed deprecated code in PowerMock 2.0."

This reverts commit ee21c60.
  • Loading branch information...
thekingnothing committed Sep 10, 2017
1 parent ee21c60 commit 659989f9515e207642548615a39f8eff06f314cf
Showing with 1,336 additions and 14 deletions.
  1. +15 −0 gradle/modules.gradle
  2. +2 −1 ...ck-api-easymock/src/main/java/org/powermock/api/easymock/powermocklistener/AnnotationEnabler.java
  3. +2 −2 .../powermock-api-easymock/src/main/java/org/powermock/api/extension/listener/AnnotationEnabler.java
  4. +1 −0 ...ck-api-easymock/src/main/java/org/powermock/api/extension/listener/EasyMockAnnotationSupport.java
  5. +1 −1 ...owermock-api-easymock/src/main/java/org/powermock/api/extension/listener/TestSubjectInjector.java
  6. +10 −1 ...i/powermock-api-mockito/src/main/java/org/powermock/api/extension/listener/AnnotationEnabler.java
  7. +10 −1 .../powermock-api-mockito2/src/main/java/org/powermock/api/extension/listener/AnnotationEnabler.java
  8. +2 −1 ...ock-api-mockito2/src/main/java/org/powermock/api/mockito/powermocklistener/AnnotationEnabler.java
  9. +87 −0 powermock-core/src/main/java/org/powermock/core/classloader/annotations/Mock.java
  10. +100 −0 ...ck-modules/powermock-module-junit3/src/main/java/org/powermock/modules/junit3/PowerMockSuite.java
  11. +57 −0 ...ock-module-junit3/src/main/java/org/powermock/modules/junit3/internal/JUnit3TestSuiteChunker.java
  12. +45 −0 ...ule-junit3/src/main/java/org/powermock/modules/junit3/internal/PowerMockJUnit3RunnerDelegate.java
  13. +208 −0 ...e-junit3/src/main/java/org/powermock/modules/junit3/internal/impl/JUnit3TestSuiteChunkerImpl.java
  14. +150 −0 ...3/src/main/java/org/powermock/modules/junit3/internal/impl/PowerMockJUnit3RunnerDelegateImpl.java
  15. +74 −0 ...-junit3/src/main/java/org/powermock/modules/junit3/internal/impl/PowerMockJUnit3TestListener.java
  16. +4 −1 .../powermock-module-testng-common/src/main/java/org/powermock/modules/testng/PowerMockTestCase.java
  17. +3 −0 powermock-release/build.gradle
  18. +2 −0 settings.gradle
  19. +15 −0 tests/easymock/build.gradle
  20. +33 −0 tests/easymock/junit3/src/test/java/samples/junit3/AllJUnit3Tests.java
  21. +40 −0 ...symock/junit3/src/test/java/samples/junit3/annotationbased/AnnotationDemoWithSetupMethodTest.java
  22. +55 −0 .../easymock/junit3/src/test/java/samples/junit3/annotationbased/PrivateFinalWithAnnotationTest.java
  23. +69 −0 tests/easymock/junit3/src/test/java/samples/junit3/privateandfinal/PrivateFinalTest.java
  24. +70 −0 tests/easymock/junit3/src/test/java/samples/junit3/privateandfinal/StupidPrivateFinalTest.java
  25. +177 −0 tests/easymock/junit3/src/test/java/samples/junit3/singleton/MockStaticTest.java
  26. +68 −0 ...junit3/src/test/java/samples/junit3/suppressconstructor/SuppressConstructorHierarchyDemoTest.java
  27. +2 −4 ...ito-junit4/src/test/java/org/powermock/modules/junit4/largemethod/LargeMethodInInterfaceTest.java
  28. +13 −0 ...o/junit4-agent/src/test/java/samples/powermockito/junit4/agent/MockFinalUsingAnnotationsTest.java
  29. +7 −1 ...a/powermock/modules/test/mockito/junit4/delegate/parameterized/MockFinalUsingAnnotationsTest.java
  30. +13 −0 ...nit4/src/test/java/samples/powermockito/junit4/annotationbased/MockFinalUsingAnnotationsTest.java
  31. +1 −1 version.properties
View
@@ -287,6 +287,21 @@ project(":powermock-modules:powermock-module-javaagent") {
}
}
project(":powermock-modules:powermock-module-junit3") {
description = "PowerMock support module for JUnit 3.x."
dependencies {
compile(project(":powermock-core")) {
exclude group: 'junit', module: 'junit'
}
compile("junit:junit:3.8.2") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testCompile("org.hamcrest:hamcrest-core:${hamcrestVersion}")
testCompile("org.assertj:assertj-core:${assertjVersion}")
}
}
project(":powermock-modules:powermock-module-junit4-common") {
description = "PowerMock support module for all versions of JUnit 4.x."
@@ -17,9 +17,10 @@
import org.powermock.api.easymock.annotation.MockNice;
import org.powermock.api.easymock.annotation.MockStrict;
import org.powermock.core.classloader.annotations.Mock;
/**
* Before each test method all fields annotated with {@link org.powermock.api.easymock.annotation.Mock},
* Before each test method all fields annotated with {@link Mock},
* {@link MockNice} or {@link MockStrict} will have mock objects created for
* them and injected to the fields.
*
@@ -16,9 +16,9 @@
package org.powermock.api.extension.listener;
import org.powermock.api.easymock.EasyMockConfiguration;
import org.powermock.api.easymock.annotation.Mock;
import org.powermock.api.easymock.annotation.MockNice;
import org.powermock.api.easymock.annotation.MockStrict;
import org.powermock.core.classloader.annotations.Mock;
import org.powermock.core.spi.listener.AnnotationEnablerListener;
import org.powermock.core.spi.support.AbstractPowerMockTestListenerBase;
import org.powermock.reflect.Whitebox;
@@ -53,7 +53,7 @@
@SuppressWarnings("unchecked")
public Class<? extends Annotation>[] getMockAnnotations() {
return new Class[]{Mock.class, MockNice.class, MockStrict.class};
return new Class[]{org.powermock.api.easymock.annotation.Mock.class, Mock.class, MockNice.class, MockStrict.class};
}
@Override
@@ -68,6 +68,7 @@ protected void injectNiceMocks() throws Exception {
@SuppressWarnings("deprecation")
protected void injectDefaultMocks() throws Exception {
inject(testInstance, Mock.class, annotationMockCreatorFactory.createDefaultMockCreator());
inject(testInstance, org.powermock.core.classloader.annotations.Mock.class, annotationMockCreatorFactory.createDefaultMockCreator());
}
@SuppressWarnings("unchecked")
@@ -27,7 +27,7 @@
/**
* The class injects mocks created with {@link Mock}, {@link org.powermock.api.easymock.annotation.Mock}
* to fields of objects which is annotated with {@link TestSubject}
* and {@link org.powermock.core.classloader.annotations.Mock} to fields of objects which is annotated with {@link TestSubject}
* @see TestSubject
* @since 1.6.5
*/
@@ -87,6 +87,15 @@ private void standardInject(Object testInstance) throws IllegalAccessException {
continue;
}
final Class<?> type = field.getType();
if (field.isAnnotationPresent(org.powermock.core.classloader.annotations.Mock.class)) {
org.powermock.core.classloader.annotations.Mock annotation = field
.getAnnotation(org.powermock.core.classloader.annotations.Mock.class);
final String[] value = annotation.value();
if (value.length != 1 || !"".equals(value[0])) {
System.err
.println("PowerMockito deprecation: Use PowerMockito.spy(..) for partial mocking instead. A standard mock will be created instead.");
}
}
if (field.isAnnotationPresent(org.mockito.Mock.class)) {
org.mockito.Mock mockAnnotation = field.getAnnotation(org.mockito.Mock.class);
@@ -116,7 +125,7 @@ private void standardInject(Object testInstance) throws IllegalAccessException {
@SuppressWarnings("unchecked")
@Override
public Class<? extends Annotation>[] getMockAnnotations() {
return new Class[]{org.mockito.Mock.class, Mock.class};
return new Class[]{org.mockito.Mock.class, Mock.class, org.powermock.core.classloader.annotations.Mock.class};
}
private Object processAnnotationOn(Captor annotation, Field field) {
@@ -76,6 +76,15 @@ private void standardInject(Object testInstance) throws IllegalAccessException {
continue;
}
final Class<?> type = field.getType();
if (field.isAnnotationPresent(org.powermock.core.classloader.annotations.Mock.class)) {
org.powermock.core.classloader.annotations.Mock annotation = field
.getAnnotation(org.powermock.core.classloader.annotations.Mock.class);
final String[] value = annotation.value();
if (value.length != 1 || !"".equals(value[0])) {
System.err
.println("PowerMockito deprecation: Use PowerMockito.spy(..) for partial mocking instead. A standard mock will be created instead.");
}
}
if (field.isAnnotationPresent(org.mockito.Mock.class)) {
org.mockito.Mock mockAnnotation = field.getAnnotation(org.mockito.Mock.class);
@@ -105,7 +114,7 @@ private void standardInject(Object testInstance) throws IllegalAccessException {
@SuppressWarnings("unchecked")
@Override
public Class<? extends Annotation>[] getMockAnnotations() {
return new Class[]{org.mockito.Mock.class, Mock.class};
return new Class[]{org.mockito.Mock.class, Mock.class, org.powermock.core.classloader.annotations.Mock.class};
}
private Object processAnnotationOn(Captor annotation, Field field) {
@@ -17,7 +17,8 @@
package org.powermock.api.mockito.powermocklistener;
/**
* Before each test method all fields annotated with {@link org.mockito.Mock} have mock objects created for them
* Before each test method all fields annotated with {@link org.mockito.MockitoAnnotations.Mock},
* {@link org.mockito.Mock} or {@link org.powermock.core.classloader.annotations.Mock} have mock objects created for them
* and injected to the fields.
*
* @deprecated Test Runners uses an annotation enabling listener per default
@@ -0,0 +1,87 @@
/*
* Copyright 2011 the original author or authors.
*
* 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.powermock.core.classloader.annotations;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This annotation can be placed on those fields in your test class that should
* be mocked. This eliminates the need to setup and tear-down mocks manually
* which minimizes repetitive test code and makes the test more readable. In
* order for PowerMock to control the life-cycle of the mocks you must supply
* the {@link PowerMockListener} annotation to the class-level of the test case.
* For example:
*
* <pre>
* ...
* &#064;PowerMockListener(AnnotationEnabler.class)
* public class PersonServiceTest {
*
* &#064;Mock
* private PersonDao personDaoMock;
*
* private PersonService classUnderTest;
*
* &#064;Before
* public void setUp() {
* classUnderTest = new PersonService(personDaoMock);
* }
* ...
* }
* </pre>
* <p>
*
* Note that you can also create partial mocks by using the annotation. Let's
* say that the PersonService has a method called "getPerson" and another method
* called "savePerson" and these are the only two methods that you'd like to
* mock. Rewriting the previous example to accommodate this will give us the
* following test:
*
* <pre>
* ...
* &#064;PowerMockListener(EasyMockAnnotationEnabler.class)
* public class PersonServiceTest {
*
* &#064;Mock({&quot;getPerson&quot;, &quot;savePerson&quot;})
* private PersonDao personDaoMock;
*
* private PersonService classUnderTest;
*
* &#064;Before
* public void setUp() {
* classUnderTest = new PersonService(personDaoMock);
* }
* ...
* }
* </pre>
* <p>
*
* @deprecated Use Mock annotation in respective extension API instead. This
* annotation will be removed in an upcoming release.
*/
@Deprecated
@Target( { ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Mock {
String[] value() default "";
}
@@ -0,0 +1,100 @@
/*
* Copyright 2008 the original author or authors.
*
* 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.powermock.modules.junit3;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import org.powermock.modules.junit3.internal.JUnit3TestSuiteChunker;
import org.powermock.modules.junit3.internal.impl.JUnit3TestSuiteChunkerImpl;
import java.util.Enumeration;
/**
* A custom JUnit 3 Suite that must be used to run PowerMock tests under JUnit3.
* @deprecated Since PowerMock 2.0 Supporting jUnit 3 will be dropped.
*/
@Deprecated
public class PowerMockSuite extends TestSuite {
private JUnit3TestSuiteChunker testChunker;
public PowerMockSuite(String name, Class<? extends TestCase>... testCases) throws Exception {
if (name != null) {
setName(name);
}
testChunker = new JUnit3TestSuiteChunkerImpl(testCases);
}
public PowerMockSuite(Class<? extends TestCase>... testCases) throws Exception {
this(null, testCases);
}
@Override
public void run(TestResult result) {
testChunker.run(result);
}
@Override
public void addTest(Test test) {
try {
testChunker.addTest(test);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
}
}
@Override
public void runTest(Test test, TestResult result) {
testChunker.runTest(test, result);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void addTestSuite(Class testClass) {
try {
testChunker.addTestSuite(testClass);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public Test testAt(int index) {
return testChunker.testAt(index);
}
@Override
public int testCount() {
return testChunker.getTestCount();
}
@SuppressWarnings("rawtypes")
@Override
public Enumeration tests() {
return testChunker.tests();
}
@Override
public int countTestCases() {
return testChunker.countTestCases();
}
}
@@ -0,0 +1,57 @@
/*
* Copyright 2008 the original author or authors.
*
* 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.powermock.modules.junit3.internal;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import org.powermock.tests.utils.RunnerTestSuiteChunker;
import java.lang.reflect.Method;
import java.util.Enumeration;
/**
* @deprecated Since PowerMock 2.0 Supporting jUnit 3 will be dropped.
*/
@Deprecated
public interface JUnit3TestSuiteChunker extends RunnerTestSuiteChunker {
/**
* Add a class to the test suite. Methods in this class will be checked
* according to {@link #shouldExecuteTestForMethod(Class, Method)} to see if
* it should be executed.
*
* @param clazz
* The class that should contain test cases.
* @throws Exception
* If something unexpected goes wrong.
*/
void addTestClassToSuite(Class<?> clazz) throws Exception;
void run(TestResult result);
void addTest(Test test) throws Exception;
void runTest(Test test, TestResult result);
void addTestSuite(Class<? extends TestCase> testClass) throws Exception;
Test testAt(int index);
int countTestCases();
Enumeration<?> tests();
}
Oops, something went wrong.

0 comments on commit 659989f

Please sign in to comment.