├── .travis.yml ├── examples ├── simple │ └── src │ │ └── main │ │ └── java │ │ └── simpleConfig.properties ├── DocumentationExamples │ └── src │ │ └── main │ │ └── java │ │ └── powermock │ │ └── examples │ │ ├── partialmocking │ │ ├── Status.java │ │ ├── EntityManager.java │ │ └── StatusSender.java │ │ ├── annotationbased │ │ └── dao │ │ │ └── SomeDao.java │ │ ├── suppress │ │ ├── constructor │ │ └── constructorhierarchy │ │ │ ├── EvilGrandParent.java │ │ │ └── EvilParent.java │ │ ├── bypassencapsulation │ │ └── nontest │ │ │ └── Cache.java │ │ └── staticmocking │ │ └── IdGenerator.java ├── log4j │ └── src │ │ └── main │ │ └── java │ │ └── demo │ │ └── org │ │ └── powermock │ │ └── examples │ │ ├── Log4jUserParent.java │ │ └── Log4jUser.java ├── HamcrestExample │ └── src │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── powermock │ │ │ └── hamcrest │ │ │ └── HamcrestExample.java │ │ └── test │ │ └── java │ │ └── org │ │ └── powermock │ │ └── hamcrest │ │ └── HamcrestExampleTest.java ├── slf4j-noimpl │ └── src │ │ ├── main │ │ └── java │ │ │ └── demo │ │ │ └── org │ │ │ └── powermock │ │ │ └── examples │ │ │ └── SL4JUser.java │ │ └── test │ │ └── java │ │ └── demo │ │ └── org │ │ └── powermock │ │ └── examples │ │ └── SPITest.java ├── spring-mockito-xml │ └── src │ │ └── main │ │ ├── resources │ │ └── employees.xml │ │ └── java │ │ └── powermock │ │ └── examples │ │ └── spring │ │ ├── IdGenerator.java │ │ └── Message.java ├── spring-mockito-xml-agent │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── employees.xml │ │ └── java │ │ │ └── powermock │ │ │ └── examples │ │ │ └── spring │ │ │ └── IdGenerator.java │ │ └── test │ │ └── java │ │ └── org │ │ └── powermock │ │ └── modules │ │ └── agent │ │ └── AbstractClassTransformerTest.java ├── jcl │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── powermock │ │ └── examples │ │ └── JclUser.java ├── slf4j │ └── src │ │ └── main │ │ ├── resources │ │ └── log4j.properties │ │ └── java │ │ └── demo │ │ └── org │ │ └── powermock │ │ └── examples │ │ └── Slf4jUser.java ├── slf4j-mockito │ └── src │ │ ├── main │ │ ├── java │ │ │ └── demo │ │ │ │ └── org │ │ │ │ └── powermock │ │ │ │ └── examples │ │ │ │ └── Slf4jUser.java │ │ └── resources │ │ │ └── log4j.properties │ │ └── test │ │ └── java │ │ └── demo │ │ └── org │ │ └── powermock │ │ └── examples │ │ └── Slf4jUserTest.java ├── SignedMocking │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── powermock │ │ └── examples │ │ └── AcegiSecurityUser.java ├── jdom │ └── src │ │ └── main │ │ └── java │ │ └── examples │ │ └── jdom │ │ └── StaticClass.java ├── jmock │ └── src │ │ └── main │ │ └── java │ │ └── powermock │ │ └── examples │ │ └── jmock │ │ ├── FinalClass.java │ │ └── ClassWithStaticMethod.java ├── tutorial │ └── src │ │ └── main │ │ └── java │ │ └── demo │ │ └── org │ │ └── powermock │ │ └── examples │ │ └── tutorial │ │ ├── hellopower │ │ └── HelloWorld.java │ │ ├── partialmocking │ │ ├── dao │ │ │ └── domain │ │ │ │ └── Connection.java │ │ └── domain │ │ │ └── DataProducer.java │ │ └── staticmocking │ │ ├── osgi │ │ ├── ServiceRegistration.java │ │ └── BundleContext.java │ │ └── impl │ │ └── IdGenerator.java ├── AbstractFactory │ └── src │ │ └── main │ │ └── java │ │ └── powermock │ │ └── examples │ │ └── service │ │ └── MyService.java ├── java8 │ └── src │ │ └── main │ │ └── java │ │ └── demo │ │ └── org │ │ └── powermock │ │ └── examples │ │ └── SimpleOps.java ├── spring-mockito │ └── src │ │ └── main │ │ └── java │ │ └── powermock │ │ └── examples │ │ └── spring │ │ ├── MyBean.java │ │ ├── IdGenerator.java │ │ └── Message.java └── dom4j │ └── src │ └── main │ └── java │ └── org │ └── powermock │ └── examples │ └── dom4j │ └── XMLProtocol.java ├── .gitignore ├── core └── src │ ├── test │ ├── resources │ │ └── org │ │ │ └── powermock │ │ │ └── core │ │ │ └── classloader │ │ │ └── foo │ │ │ └── bar │ │ │ └── baz │ │ │ └── test.txt │ └── java │ │ └── org │ │ └── powermock │ │ └── core │ │ └── classloader │ │ └── Collaborator.java │ └── main │ └── java │ └── org │ └── powermock │ ├── core │ ├── IndicateReloadClass.java │ ├── spi │ │ ├── testresult │ │ │ ├── Result.java │ │ │ ├── TestMethodResult.java │ │ │ └── TestSuiteResult.java │ │ └── listener │ │ │ └── AnnotationEnablerListener.java │ ├── transformers │ │ └── TransformStrategy.java │ ├── ClassLocator.java │ └── classloader │ │ └── ClassPathAdjuster.java │ └── tests │ └── utils │ ├── ArrayMerger.java │ ├── IgnorePackagesExtractor.java │ └── TestChunk.java ├── api ├── mockito │ └── src │ │ └── main │ │ ├── resources │ │ └── mockito-extensions │ │ │ └── org.mockito.plugins.MockMaker │ │ └── java │ │ └── org │ │ └── powermock │ │ └── api │ │ └── mockito │ │ ├── verification │ │ ├── WithoutVerifiedArguments.java │ │ ├── WithOrWithoutVerifiedArguments.java │ │ ├── WithVerifiedArguments.java │ │ └── ConstructorArgumentsVerification.java │ │ └── expectation │ │ ├── WithOrWithoutExpectedArguments.java │ │ ├── ConstructorExpectationSetup.java │ │ ├── WithAnyArguments.java │ │ ├── WithoutExpectedArguments.java │ │ ├── WithExpectedParameterTypes.java │ │ ├── PrivatelyExpectedArguments.java │ │ └── WithExpectedArguments.java ├── easymock │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── powermock │ │ └── api │ │ ├── easymock │ │ └── internal │ │ │ └── mockstrategy │ │ │ ├── MockStrategy.java │ │ │ └── impl │ │ │ ├── NiceMockStrategy.java │ │ │ ├── StrictMockStrategy.java │ │ │ ├── DefaultMockStrategy.java │ │ │ └── AbstractMockStrategyBase.java │ │ └── extension │ │ └── proxyframework │ │ └── ProxyFrameworkImpl.java ├── pom.xml └── support │ └── src │ └── main │ └── java │ └── org │ └── powermock │ └── api │ └── support │ └── SafeExceptionRethrower.java ├── src └── site │ ├── resources │ └── images │ │ └── logos │ │ ├── jayway.png │ │ └── powermock.png │ └── apt │ └── docs │ └── installing.apt ├── tests ├── utils │ └── src │ │ └── main │ │ └── java │ │ └── samples │ │ ├── suppressfield │ │ ├── DomainObject.java │ │ └── ItemRepository.java │ │ ├── simplereturn │ │ ├── SimpleReturnExample.java │ │ └── SimpleReturnExampleUser.java │ │ ├── singleton │ │ ├── SimpleStaticService.java │ │ ├── StaticWithPrivateCtor.java │ │ └── StaticHelper.java │ │ ├── powermockignore │ │ └── PowerMockIgnoreDemo.java │ │ ├── swing │ │ └── ReallySimpleSwingDemo.java │ │ ├── classhierarchy │ │ ├── ChildA.java │ │ ├── ChildB.java │ │ └── Parent.java │ │ ├── reflection │ │ ├── UseMe.java │ │ ├── UseMeInterface.java │ │ └── ReflectionInstantiator.java │ │ ├── rule │ │ ├── SimpleThing.java │ │ ├── SimpleThingImpl.java │ │ ├── SimpleThingCreator.java │ │ └── ThingToTest.java │ │ ├── anonymousmocking │ │ └── MyAbstractClass.java │ │ ├── finalmocking │ │ ├── HoldingFinalDemo.java │ │ └── StaticHoldingFinalDemo.java │ │ ├── simplemix │ │ ├── SimpleMixConstruction.java │ │ ├── SimpleMixUtilities.java │ │ └── SimpleMixCollaborator.java │ │ ├── java │ │ └── ClassInsideJavaPackage.java │ │ ├── enummocking │ │ └── MyEnum.java │ │ ├── suppressmethod │ │ ├── SuppressMethodParent.java │ │ └── SuppressMethodExample.java │ │ ├── spy │ │ └── SpyObject.java │ │ ├── suppressconstructor │ │ ├── InvokeConstructor.java │ │ ├── SuppressConstructorHeirarchyEvilGrandParent.java │ │ ├── SuppressConstructorSubclassDemo.java │ │ ├── SuppressNonParentConstructorDemo.java │ │ └── SuppressConstructorDemo.java │ │ ├── mockpolicy │ │ ├── SomeClassWithAMethodParent.java │ │ ├── SomeClassWithAMethod.java │ │ ├── SimpleClassWithADependency.java │ │ ├── frameworkexample │ │ │ ├── SimpleFrameworkUser.java │ │ │ ├── NativeResult.java │ │ │ └── SimpleFramework.java │ │ └── ResultCalculator.java │ │ ├── partialmocking │ │ ├── MockWithStaticStateDemo.java │ │ ├── MockSelfDemoSubClass.java │ │ ├── PartialMockingWithConstructor.java │ │ ├── MockSelfWithNoDefaultConstructorDemo.java │ │ ├── MockSelfDemoWithSubClass.java │ │ └── PartialMockingExample.java │ │ ├── newmocking │ │ ├── NewDemo.java │ │ ├── SomeDependency.java │ │ ├── MyClass.java │ │ └── StupidNew.java │ │ ├── expectnew │ │ └── ExpectNewOfFinalSystemClassDemo.java │ │ ├── methodhierarchy │ │ ├── MethodInvocationDemo.java │ │ └── MethodInvocationDemoParent.java │ │ ├── Service.java │ │ ├── strict │ │ └── StrictDemo.java │ │ ├── argumentmatcher │ │ └── ArgumentMatcherDemo.java │ │ ├── nice │ │ └── NiceDemo.java │ │ ├── nativemocking │ │ └── NativeService.java │ │ ├── overloading │ │ └── StaticAndInstanceMethodWithSameName.java │ │ ├── expectvoid │ │ └── ExpectVoidDemo.java │ │ ├── annotationbased │ │ └── AnnotationDemo.java │ │ ├── abstractmocking │ │ └── AbstractMethodMocking.java │ │ ├── interfacemethodfinding │ │ └── WsUtil.java │ │ ├── privateandfinal │ │ └── PrivateFinal.java │ │ ├── staticinitializer │ │ └── SimpleStaticInitializerExample.java │ │ └── injectmocks │ │ └── DependencyHolder.java └── pom.xml ├── modules ├── module-impl │ ├── agent │ │ ├── META-INF │ │ │ └── MANIFEST.MF │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── powermock │ │ │ └── modules │ │ │ └── agent │ │ │ └── support │ │ │ └── SimpleClassCache.java │ └── junit4-common │ │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── powermock │ │ └── modules │ │ └── junit4 │ │ └── common │ │ └── internal │ │ └── PowerMockJUnitRunnerDelegate.java ├── module-test │ ├── easymock │ │ ├── testng-test │ │ │ ├── src │ │ │ │ └── test │ │ │ │ │ └── java │ │ │ │ │ └── samples │ │ │ │ │ └── testng │ │ │ │ │ ├── DocumentBuilderFactoryTest.java │ │ │ │ │ └── FinalTest.java │ │ │ └── suite.xml │ │ ├── junit4-test │ │ │ └── src │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── samples │ │ │ │ └── junit4 │ │ │ │ ├── assume │ │ │ │ └── AssumeTest.java │ │ │ │ ├── noannotation │ │ │ │ ├── SetUpIsOnlyCalledOnceWhenExtendingTestCaseTest.java │ │ │ │ ├── SetUpAndTearDownWhenNotExtendingTestCaseTest.java │ │ │ │ └── SetUpAndTearDownWhenExtendingTestCaseTest.java │ │ │ │ ├── nice │ │ │ │ └── NiceDemoTest.java │ │ │ │ ├── misc │ │ │ │ └── PrivateInnerInterfacesInTestClassTest.java │ │ │ │ ├── testhierarchy │ │ │ │ └── TestParent.java │ │ │ │ ├── enummocking │ │ │ │ └── EnumMockingTest.java │ │ │ │ ├── abstractmocking │ │ │ │ └── AbstractMethodMockingTest.java │ │ │ │ ├── simplereturn │ │ │ │ └── SimpleReturnExampleUserTest.java │ │ │ │ ├── expectnew │ │ │ │ └── ExpectNewOfFinalSystemClassTest.java │ │ │ │ └── stackoverflow │ │ │ │ └── EvilHashCode.java │ │ ├── junit410-test │ │ │ └── src │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── samples │ │ │ │ └── junit410 │ │ │ │ └── assume │ │ │ │ └── AssumeForJUnit410Test.java │ │ ├── junit45-test │ │ │ └── src │ │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── demo │ │ │ │ └── org │ │ │ │ └── powermock │ │ │ │ └── modules │ │ │ │ └── test │ │ │ │ └── junit45 │ │ │ │ └── failure │ │ │ │ ├── MyUtils.java │ │ │ │ ├── MyException.java │ │ │ │ └── MyClass.java │ │ ├── junit4-legacy-test │ │ │ └── src │ │ │ │ └── test │ │ │ │ └── java │ │ │ │ └── samples │ │ │ │ └── junit4 │ │ │ │ └── legacy │ │ │ │ └── noannotation │ │ │ │ ├── SetUpAndTearDownWhenNotExtendingTestCaseTest.java │ │ │ │ └── SetUpAndTearDownWhenExtendingTestCaseTest.java │ │ └── testng-agent-test │ │ │ └── suite.xml │ ├── pom.xml │ └── mockito │ │ └── junit4 │ │ ├── pom.xml │ │ └── src │ │ └── test │ │ └── java │ │ └── samples │ │ └── powermockito │ │ └── junit4 │ │ └── FinalEqualsClass.java └── pom.xml ├── classloading ├── classloading-base │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── powermock │ │ └── classloading │ │ └── spi │ │ ├── DeepClonerSPI.java │ │ └── DoNotClone.java ├── classloading-objenesis │ └── src │ │ └── test │ │ └── java │ │ └── powermock │ │ └── classloading │ │ └── classes │ │ ├── MyEnum.java │ │ ├── MyStaticFinalNumberHolder.java │ │ ├── MyStaticFinalPrimitiveHolder.java │ │ ├── MyStaticFinalArgumentHolder.java │ │ ├── MyHierarchicalFieldHolder.java │ │ ├── MyEnumHolder.java │ │ ├── MyIntegerHolder.java │ │ ├── MyPrimitiveArrayHolder.java │ │ └── MyHierarchicalOverloadedFieldHolder.java ├── classloading-xstream │ └── src │ │ └── test │ │ └── java │ │ └── powermock │ │ └── classloading │ │ └── classes │ │ ├── MyEnum.java │ │ ├── MyStaticFinalNumberHolder.java │ │ ├── MyStaticFinalPrimitiveHolder.java │ │ ├── MyStaticFinalArgumentHolder.java │ │ ├── MyHierarchicalFieldHolder.java │ │ ├── MyEnumHolder.java │ │ ├── MyIntegerHolder.java │ │ ├── MyPrimitiveArrayHolder.java │ │ └── MyHierarchicalOverloadedFieldHolder.java └── pom.xml ├── release ├── with-junit-mockito-dependencies │ └── src │ │ └── assembly │ │ └── final.xml ├── with-junit-easymock-dependencies │ └── src │ │ └── assembly │ │ └── final.xml ├── with-testng-easymock-dependencies │ └── src │ │ └── assembly │ │ └── final.xml ├── with-testng-mockito-dependencies │ └── src │ │ └── assembly │ │ └── final.xml ├── mockito-extension-api-full │ └── src │ │ └── assembly │ │ └── full.xml ├── easymock-extension-api-full │ └── src │ │ └── assembly │ │ └── full.xml ├── junit-without-mock-framework │ └── src │ │ └── assembly │ │ └── full.xml ├── testng-without-mock-framework │ └── src │ │ └── assembly │ │ └── full.xml └── without-test-and-mock-framework │ └── src │ └── assembly │ └── full.xml └── reflect └── src ├── main └── java │ └── org │ └── powermock │ └── reflect │ ├── proxyframework │ └── RegisterProxyFramework.java │ └── spi │ └── ProxyFramework.java └── test └── java └── org └── powermock └── reflect ├── testclasses ├── Parent.java ├── AnInterface.java ├── Child.java ├── AbstractClass.java ├── ClassWithStandardMethod.java ├── ClassWithMethodUsingSuperTypeArgument.java ├── ClassWithChildThatHasInternalState.java ├── ClassWithList.java ├── ClassWithOverriddenMethod.java ├── ClassWithAMethod.java ├── ClassWithSeveralMethodsWithSameName.java ├── ClassWithOverloadedMethods.java ├── ClassWithVarArgsConstructor.java ├── ClassWithSeveralMethodsWithSameNameOneWithoutParameters.java └── ClassWithSimpleStateOfSameType.java └── context ├── MyIntContext.java └── MyStringContext.java /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | -------------------------------------------------------------------------------- /examples/simple/src/main/java/simpleConfig.properties: -------------------------------------------------------------------------------- 1 | greeting=Hello 2 | target=World -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *.iws 3 | *.ipr 4 | *.iml 5 | .classpath 6 | .project 7 | .settings 8 | .springBeans 9 | repo -------------------------------------------------------------------------------- /core/src/test/resources/org/powermock/core/classloader/foo/bar/baz/test.txt: -------------------------------------------------------------------------------- 1 | This is the droid that you are looking for... -------------------------------------------------------------------------------- /api/mockito/src/main/resources/mockito-extensions/org.mockito.plugins.MockMaker: -------------------------------------------------------------------------------- 1 | org.powermock.api.mockito.internal.mockmaker.PowerMockMaker -------------------------------------------------------------------------------- /src/site/resources/images/logos/jayway.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/powermock/HEAD/src/site/resources/images/logos/jayway.png -------------------------------------------------------------------------------- /src/site/resources/images/logos/powermock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebookarchive/powermock/HEAD/src/site/resources/images/logos/powermock.png -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/suppressfield/DomainObject.java: -------------------------------------------------------------------------------- 1 | package samples.suppressfield; 2 | 3 | public class DomainObject { 4 | 5 | public DomainObject() { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/simplereturn/SimpleReturnExample.java: -------------------------------------------------------------------------------- 1 | package samples.simplereturn; 2 | 3 | public class SimpleReturnExample { 4 | 5 | public int mySimpleMethod() { 6 | return 44; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/DocumentationExamples/src/main/java/powermock/examples/partialmocking/Status.java: -------------------------------------------------------------------------------- 1 | package powermock.examples.partialmocking; 2 | 3 | /** 4 | * Created by Katharina Laube on 08.09.2014. 5 | */ 6 | public class Status { 7 | } 8 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/singleton/SimpleStaticService.java: -------------------------------------------------------------------------------- 1 | package samples.singleton; 2 | 3 | public class SimpleStaticService { 4 | 5 | public static String say(final String string) { 6 | return "Hello " + string; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /modules/module-impl/agent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Premain-Class: org.powermock.modules.agent.PowerMockAgent 3 | Agent-Class: org.powermock.modules.agent.PowerMockAgent 4 | Can-Retransform-Classes: true 5 | Can-Redefine-Classes: true 6 | -------------------------------------------------------------------------------- /classloading/classloading-base/src/main/java/org/powermock/classloading/spi/DeepClonerSPI.java: -------------------------------------------------------------------------------- 1 | package org.powermock.classloading.spi; 2 | 3 | /** 4 | * A deep-cloner must implement this interface. 5 | */ 6 | public interface DeepClonerSPI { 7 | T clone(T objectToClone); 8 | } 9 | -------------------------------------------------------------------------------- /examples/log4j/src/main/java/demo/org/powermock/examples/Log4jUserParent.java: -------------------------------------------------------------------------------- 1 | package demo.org.powermock.examples; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | public class Log4jUserParent { 6 | protected static final Logger log = Logger.getLogger(Log4jUserParent.class); 7 | } 8 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/powermockignore/PowerMockIgnoreDemo.java: -------------------------------------------------------------------------------- 1 | package samples.powermockignore; 2 | 3 | import javax.swing.*; 4 | 5 | public class PowerMockIgnoreDemo { 6 | 7 | public void showDialog() { 8 | JOptionPane.showInputDialog("Input:"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/swing/ReallySimpleSwingDemo.java: -------------------------------------------------------------------------------- 1 | package samples.swing; 2 | 3 | import javax.swing.*; 4 | 5 | public class ReallySimpleSwingDemo { 6 | 7 | public void displayMessage(String message) { 8 | JOptionPane.showMessageDialog(null, message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /api/easymock/src/main/java/org/powermock/api/easymock/internal/mockstrategy/MockStrategy.java: -------------------------------------------------------------------------------- 1 | package org.powermock.api.easymock.internal.mockstrategy; 2 | 3 | import org.easymock.IMocksControl; 4 | 5 | public interface MockStrategy { 6 | 7 | IMocksControl createMockControl(Class type); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /examples/DocumentationExamples/src/main/java/powermock/examples/partialmocking/EntityManager.java: -------------------------------------------------------------------------------- 1 | package powermock.examples.partialmocking; 2 | 3 | /** 4 | * Created by Katharina Laube on 08.09.2014. 5 | */ 6 | public class EntityManager { 7 | public void persist(Status status) { 8 | // persist status 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/HamcrestExample/src/main/java/org/powermock/hamcrest/HamcrestExample.java: -------------------------------------------------------------------------------- 1 | package org.powermock.hamcrest; 2 | 3 | /** 4 | * A very simple class that's used just to assert that PowerMock works together 5 | * with Hamcrest. 6 | */ 7 | public class HamcrestExample { 8 | 9 | public static String getString() { 10 | return "hamcrest"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /api/easymock/src/main/java/org/powermock/api/easymock/internal/mockstrategy/impl/NiceMockStrategy.java: -------------------------------------------------------------------------------- 1 | package org.powermock.api.easymock.internal.mockstrategy.impl; 2 | 3 | import org.easymock.internal.MocksControl.MockType; 4 | 5 | public class NiceMockStrategy extends AbstractMockStrategyBase { 6 | 7 | public NiceMockStrategy() { 8 | super(MockType.NICE); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /api/easymock/src/main/java/org/powermock/api/easymock/internal/mockstrategy/impl/StrictMockStrategy.java: -------------------------------------------------------------------------------- 1 | package org.powermock.api.easymock.internal.mockstrategy.impl; 2 | 3 | import org.easymock.internal.MocksControl.MockType; 4 | 5 | public class StrictMockStrategy extends AbstractMockStrategyBase { 6 | 7 | public StrictMockStrategy() { 8 | super(MockType.STRICT); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /api/easymock/src/main/java/org/powermock/api/easymock/internal/mockstrategy/impl/DefaultMockStrategy.java: -------------------------------------------------------------------------------- 1 | package org.powermock.api.easymock.internal.mockstrategy.impl; 2 | 3 | import org.easymock.internal.MocksControl.MockType; 4 | 5 | public class DefaultMockStrategy extends AbstractMockStrategyBase { 6 | 7 | public DefaultMockStrategy() { 8 | super(MockType.DEFAULT); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/slf4j-noimpl/src/main/java/demo/org/powermock/examples/SL4JUser.java: -------------------------------------------------------------------------------- 1 | package demo.org.powermock.examples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | 7 | public class SL4JUser { 8 | final Logger logger = LoggerFactory.getLogger(SL4JUser.class); 9 | 10 | public boolean returnTrue() { 11 | logger.info("ikk"); 12 | return true; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/spring-mockito-xml/src/main/resources/employees.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | John 5 | Doe 6 | 7 | 8 | Paul 9 | Anderson 10 | 11 | 12 | Jane 13 | Doe 14 | 15 | -------------------------------------------------------------------------------- /examples/spring-mockito-xml-agent/src/main/resources/employees.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | John 5 | Doe 6 | 7 | 8 | Paul 9 | Anderson 10 | 11 | 12 | Jane 13 | Doe 14 | 15 | -------------------------------------------------------------------------------- /release/with-junit-mockito-dependencies/src/assembly/final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | zip 4 | 5 | true 6 | 7 | 8 | 9 | false 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/jcl/src/main/java/org/powermock/examples/JclUser.java: -------------------------------------------------------------------------------- 1 | package org.powermock.examples; 2 | 3 | import org.apache.commons.logging.Log; 4 | import org.apache.commons.logging.LogFactory; 5 | 6 | public class JclUser { 7 | private static final Log log = LogFactory.getLog(JclUser.class); 8 | 9 | public final String getMessage() { 10 | log.debug("getMessage!"); 11 | return "log4j user"; 12 | } 13 | } -------------------------------------------------------------------------------- /release/with-junit-easymock-dependencies/src/assembly/final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | zip 4 | 5 | true 6 | 7 | 8 | 9 | false 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /release/with-testng-easymock-dependencies/src/assembly/final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | zip 4 | 5 | true 6 | 7 | 8 | 9 | false 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /release/with-testng-mockito-dependencies/src/assembly/final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | zip 4 | 5 | true 6 | 7 | 8 | 9 | false 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/slf4j/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=WARN, R 2 | log4j.appender.R=org.apache.log4j.RollingFileAppender 3 | log4j.appender.R.File=${catalina.home}/logs/admin-webapp.log 4 | log4j.appender.R.File.Suffix= 5 | log4j.appender.R.MaxFileSize=10MB 6 | log4j.appender.R.MaxBackupIndex=10 7 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.R.layout.ConversionPattern=%p %d{ABSOLUTE} %c:%L %x - %m%n -------------------------------------------------------------------------------- /examples/slf4j-mockito/src/main/java/demo/org/powermock/examples/Slf4jUser.java: -------------------------------------------------------------------------------- 1 | package demo.org.powermock.examples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | public class Slf4jUser { 7 | private static final Logger log = LoggerFactory.getLogger(Slf4jUser.class); 8 | 9 | public final String getMessage() { 10 | log.debug("getMessage!"); 11 | return "log4j user"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/slf4j-mockito/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=WARN, R 2 | log4j.appender.R=org.apache.log4j.RollingFileAppender 3 | log4j.appender.R.File=${catalina.home}/logs/admin-webapp.log 4 | log4j.appender.R.File.Suffix= 5 | log4j.appender.R.MaxFileSize=10MB 6 | log4j.appender.R.MaxBackupIndex=10 7 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.R.layout.ConversionPattern=%p %d{ABSOLUTE} %c:%L %x - %m%n -------------------------------------------------------------------------------- /examples/slf4j/src/main/java/demo/org/powermock/examples/Slf4jUser.java: -------------------------------------------------------------------------------- 1 | package demo.org.powermock.examples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | public class Slf4jUser { 7 | private static final Logger log = LoggerFactory.getLogger(Slf4jUser.class); 8 | 9 | public final String getMessage() { 10 | log.debug("getMessage!"); 11 | return "log4j user"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/log4j/src/main/java/demo/org/powermock/examples/Log4jUser.java: -------------------------------------------------------------------------------- 1 | package demo.org.powermock.examples; 2 | 3 | 4 | public class Log4jUser extends Log4jUserParent{ 5 | 6 | public final String getMessage() { 7 | log.debug("getMessage!"); 8 | return "log4j user"; 9 | } 10 | 11 | public String mergeMessageWith(String otherMessage) { 12 | log.debug("mergeMessageWith!"); 13 | return getMessage() + otherMessage; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /modules/module-test/easymock/testng-test/src/test/java/samples/testng/DocumentBuilderFactoryTest.java: -------------------------------------------------------------------------------- 1 | package samples.testng; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import javax.xml.parsers.DocumentBuilderFactory; 6 | 7 | public class DocumentBuilderFactoryTest { 8 | 9 | @Test 10 | public void classesNotAnnotatedWithPrepareForTestAreNotLoadedByByPowerMockCl() throws Exception { 11 | DocumentBuilderFactory.newInstance(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/simplereturn/SimpleReturnExampleUser.java: -------------------------------------------------------------------------------- 1 | package samples.simplereturn; 2 | 3 | public class SimpleReturnExampleUser { 4 | 5 | private SimpleReturnExample simpleReturnExample; 6 | 7 | public SimpleReturnExampleUser(SimpleReturnExample intReturn2) { 8 | super(); 9 | this.simpleReturnExample = intReturn2; 10 | } 11 | 12 | public int myMethod() { 13 | return simpleReturnExample.mySimpleMethod(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/assume/AssumeTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.assume; 2 | 3 | import org.junit.Assume; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.powermock.modules.junit4.PowerMockRunner; 7 | 8 | import static org.junit.Assume.assumeTrue; 9 | 10 | @RunWith(PowerMockRunner.class) 11 | public class AssumeTest { 12 | 13 | @Test 14 | public void assumesWorkWithPowerMockForJUnit44() throws Exception { 15 | // When 16 | assumeTrue(false); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit410-test/src/test/java/samples/junit410/assume/AssumeForJUnit410Test.java: -------------------------------------------------------------------------------- 1 | package samples.junit410.assume; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.modules.junit4.PowerMockRunner; 6 | 7 | import static org.junit.Assume.assumeTrue; 8 | 9 | @RunWith(PowerMockRunner.class) 10 | public class AssumeForJUnit410Test { 11 | 12 | @Test 13 | public void assumesWorkWithPowerMockForJUnit410() throws Exception { 14 | // When 15 | assumeTrue(false); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /release/mockito-extension-api-full/src/assembly/full.xml: -------------------------------------------------------------------------------- 1 | 2 | full 3 | 4 | jar 5 | 6 | false 7 | 8 | 9 | 10 | 11 | true 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /release/easymock-extension-api-full/src/assembly/full.xml: -------------------------------------------------------------------------------- 1 | 2 | full 3 | 4 | jar 5 | 6 | false 7 | 8 | 9 | 10 | 11 | true 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /release/junit-without-mock-framework/src/assembly/full.xml: -------------------------------------------------------------------------------- 1 | 2 | full 3 | 4 | jar 5 | 6 | false 7 | 8 | 9 | 10 | 11 | true 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /release/testng-without-mock-framework/src/assembly/full.xml: -------------------------------------------------------------------------------- 1 | 2 | full 3 | 4 | jar 5 | 6 | false 7 | 8 | 9 | 10 | 11 | true 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /release/without-test-and-mock-framework/src/assembly/full.xml: -------------------------------------------------------------------------------- 1 | 2 | full 3 | 4 | jar 5 | 6 | false 7 | 8 | 9 | 10 | 11 | true 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/noannotation/SetUpIsOnlyCalledOnceWhenExtendingTestCaseTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.noannotation; 2 | 3 | import junit.framework.TestCase; 4 | import org.junit.Before; 5 | 6 | public class SetUpIsOnlyCalledOnceWhenExtendingTestCaseTest extends TestCase { 7 | 8 | private int state = 0; 9 | 10 | @Before 11 | @Override 12 | public void setUp() throws Exception { 13 | state++; 14 | } 15 | 16 | public void testSetupMethodIsOnlyCalledOnceWhenExtendingFromTestCase() throws Exception { 17 | assertEquals(1, state); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /reflect/src/main/java/org/powermock/reflect/proxyframework/RegisterProxyFramework.java: -------------------------------------------------------------------------------- 1 | package org.powermock.reflect.proxyframework; 2 | 3 | import org.powermock.reflect.internal.WhiteboxImpl; 4 | import org.powermock.reflect.spi.ProxyFramework; 5 | 6 | /** 7 | * All API's must register a proxy framework using this class. 8 | */ 9 | public class RegisterProxyFramework { 10 | 11 | /** 12 | * Register a proxy framework. 13 | * 14 | * @param proxyFramework 15 | * The proxy framework to register. 16 | */ 17 | public static void registerProxyFramework(ProxyFramework proxyFramework) { 18 | WhiteboxImpl.setInternalState(WhiteboxImpl.class, proxyFramework); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/HamcrestExample/src/test/java/org/powermock/hamcrest/HamcrestExampleTest.java: -------------------------------------------------------------------------------- 1 | package org.powermock.hamcrest; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.modules.junit4.PowerMockRunner; 6 | 7 | import static org.hamcrest.CoreMatchers.is; 8 | import static org.junit.Assert.assertThat; 9 | 10 | /** 11 | * A simple test case that asserts the PowerMock works together with Hamcrest 12 | * matchers. 13 | */ 14 | @RunWith(PowerMockRunner.class) 15 | public class HamcrestExampleTest { 16 | 17 | @Test 18 | public void testGetString() throws Exception { 19 | assertThat("File extension", HamcrestExample.getString(), is("hamcrest")); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /reflect/src/main/java/org/powermock/reflect/spi/ProxyFramework.java: -------------------------------------------------------------------------------- 1 | package org.powermock.reflect.spi; 2 | 3 | /** 4 | * The purpose of a the proxy framework implementation is to return the 5 | * unproxied types of classes. 6 | */ 7 | public interface ProxyFramework { 8 | 9 | /** 10 | * Check if the class is a proxy and if it is return the unproxied type. 11 | * 12 | * @param type 13 | * The class to check. 14 | * @return The unproxied class type. 15 | */ 16 | Class getUnproxiedType(Class type); 17 | 18 | /** 19 | * @return true if type is a proxy, false 20 | * otherwise. 21 | */ 22 | boolean isProxy(Class type); 23 | } 24 | -------------------------------------------------------------------------------- /examples/DocumentationExamples/src/main/java/powermock/examples/partialmocking/StatusSender.java: -------------------------------------------------------------------------------- 1 | package powermock.examples.partialmocking; 2 | 3 | /** 4 | * Used to demonstrate PowerMock's ability to partial mock method calls. 5 | * 6 | * Created by Katharina Laube on 08.09.2014. 7 | */ 8 | public class StatusSender { 9 | 10 | EntityManager entityManager = new EntityManager(); 11 | 12 | public boolean handleStatus(Status status){ 13 | 14 | entityManager.persist(status); 15 | 16 | return sendStatus(status); 17 | } 18 | 19 | public boolean sendStatus(Status status){ 20 | // code that will not be tested with handleStatus method 21 | // (i.e. send status via a topic) 22 | return false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /modules/module-impl/agent/src/main/java/org/powermock/modules/agent/support/SimpleClassCache.java: -------------------------------------------------------------------------------- 1 | package org.powermock.modules.agent.support; 2 | 3 | import java.util.LinkedList; 4 | 5 | class SimpleClassCache { 6 | private final LinkedList cache = new LinkedList(); 7 | private final int cacheSize; 8 | 9 | SimpleClassCache(int cacheSize) { 10 | this.cacheSize = cacheSize; 11 | } 12 | 13 | public synchronized boolean addIfNotCached(String className) { 14 | if(cache.contains(className)) { 15 | return false; 16 | } 17 | 18 | if(cache.size() == cacheSize) { 19 | cache.removeFirst(); 20 | } 21 | 22 | cache.add(className); 23 | return true; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /examples/spring-mockito-xml-agent/src/test/java/org/powermock/modules/agent/AbstractClassTransformerTest.java: -------------------------------------------------------------------------------- 1 | package org.powermock.modules.agent; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.hamcrest.CoreMatchers.equalTo; 6 | import static org.junit.Assert.assertThat; 7 | 8 | public class AbstractClassTransformerTest { 9 | 10 | @Test public void 11 | replace_slash_with_dots_method_replaces_slashes_with_dots() { 12 | // Given 13 | AbstractClassTransformer abstractClassTransformer = new AbstractClassTransformer() { }; 14 | 15 | // When 16 | String replaced = abstractClassTransformer.replaceSlashWithDots("org/powermock/core/Main"); 17 | 18 | // Then 19 | assertThat(replaced, equalTo("org.powermock.core.Main")); 20 | } 21 | } -------------------------------------------------------------------------------- /examples/SignedMocking/src/main/java/org/powermock/examples/AcegiSecurityUser.java: -------------------------------------------------------------------------------- 1 | package org.powermock.examples; 2 | 3 | import org.acegisecurity.acl.basic.BasicAclEntry; 4 | import org.acegisecurity.acl.basic.cache.NullAclEntryCache; 5 | 6 | /** 7 | * A simple naive example of a class that uses a dependency in the Acegi 8 | * Security framework (which is signed). Using plain EasyMock you'd would not be 9 | * able to mock a class located in the Acegi Security jar file. 10 | */ 11 | public class AcegiSecurityUser { 12 | 13 | private NullAclEntryCache cache; 14 | 15 | public AcegiSecurityUser(NullAclEntryCache cache) { 16 | this.cache = cache; 17 | } 18 | 19 | public BasicAclEntry[] getDecisionVoters() { 20 | return cache.getEntriesFromCache(null); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/slf4j-noimpl/src/test/java/demo/org/powermock/examples/SPITest.java: -------------------------------------------------------------------------------- 1 | package demo.org.powermock.examples; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import demo.org.powermock.examples.SL4JUser; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.powermock.api.easymock.mockpolicies.Slf4jMockPolicy; 9 | import org.powermock.core.classloader.annotations.MockPolicy; 10 | import org.powermock.modules.junit4.PowerMockRunner; 11 | 12 | 13 | @RunWith(PowerMockRunner.class) 14 | @MockPolicy(Slf4jMockPolicy.class) 15 | public class SPITest { 16 | 17 | @Test 18 | public void powerMockCanLoadClassesThatHaveMethodsAndFieldsReturningClassesThatAreNotInClasspath() throws Exception { 19 | SL4JUser obj = new SL4JUser(); 20 | assertTrue(obj.returnTrue()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/core/IndicateReloadClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.core; 17 | 18 | public class IndicateReloadClass { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/Parent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | public class Parent { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/classhierarchy/ChildA.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.classhierarchy; 17 | 18 | public class ChildA extends Parent { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/classhierarchy/ChildB.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.classhierarchy; 17 | 18 | public class ChildB extends Parent { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/reflection/UseMe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package samples.reflection; 18 | 19 | public class UseMe implements UseMeInterface { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/nice/NiceDemoTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.nice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.modules.junit4.PowerMockRunner; 6 | import samples.nice.NiceDemo; 7 | 8 | import static org.powermock.api.easymock.PowerMock.*; 9 | 10 | /** 11 | * This is a simple test case for the {@link NiceDemo} class that demonstrates 12 | * that strict method mocking works. 13 | * 14 | */ 15 | @RunWith(PowerMockRunner.class) 16 | public class NiceDemoTest { 17 | 18 | @Test 19 | public void testCallAThenB_noExpectations() throws Exception { 20 | NiceDemo tested = createNicePartialMock(NiceDemo.class, "A", "B"); 21 | 22 | replay(tested); 23 | 24 | tested.callAThenB(); 25 | 26 | verify(tested); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/reflection/UseMeInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package samples.reflection; 19 | 20 | public interface UseMeInterface { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/AnInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | public interface AnInterface { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/Child.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | public class Child extends Parent { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/AbstractClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | public abstract class AbstractClass { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/rule/SimpleThing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package samples.rule; 18 | 19 | public interface SimpleThing { 20 | String getThingName(); 21 | } 22 | -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/core/spi/testresult/Result.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.core.spi.testresult; 17 | 18 | public enum Result { 19 | SUCCESSFUL, FAILED, IGNORED; 20 | } -------------------------------------------------------------------------------- /examples/jdom/src/main/java/examples/jdom/StaticClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package examples.jdom; 17 | 18 | 19 | public class StaticClass { 20 | static int staticMethod() { 21 | return 1; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | powermock 5 | org.powermock 6 | 1.5.7-SNAPSHOT 7 | 8 | 4.0.0 9 | org.powermock.tests 10 | powermock-tests 11 | pom 12 | powermock-tests 13 | 14 | 15 | Common tests for PowerMock core and modules for mocking frameworks. 16 | 17 | 18 | 19 | utils 20 | 21 | 22 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/anonymousmocking/MyAbstractClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.anonymousmocking; 17 | 18 | public abstract class MyAbstractClass { 19 | public abstract String getMessage(); 20 | } 21 | -------------------------------------------------------------------------------- /classloading/classloading-objenesis/src/test/java/powermock/classloading/classes/MyEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package powermock.classloading.classes; 18 | 19 | public enum MyEnum { 20 | 21 | MyEnum1, MyEnum2 22 | 23 | } 24 | -------------------------------------------------------------------------------- /classloading/classloading-xstream/src/test/java/powermock/classloading/classes/MyEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package powermock.classloading.classes; 18 | 19 | public enum MyEnum { 20 | 21 | MyEnum1, MyEnum2 22 | 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/core/spi/testresult/TestMethodResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.core.spi.testresult; 17 | 18 | public interface TestMethodResult { 19 | 20 | Result getResult(); 21 | } 22 | -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/core/transformers/TransformStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.powermock.core.transformers; 18 | 19 | public enum TransformStrategy { 20 | CLASSLOADER, INST_REDEFINE, INST_TRANSFORM; 21 | } 22 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/finalmocking/HoldingFinalDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.finalmocking; 17 | 18 | public final class HoldingFinalDemo { 19 | 20 | public FinalDemo getFinalDemo() { 21 | return null; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/simplemix/SimpleMixConstruction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.simplemix; 17 | 18 | public class SimpleMixConstruction { 19 | 20 | public int getMyValue() { 21 | return 4; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /modules/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | powermock 5 | org.powermock 6 | 1.5.7-SNAPSHOT 7 | 8 | 4.0.0 9 | org.powermock 10 | powermock-modules 11 | pom 12 | powermock-modules 13 | 14 | 15 | Aggregator for building PowerMock implementation and test modules. 16 | 17 | 18 | 19 | module-impl 20 | module-test 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/finalmocking/StaticHoldingFinalDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.finalmocking; 17 | 18 | public class StaticHoldingFinalDemo { 19 | 20 | public static FinalDemo getFinalDemo() { 21 | return null; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | powermock 5 | org.powermock 6 | 1.5.7-SNAPSHOT 7 | 8 | 4.0.0 9 | org.powermock 10 | powermock-api 11 | pom 12 | powermock-api 13 | 14 | 15 | The mocking framework-specific interfaces to PowerMock. 16 | 17 | 18 | 19 | easymock 20 | mockito 21 | support 22 | 23 | 24 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/java/ClassInsideJavaPackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.java; 17 | 18 | public final class ClassInsideJavaPackage { 19 | 20 | public final String mockMe() { 21 | return "string"; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/suppressfield/ItemRepository.java: -------------------------------------------------------------------------------- 1 | package samples.suppressfield; 2 | 3 | import java.util.HashMap; 4 | 5 | public class ItemRepository { 6 | private static HashMap itemMap = new HashMap(); 7 | 8 | @SuppressWarnings("unused") 9 | private MyClass myClass = new MyClass(); 10 | 11 | private int totalItems = 0; 12 | 13 | public void addItem(String key, String value) { 14 | itemMap.put(key, value); 15 | totalItems++; 16 | } 17 | 18 | public void delItem(String key) { 19 | if (itemMap.containsKey(key)) { 20 | itemMap.remove(key); 21 | totalItems--; 22 | } 23 | } 24 | 25 | private static class MyClass { 26 | public MyClass() { 27 | throw new IllegalArgumentException("Constructor should never be called during this test"); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /core/src/test/java/org/powermock/core/classloader/Collaborator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.core.classloader; 17 | 18 | public class Collaborator { 19 | private int count; 20 | 21 | public void doStuff(int indx) { 22 | count += indx; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/verification/WithoutVerifiedArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.mockito.verification; 17 | 18 | public interface WithoutVerifiedArguments { 19 | 20 | public void withNoArguments() throws Exception; 21 | 22 | } -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/core/ClassLocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.core; 17 | 18 | public class ClassLocator extends SecurityManager { 19 | public static Class getCallerClass() { 20 | return new ClassLocator().getClassContext()[4]; 21 | } 22 | } -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/enummocking/MyEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.enummocking; 17 | 18 | public enum MyEnum { 19 | 20 | MY_VALUE; 21 | 22 | public static String getString() { 23 | return MY_VALUE.toString(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/suppressmethod/SuppressMethodParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package samples.suppressmethod; 18 | 19 | public abstract class SuppressMethodParent { 20 | 21 | public int myMethod() { 22 | return 42; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/rule/SimpleThingImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package samples.rule; 18 | 19 | public class SimpleThingImpl implements SimpleThing { 20 | 21 | public String getThingName() { 22 | return null; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/verification/WithOrWithoutVerifiedArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.mockito.verification; 17 | 18 | public interface WithOrWithoutVerifiedArguments extends WithVerifiedArguments, WithoutVerifiedArguments { 19 | } 20 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/noannotation/SetUpAndTearDownWhenNotExtendingTestCaseTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.noannotation; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.modules.junit4.PowerMockRunner; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | import static org.junit.Assert.fail; 9 | 10 | @RunWith(PowerMockRunner.class) 11 | public class SetUpAndTearDownWhenNotExtendingTestCaseTest { 12 | private static final String INITIAL_MESSAGE = ""; 13 | private static String CURRENT_MESSAGE = INITIAL_MESSAGE; 14 | 15 | public void setUp() throws Exception { 16 | fail("Should not call setUp"); 17 | } 18 | 19 | public void tearDown() throws Exception { 20 | fail("Should not call tearDown"); 21 | } 22 | 23 | @Test 24 | public void testSomething() throws Exception { 25 | assertEquals(INITIAL_MESSAGE, CURRENT_MESSAGE); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/expectation/WithOrWithoutExpectedArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.mockito.expectation; 17 | 18 | public interface WithOrWithoutExpectedArguments extends WithExpectedArguments, WithoutExpectedArguments { 19 | } 20 | -------------------------------------------------------------------------------- /modules/module-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | powermock 5 | org.powermock 6 | 1.5.7-SNAPSHOT 7 | ../../pom.xml 8 | 9 | 4.0.0 10 | org.powermock 11 | powermock-modules-test 12 | pom 13 | powermock-modules-test 14 | 15 | 16 | Tests for mocking framework modules. 17 | 18 | 19 | 20 | easymock 21 | mockito 22 | 23 | 24 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/rule/SimpleThingCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package samples.rule; 18 | 19 | public class SimpleThingCreator { 20 | 21 | public static SimpleThing createSimpleThing() { 22 | return new SimpleThingImpl(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/spy/SpyObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.spy; 17 | 18 | public class SpyObject { 19 | 20 | public String getMyString() { 21 | return "something"; 22 | } 23 | 24 | public String getStringTwo() { 25 | return "two"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/suppressconstructor/InvokeConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.suppressconstructor; 17 | 18 | public class InvokeConstructor { 19 | 20 | public String doStuff(String m) { 21 | return new SuppressConstructorHierarchy(m).getMessage(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/misc/PrivateInnerInterfacesInTestClassTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.misc; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.core.classloader.annotations.PrepareForTest; 6 | import org.powermock.modules.junit4.PowerMockRunner; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | @RunWith(PowerMockRunner.class) 11 | @PrepareForTest( { PrivateInnerInterfacesInTestClassTest.class }) 12 | public class PrivateInnerInterfacesInTestClassTest { 13 | 14 | @Test 15 | public void privateInterfacesCanBeLoadedAndBytcodeManipulatedByPowerMock() throws Exception { 16 | InnerInterface innerInterface = new InnerInterface() { 17 | public String aMethod() { 18 | return "ok"; 19 | } 20 | }; 21 | assertEquals("ok", innerInterface.aMethod()); 22 | } 23 | 24 | private interface InnerInterface { 25 | String aMethod(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/mockpolicy/SomeClassWithAMethodParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.mockpolicy; 17 | 18 | public class SomeClassWithAMethodParent { 19 | 20 | public double getResult() { 21 | return new ResultCalculator(4).calculate(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/partialmocking/MockWithStaticStateDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.partialmocking; 17 | 18 | public class MockWithStaticStateDemo { 19 | 20 | private static final int state = 5; 21 | 22 | public static int getState() { 23 | return state; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/jmock/src/main/java/powermock/examples/jmock/FinalClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package powermock.examples.jmock; 18 | 19 | /** 20 | * Example of a final class 21 | */ 22 | public final class FinalClass { 23 | 24 | public String helloWorld() { 25 | return "Hello world"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithStandardMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.powermock.reflect.testclasses; 18 | 19 | public class ClassWithStandardMethod { 20 | 21 | public boolean myMethod(double value) { 22 | return true; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /classloading/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | powermock 5 | org.powermock 6 | 1.5.7-SNAPSHOT 7 | 8 | 4.0.0 9 | org.powermock 10 | powermock-classloading-module 11 | pom 12 | powermock-classloading-module 13 | 14 | 15 | PowerMock Classloading Module 16 | 17 | 18 | 19 | classloading-base 20 | classloading-objenesis 21 | classloading-xstream 22 | 23 | 24 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit45-test/src/main/java/demo/org/powermock/modules/test/junit45/failure/MyUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo.org.powermock.modules.test.junit45.failure; 17 | 18 | public class MyUtils { 19 | 20 | public static boolean isValid(int a) { 21 | return a > 10; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/newmocking/NewDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package samples.newmocking; 18 | 19 | public final class NewDemo { 20 | 21 | public void methodUnderTest() 22 | { 23 | SomeDependency loadingPool = new SomeDependency(); 24 | loadingPool.complete(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/simplemix/SimpleMixUtilities.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.simplemix; 17 | 18 | import java.util.Random; 19 | 20 | public class SimpleMixUtilities { 21 | public static int getRandomInteger() { 22 | return new Random().nextInt(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-legacy-test/src/test/java/samples/junit4/legacy/noannotation/SetUpAndTearDownWhenNotExtendingTestCaseTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.legacy.noannotation; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.modules.junit4.legacy.PowerMockRunner; 6 | 7 | import static org.junit.Assert.assertEquals; 8 | import static org.junit.Assert.fail; 9 | 10 | @RunWith(PowerMockRunner.class) 11 | public class SetUpAndTearDownWhenNotExtendingTestCaseTest { 12 | private static final String INITIAL_MESSAGE = ""; 13 | private static String CURRENT_MESSAGE = INITIAL_MESSAGE; 14 | 15 | public void setUp() throws Exception { 16 | fail("Should not call setUp"); 17 | } 18 | 19 | public void tearDown() throws Exception { 20 | fail("Should not call tearDown"); 21 | } 22 | 23 | @Test 24 | public void testSomething() throws Exception { 25 | assertEquals(INITIAL_MESSAGE, CURRENT_MESSAGE); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/expectation/ConstructorExpectationSetup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.mockito.expectation; 17 | 18 | public interface ConstructorExpectationSetup extends WithOrWithoutExpectedArguments, WithExpectedParameterTypes, WithAnyArguments { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /examples/tutorial/src/main/java/demo/org/powermock/examples/tutorial/hellopower/HelloWorld.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo.org.powermock.examples.tutorial.hellopower; 17 | 18 | public class HelloWorld { 19 | public String greet() { 20 | return SimpleConfig.getGreeting() + " " + SimpleConfig.getTarget(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/classhierarchy/Parent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.classhierarchy; 17 | 18 | public class Parent { 19 | private int value; 20 | 21 | public int getValue() { 22 | return value; 23 | } 24 | 25 | public void setValue(int value) { 26 | this.value = value; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/expectation/WithAnyArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.mockito.expectation; 17 | 18 | import org.mockito.stubbing.OngoingStubbing; 19 | 20 | public interface WithAnyArguments { 21 | 22 | OngoingStubbing withAnyArguments() throws Exception; 23 | 24 | } -------------------------------------------------------------------------------- /examples/AbstractFactory/src/main/java/powermock/examples/service/MyService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.examples.service; 17 | 18 | import powermock.examples.domain.Person; 19 | 20 | import java.util.Set; 21 | 22 | public interface MyService { 23 | 24 | Set getAllPersons(); 25 | 26 | } -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/context/MyIntContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.powermock.reflect.context; 18 | 19 | public class MyIntContext { 20 | 21 | private int simpleIntState = 42; 22 | 23 | public int getSimpleIntState() { 24 | return simpleIntState; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/context/MyStringContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.powermock.reflect.context; 18 | 19 | public class MyStringContext { 20 | private String myStringState = "string"; 21 | 22 | public String getMyStringState() { 23 | return myStringState; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithMethodUsingSuperTypeArgument.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | public class ClassWithMethodUsingSuperTypeArgument { 19 | public void methodHavingASuperTypeArgument(ClassWithStandardMethod arg) { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/mockpolicy/SomeClassWithAMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.mockpolicy; 17 | 18 | public class SomeClassWithAMethod extends SomeClassWithAMethodParent { 19 | 20 | @Override 21 | public double getResult() { 22 | return super.getResult() * 2; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/singleton/StaticWithPrivateCtor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package samples.singleton; 18 | 19 | public class StaticWithPrivateCtor { 20 | 21 | private StaticWithPrivateCtor(){ 22 | } 23 | 24 | public static String staticMethod() { 25 | return "something"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /examples/jmock/src/main/java/powermock/examples/jmock/ClassWithStaticMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package powermock.examples.jmock; 18 | 19 | /** 20 | * Class with static methods 21 | */ 22 | public class ClassWithStaticMethod { 23 | 24 | public static String returnString() { 25 | return "a string"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit45-test/src/main/java/demo/org/powermock/modules/test/junit45/failure/MyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo.org.powermock.modules.test.junit45.failure; 17 | 18 | public class MyException extends Exception { 19 | private static final long serialVersionUID = -222072316863858540L; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/simplemix/SimpleMixCollaborator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.simplemix; 17 | 18 | import java.util.Random; 19 | 20 | public final class SimpleMixCollaborator { 21 | 22 | public final int getRandomInteger() { 23 | return new Random().nextInt(400); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/singleton/StaticHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.singleton; 17 | 18 | public class StaticHelper { 19 | 20 | public static void sayHelloHelper() { 21 | System.out.println("hello"); 22 | } 23 | 24 | public static void sayHelloAgain() { 25 | System.out.println("hello"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/verification/WithVerifiedArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.mockito.verification; 17 | 18 | 19 | public interface WithVerifiedArguments { 20 | 21 | public abstract void withArguments(Object firstArgument, Object... additionalArguments) throws Exception; 22 | 23 | } -------------------------------------------------------------------------------- /classloading/classloading-objenesis/src/test/java/powermock/classloading/classes/MyStaticFinalNumberHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyStaticFinalNumberHolder { 19 | 20 | private static final Long myLong = 1L; 21 | 22 | public Long getMyLong() { 23 | return myLong; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /classloading/classloading-objenesis/src/test/java/powermock/classloading/classes/MyStaticFinalPrimitiveHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyStaticFinalPrimitiveHolder { 19 | 20 | private static final int myInt = 1; 21 | 22 | public int getMyInt() { 23 | return myInt; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /classloading/classloading-xstream/src/test/java/powermock/classloading/classes/MyStaticFinalNumberHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyStaticFinalNumberHolder { 19 | 20 | private static final Long myLong = 1L; 21 | 22 | public Long getMyLong() { 23 | return myLong; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /classloading/classloading-xstream/src/test/java/powermock/classloading/classes/MyStaticFinalPrimitiveHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyStaticFinalPrimitiveHolder { 19 | 20 | private static final int myInt = 1; 21 | 22 | public int getMyInt() { 23 | return myInt; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/expectnew/ExpectNewOfFinalSystemClassDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.expectnew; 17 | 18 | public class ExpectNewOfFinalSystemClassDemo { 19 | 20 | public char getFirstChar() { 21 | String myString = new String("My String"); 22 | return myString.charAt(0); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/expectation/WithoutExpectedArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.mockito.expectation; 17 | 18 | import org.mockito.stubbing.OngoingStubbing; 19 | 20 | public interface WithoutExpectedArguments { 21 | 22 | OngoingStubbing withNoArguments() throws Exception; 23 | 24 | } -------------------------------------------------------------------------------- /examples/tutorial/src/main/java/demo/org/powermock/examples/tutorial/partialmocking/dao/domain/Connection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo.org.powermock.examples.tutorial.partialmocking.dao.domain; 17 | 18 | public interface Connection { 19 | 20 | void disconnect(); 21 | 22 | void send(byte[] data); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithChildThatHasInternalState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | @SuppressWarnings("unused") 19 | public class ClassWithChildThatHasInternalState extends ClassWithInternalState { 20 | 21 | private int anotherInternalState = 42; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /api/easymock/src/main/java/org/powermock/api/extension/proxyframework/ProxyFrameworkImpl.java: -------------------------------------------------------------------------------- 1 | package org.powermock.api.extension.proxyframework; 2 | 3 | import net.sf.cglib.proxy.Enhancer; 4 | import org.powermock.reflect.spi.ProxyFramework; 5 | 6 | /** 7 | * CGLib proxy framework setup. 8 | */ 9 | public class ProxyFrameworkImpl implements ProxyFramework { 10 | 11 | /** 12 | * {@inheritDoc} 13 | */ 14 | public Class getUnproxiedType(Class type) { 15 | Class currentType = type; 16 | while (isProxy(currentType)) { 17 | currentType = currentType.getSuperclass(); 18 | } 19 | return currentType; 20 | } 21 | 22 | /** 23 | * {@inheritDoc} 24 | */ 25 | public boolean isProxy(Class type) { 26 | if (type == null) { 27 | return false; 28 | } 29 | return type.getName().contains("$$EnhancerByCGLIB$$") || Enhancer.isEnhanced(type); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/expectation/WithExpectedParameterTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.mockito.expectation; 17 | 18 | public interface WithExpectedParameterTypes { 19 | 20 | WithExpectedArguments withParameterTypes(Class parameterType, Class... additionalParameterTypes); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/mockpolicy/SimpleClassWithADependency.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.mockpolicy; 17 | 18 | 19 | public class SimpleClassWithADependency { 20 | 21 | private ResultCalculator calculator; 22 | 23 | public double getResult() { 24 | return calculator.calculate(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/partialmocking/MockSelfDemoSubClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.partialmocking; 17 | 18 | public class MockSelfDemoSubClass { 19 | 20 | public String getAMessage() { 21 | return "A message"; 22 | } 23 | 24 | protected String getAProtectedMessage() { 25 | return "protected"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | import java.util.LinkedList; 19 | import java.util.List; 20 | 21 | public class ClassWithList { 22 | 23 | @SuppressWarnings("unused") 24 | private List list = new LinkedList(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithOverriddenMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | public class ClassWithOverriddenMethod extends ClassWithStandardMethod { 19 | 20 | @Override 21 | public boolean myMethod(double value) { 22 | return true; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/methodhierarchy/MethodInvocationDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.methodhierarchy; 17 | 18 | public class MethodInvocationDemo extends MethodInvocationDemoParent { 19 | 20 | @SuppressWarnings("unused") 21 | private String getString() { 22 | return getTheString(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /api/easymock/src/main/java/org/powermock/api/easymock/internal/mockstrategy/impl/AbstractMockStrategyBase.java: -------------------------------------------------------------------------------- 1 | package org.powermock.api.easymock.internal.mockstrategy.impl; 2 | 3 | import org.easymock.IMocksControl; 4 | import org.easymock.internal.MocksControl; 5 | import org.easymock.internal.MocksControl.MockType; 6 | import org.powermock.api.easymock.internal.mockstrategy.MockStrategy; 7 | 8 | /** 9 | * Base class that should be used by all mock strategies. Enables mocking of 10 | * signed classes. 11 | */ 12 | public abstract class AbstractMockStrategyBase implements MockStrategy { 13 | 14 | private final MockType mockType; 15 | 16 | public AbstractMockStrategyBase(MockType mockType) { 17 | if (mockType == null) { 18 | throw new IllegalArgumentException("Internal error: mockType cannot be null"); 19 | } 20 | this.mockType = mockType; 21 | } 22 | 23 | public IMocksControl createMockControl(Class type) { 24 | return new MocksControl(mockType); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples; 17 | 18 | /** 19 | * A very simple service interface used as a dependency for various classes to 20 | * demonstrate different kinds of mocking. 21 | * 22 | * @author Johan Haleby 23 | */ 24 | public interface Service { 25 | 26 | public String getServiceMessage(); 27 | } 28 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/testhierarchy/TestParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.junit4.testhierarchy; 17 | 18 | import org.junit.runner.RunWith; 19 | import org.powermock.modules.junit4.PowerMockRunner; 20 | 21 | @RunWith(PowerMockRunner.class) 22 | public class TestParent { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /modules/module-test/easymock/testng-agent-test/suite.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/strict/StrictDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.strict; 17 | 18 | public class StrictDemo { 19 | 20 | public void callAThenB() { 21 | A(); 22 | B(); 23 | } 24 | 25 | private void A() { 26 | // Does nothing 27 | } 28 | 29 | private void B() { 30 | // Does nothing 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/suppressconstructor/SuppressConstructorHeirarchyEvilGrandParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.suppressconstructor; 17 | 18 | public class SuppressConstructorHeirarchyEvilGrandParent { 19 | 20 | SuppressConstructorHeirarchyEvilGrandParent() { 21 | throw new RuntimeException("This should be suppressed!!"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /modules/module-test/easymock/testng-test/suite.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/mockpolicy/frameworkexample/SimpleFrameworkUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.mockpolicy.frameworkexample; 17 | 18 | public class SimpleFrameworkUser { 19 | 20 | public String performComplexOperation(String operation) { 21 | return new SimpleFramework().doNativeStuff(operation).get(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/expectation/PrivatelyExpectedArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */package org.powermock.api.mockito.expectation; 16 | 17 | public interface PrivatelyExpectedArguments { 18 | void withArguments(Object firstArgument, Object... additionalArguments) throws Exception; 19 | 20 | void withNoArguments() throws Exception; 21 | } 22 | -------------------------------------------------------------------------------- /classloading/classloading-xstream/src/test/java/powermock/classloading/classes/MyStaticFinalArgumentHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyStaticFinalArgumentHolder { 19 | 20 | private static final MyArgument myObject = new MyArgument("hello"); 21 | 22 | public MyArgument getMyObject() { 23 | return myObject; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/core/spi/testresult/TestSuiteResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.core.spi.testresult; 17 | 18 | public interface TestSuiteResult { 19 | 20 | int getTestCount(); 21 | 22 | int getIgnoreCount(); 23 | 24 | int getSuccessCount(); 25 | 26 | int getFailureCount(); 27 | 28 | Result getResult(); 29 | } 30 | -------------------------------------------------------------------------------- /examples/java8/src/main/java/demo/org/powermock/examples/SimpleOps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo.org.powermock.examples; 17 | 18 | import java.util.List; 19 | import java.util.stream.Collectors; 20 | 21 | public class SimpleOps { 22 | public List doStreamStuff(List inputs) { 23 | return inputs.stream().collect(Collectors.toList()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/tutorial/src/main/java/demo/org/powermock/examples/tutorial/partialmocking/domain/DataProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo.org.powermock.examples.tutorial.partialmocking.domain; 17 | 18 | public class DataProducer extends ProviderArtifact { 19 | 20 | public DataProducer(int id, String name) { 21 | super(id, name); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/argumentmatcher/ArgumentMatcherDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.argumentmatcher; 17 | 18 | import java.util.List; 19 | 20 | public class ArgumentMatcherDemo { 21 | 22 | public List findByNamedQuery(String argument, List someList) { 23 | someList.add("one"); 24 | return someList; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/expectation/WithExpectedArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.mockito.expectation; 17 | 18 | import org.mockito.stubbing.OngoingStubbing; 19 | 20 | public interface WithExpectedArguments { 21 | 22 | OngoingStubbing withArguments(Object firstArgument, Object... additionalArguments) throws Exception; 23 | 24 | } -------------------------------------------------------------------------------- /classloading/classloading-objenesis/src/test/java/powermock/classloading/classes/MyStaticFinalArgumentHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyStaticFinalArgumentHolder { 19 | 20 | private static final MyArgument myObject = new MyArgument("hello"); 21 | 22 | public MyArgument getMyObject() { 23 | return myObject; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /modules/module-test/mockito/junit4/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | powermock-modules-test-mockito 4 | 5 | org.powermock 6 | 7 | 1.5.7-SNAPSHOT 8 | 9 | 4.0.0 10 | org.powermock 11 | powermock-module-test-mockito-junit4 12 | powermock-module-test-mockito-junit4 13 | 1.5.7-SNAPSHOT 14 | 15 | 16 | Tests for Mockito module with JUnit 4.x. 17 | 18 | 19 | 20 | 21 | org.powermock 22 | powermock-module-junit4 23 | ${project.version} 24 | test 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/mockpolicy/ResultCalculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.mockpolicy; 17 | 18 | public class ResultCalculator { 19 | private int operand; 20 | 21 | public ResultCalculator(int operand) { 22 | this.operand = operand; 23 | } 24 | 25 | public double calculate() { 26 | return Math.PI*operand; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/newmocking/SomeDependency.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.newmocking; 17 | 18 | 19 | public class SomeDependency { 20 | 21 | private String thing="complete"; 22 | 23 | void complete() { 24 | System.out.println(thing.toString()); // PowerMockBugPartATest gives NPE here, PowerMockBugPartBTest works 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/partialmocking/PartialMockingWithConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.partialmocking; 17 | 18 | public class PartialMockingWithConstructor { 19 | public PartialMockingWithConstructor() { 20 | initialize(); 21 | } 22 | 23 | public void initialize() { 24 | } 25 | 26 | public void touch() { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /api/mockito/src/main/java/org/powermock/api/mockito/verification/ConstructorArgumentsVerification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.mockito.verification; 17 | 18 | public interface ConstructorArgumentsVerification { 19 | 20 | void withArguments(Object argument, Object... additionalArguments) throws Exception; 21 | 22 | void withNoArguments() throws Exception; 23 | } 24 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/nice/NiceDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.nice; 17 | 18 | public class NiceDemo { 19 | 20 | public void callAThenB() { 21 | A("String"); 22 | B("String 2"); 23 | } 24 | 25 | void A(String aString) { 26 | // Does nothing 27 | } 28 | 29 | void B(String aString) { 30 | // Does nothing 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/tests/utils/ArrayMerger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.tests.utils; 17 | 18 | /** 19 | * An array merger concatenates several arrays to one. 20 | */ 21 | public interface ArrayMerger { 22 | 23 | /** 24 | * Merge arrays of a specific type. 25 | */ 26 | T[] mergeArrays(Class type, T[]... arraysToMerge); 27 | } 28 | -------------------------------------------------------------------------------- /examples/DocumentationExamples/src/main/java/powermock/examples/annotationbased/dao/SomeDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.examples.annotationbased.dao; 17 | 18 | public class SomeDao { 19 | 20 | public Object getSomeData() { 21 | return new Object(); 22 | } 23 | 24 | public Object getSomeOtherData() { 25 | return new Object(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithAMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | import java.sql.Connection; 19 | 20 | public class ClassWithAMethod { 21 | 22 | public void connect(Connection connection) { 23 | if(connection == null) { 24 | throw new IllegalArgumentException("param was null"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /classloading/classloading-objenesis/src/test/java/powermock/classloading/classes/MyHierarchicalFieldHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyHierarchicalFieldHolder extends MyReferenceFieldHolder { 19 | private MyArgument myArgument3 = new MyArgument("testing"); 20 | 21 | public MyArgument getMyArgument3() { 22 | return myArgument3; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /classloading/classloading-xstream/src/test/java/powermock/classloading/classes/MyHierarchicalFieldHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyHierarchicalFieldHolder extends MyReferenceFieldHolder { 19 | private MyArgument myArgument3 = new MyArgument("testing"); 20 | 21 | public MyArgument getMyArgument3() { 22 | return myArgument3; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /modules/module-test/easymock/testng-test/src/test/java/samples/testng/FinalTest.java: -------------------------------------------------------------------------------- 1 | package samples.testng; 2 | 3 | import org.powermock.core.classloader.annotations.PrepareForTest; 4 | import org.powermock.modules.testng.PowerMockTestCase; 5 | import org.testng.annotations.Test; 6 | import samples.finalmocking.FinalDemo; 7 | 8 | import static org.easymock.EasyMock.expect; 9 | import static org.powermock.api.easymock.PowerMock.*; 10 | import static org.testng.Assert.assertEquals; 11 | 12 | @PrepareForTest(FinalDemo.class) 13 | public class FinalTest extends PowerMockTestCase { 14 | 15 | @Test 16 | public void mockingFinalClassesAndMethodsWorkWithTestNGAndEasyMock() throws Exception { 17 | final FinalDemo finalDemo = createMock(FinalDemo.class); 18 | 19 | expect(finalDemo.say("something")).andReturn("something else"); 20 | 21 | replayAll(); 22 | 23 | final String actual = finalDemo.say("something"); 24 | 25 | verifyAll(); 26 | 27 | assertEquals("something else", actual); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/enummocking/EnumMockingTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.enummocking; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.powermock.core.classloader.annotations.PrepareForTest; 7 | import org.powermock.modules.junit4.PowerMockRunner; 8 | import samples.enummocking.MyEnum; 9 | 10 | import static org.easymock.EasyMock.expect; 11 | import static org.powermock.api.easymock.PowerMock.*; 12 | 13 | @RunWith(PowerMockRunner.class) 14 | @PrepareForTest(MyEnum.class) 15 | public class EnumMockingTest { 16 | 17 | @Test 18 | public void assertMockingOfStaticMethodInEnumWorks() throws Exception { 19 | final String expected = "something else"; 20 | mockStatic(MyEnum.class); 21 | 22 | expect(MyEnum.getString()).andReturn(expected); 23 | 24 | replayAll(); 25 | 26 | final String actual = MyEnum.getString(); 27 | 28 | verifyAll(); 29 | 30 | Assert.assertEquals(expected, actual); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit45-test/src/main/java/demo/org/powermock/modules/test/junit45/failure/MyClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo.org.powermock.modules.test.junit45.failure; 17 | 18 | public class MyClass { 19 | 20 | public int sum(int a, int b) throws MyException { 21 | if (MyUtils.isValid(a)) 22 | throw new MyException(); 23 | else 24 | return a + b; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithSeveralMethodsWithSameName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | public class ClassWithSeveralMethodsWithSameName { 19 | 20 | public double getDouble(double value) { 21 | return value; 22 | } 23 | 24 | public double getDouble(double value1, double value2) { 25 | return value1 + value2; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/mockpolicy/frameworkexample/NativeResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.mockpolicy.frameworkexample; 17 | 18 | public class NativeResult { 19 | 20 | private final String result; 21 | 22 | public NativeResult(String result) { 23 | this.result = result; 24 | } 25 | 26 | public String get() { 27 | return result; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/DocumentationExamples/src/main/java/powermock/examples/suppress/constructor/EvilParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.examples.suppress.constructor; 17 | 18 | /** 19 | * Example that demonstrates PowerMock's ability to suppress constructors. 20 | */ 21 | public class EvilParent { 22 | 23 | public EvilParent() { 24 | System.loadLibrary("evil.dll"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/abstractmocking/AbstractMethodMockingTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.abstractmocking; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.core.classloader.annotations.PrepareForTest; 6 | import org.powermock.modules.junit4.PowerMockRunner; 7 | import samples.abstractmocking.AbstractMethodMocking; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | import static org.powermock.api.easymock.PowerMock.*; 11 | 12 | @RunWith(PowerMockRunner.class) 13 | @PrepareForTest(AbstractMethodMocking.class) 14 | public class AbstractMethodMockingTest { 15 | 16 | @Test 17 | public void testMockingOfAbstractMethod() throws Exception { 18 | final String value = "a string"; 19 | AbstractMethodMocking tested = createPartialMock( 20 | AbstractMethodMocking.class, "getIt"); 21 | 22 | expectPrivate(tested, "getIt").andReturn(value); 23 | 24 | replay(tested); 25 | 26 | assertEquals(value, tested.getValue()); 27 | 28 | verify(tested); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/newmocking/MyClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.newmocking; 17 | 18 | public class MyClass { 19 | 20 | public String getMessage() { 21 | return "Hello world"; 22 | } 23 | 24 | public String getMessage(String message) { 25 | return "Hello world: " + message; 26 | } 27 | 28 | public void voidMethod() { 29 | System.out.println("Void method!"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/suppressconstructor/SuppressConstructorSubclassDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.suppressconstructor; 17 | 18 | public class SuppressConstructorSubclassDemo { 19 | 20 | private String message; 21 | 22 | SuppressConstructorSubclassDemo(String message) { 23 | this.message = message; 24 | } 25 | 26 | public String getMessage() { 27 | return message; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/suppressconstructor/SuppressNonParentConstructorDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.suppressconstructor; 17 | 18 | public class SuppressNonParentConstructorDemo { 19 | 20 | public SuppressNonParentConstructorDemo(String message) { 21 | throw new IllegalStateException(message); 22 | } 23 | 24 | public String getHello() { 25 | return "Hello"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/tests/utils/IgnorePackagesExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.tests.utils; 17 | 18 | import java.lang.reflect.AnnotatedElement; 19 | 20 | public interface IgnorePackagesExtractor { 21 | /** 22 | * @return Returns a string-array of all package names if annotation was 23 | * found. 24 | */ 25 | String[] getPackagesToIgnore(AnnotatedElement element); 26 | } 27 | -------------------------------------------------------------------------------- /examples/spring-mockito/src/main/java/powermock/examples/spring/MyBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package powermock.examples.spring; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | @Component 22 | public class MyBean { 23 | 24 | public Message generateMessage() { 25 | final long id = IdGenerator.generateNewId(); 26 | return new Message(id, "My bean message"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/nativemocking/NativeService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.nativemocking; 17 | 18 | /** 19 | * The purpose of this class is to demonstrate that it's possible to mock native 20 | * methods using plain EasyMock class extensions. 21 | */ 22 | public class NativeService { 23 | 24 | public native String invokeNative(String nativeParameter); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/mockpolicy/frameworkexample/SimpleFramework.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.mockpolicy.frameworkexample; 17 | 18 | public class SimpleFramework { 19 | 20 | static { 21 | System.loadLibrary("framework.dll"); 22 | } 23 | 24 | public NativeResult doNativeStuff(String nativeStuffToDo) { 25 | return new NativeResult(nativeStuffToDo); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/overloading/StaticAndInstanceMethodWithSameName.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.overloading; 17 | 18 | import samples.classhierarchy.ChildA; 19 | import samples.classhierarchy.Parent; 20 | 21 | public class StaticAndInstanceMethodWithSameName { 22 | public void overloaded(Parent parent) { 23 | } 24 | 25 | public static void overloaded(ChildA child) { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /classloading/classloading-objenesis/src/test/java/powermock/classloading/classes/MyEnumHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyEnumHolder { 19 | 20 | private final MyEnum myEnum; 21 | 22 | public MyEnumHolder(MyEnum myEnum) { 23 | super(); 24 | this.myEnum = myEnum; 25 | } 26 | 27 | public MyEnum getMyEnum() { 28 | return myEnum; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /classloading/classloading-xstream/src/test/java/powermock/classloading/classes/MyEnumHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyEnumHolder { 19 | 20 | private final MyEnum myEnum; 21 | 22 | public MyEnumHolder(MyEnum myEnum) { 23 | super(); 24 | this.myEnum = myEnum; 25 | } 26 | 27 | public MyEnum getMyEnum() { 28 | return myEnum; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/expectvoid/ExpectVoidDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.expectvoid; 17 | 18 | public class ExpectVoidDemo { 19 | 20 | public void invokeAPrivateVoidMethod(int something) { 21 | privateInvoke(something); 22 | } 23 | 24 | private void privateInvoke(int something) { 25 | System.out.println("Error in test privateInvoke in class " 26 | + ExpectVoidDemo.class.getSimpleName()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /classloading/classloading-base/src/main/java/org/powermock/classloading/spi/DoNotClone.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.classloading.spi; 17 | 18 | import java.lang.annotation.*; 19 | 20 | /** 21 | * Fields annotated with this annotation are not allowed to be cloned by a Deep Cloner implementation. 22 | */ 23 | @Retention(RetentionPolicy.RUNTIME) 24 | @Target(ElementType.FIELD) 25 | @Inherited 26 | public @interface DoNotClone { 27 | } 28 | -------------------------------------------------------------------------------- /classloading/classloading-xstream/src/test/java/powermock/classloading/classes/MyIntegerHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyIntegerHolder { 19 | 20 | private final int myInteger; 21 | 22 | public MyIntegerHolder(int myInteger) { 23 | super(); 24 | this.myInteger = myInteger; 25 | } 26 | 27 | public int getMyInteger() { 28 | return myInteger; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/DocumentationExamples/src/main/java/powermock/examples/bypassencapsulation/nontest/Cache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.examples.bypassencapsulation.nontest; 17 | 18 | /** 19 | * A made-up class used to demonstrate some PowerMock functionality. 20 | */ 21 | public class Cache { 22 | 23 | public void invalidateCache(final Report report) { 24 | // Imagine something useful happening here. 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithOverloadedMethods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | public class ClassWithOverloadedMethods { 19 | 20 | public String overloaded(double value, Parent parent) { 21 | return "parent"; 22 | } 23 | 24 | public String overloaded(double value, Child child) { 25 | return "child"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /classloading/classloading-objenesis/src/test/java/powermock/classloading/classes/MyIntegerHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyIntegerHolder { 19 | 20 | private final int myInteger; 21 | 22 | public MyIntegerHolder(int myInteger) { 23 | super(); 24 | this.myInteger = myInteger; 25 | } 26 | 27 | public int getMyInteger() { 28 | return myInteger; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/tutorial/src/main/java/demo/org/powermock/examples/tutorial/staticmocking/osgi/ServiceRegistration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo.org.powermock.examples.tutorial.staticmocking.osgi; 17 | 18 | /** 19 | * Copied method declaration from the OSGi ServiceRegistration interface. It's 20 | * just here for demonstration purposes. 21 | */ 22 | public interface ServiceRegistration { 23 | 24 | void unregister(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/simplereturn/SimpleReturnExampleUserTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.simplereturn; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.core.classloader.annotations.PrepareForTest; 6 | import org.powermock.modules.junit4.PowerMockRunner; 7 | import samples.simplereturn.SimpleReturnExample; 8 | import samples.simplereturn.SimpleReturnExampleUser; 9 | 10 | import static org.easymock.EasyMock.expect; 11 | import static org.junit.Assert.assertEquals; 12 | import static org.powermock.api.easymock.PowerMock.*; 13 | 14 | @RunWith(PowerMockRunner.class) 15 | @PrepareForTest(SimpleReturnExample.class) 16 | public class SimpleReturnExampleUserTest { 17 | 18 | @Test 19 | public void testCreateMockDelegatedToEasyMock() throws Exception { 20 | SimpleReturnExample mock = createMock(SimpleReturnExample.class); 21 | expect(mock.mySimpleMethod()).andReturn(2); 22 | 23 | replay(mock); 24 | 25 | assertEquals(2, new SimpleReturnExampleUser(mock).myMethod()); 26 | 27 | verify(mock); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/annotationbased/AnnotationDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.annotationbased; 17 | 18 | import samples.Service; 19 | 20 | public class AnnotationDemo { 21 | 22 | private final Service service; 23 | 24 | public AnnotationDemo(Service service) { 25 | this.service = service; 26 | } 27 | 28 | public String getServiceMessage() { 29 | return service.getServiceMessage(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /classloading/classloading-xstream/src/test/java/powermock/classloading/classes/MyPrimitiveArrayHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyPrimitiveArrayHolder { 19 | 20 | private final int[] myArray; 21 | 22 | public MyPrimitiveArrayHolder(int[] myArray) { 23 | super(); 24 | this.myArray = myArray; 25 | } 26 | 27 | public int[] getMyArray() { 28 | return myArray; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/slf4j-mockito/src/test/java/demo/org/powermock/examples/Slf4jUserTest.java: -------------------------------------------------------------------------------- 1 | package demo.org.powermock.examples; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.api.mockito.mockpolicies.Slf4jMockPolicy; 6 | import org.powermock.core.classloader.annotations.MockPolicy; 7 | import org.powermock.modules.junit4.PowerMockRunner; 8 | import org.powermock.reflect.Whitebox; 9 | import org.slf4j.Logger; 10 | 11 | import static org.junit.Assert.assertTrue; 12 | 13 | /** 14 | * Unit tests that assert that the {@link Slf4jMockPolicy} works for Mockito. 15 | */ 16 | @RunWith(PowerMockRunner.class) 17 | @MockPolicy(Slf4jMockPolicy.class) 18 | public class Slf4jUserTest { 19 | 20 | @Test 21 | public void assertSlf4jMockPolicyWorks() throws Exception { 22 | final Slf4jUser tested = new Slf4jUser(); 23 | 24 | tested.getMessage(); 25 | 26 | final Class aClass = Whitebox.getInternalState(Slf4jUser.class, Logger.class).getClass(); 27 | assertTrue(aClass.getName().contains("EnhancerByMockitoWithCGLIB")); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/noannotation/SetUpAndTearDownWhenExtendingTestCaseTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.noannotation; 2 | 3 | import junit.framework.TestCase; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.modules.junit4.PowerMockRunner; 6 | 7 | @RunWith(PowerMockRunner.class) 8 | public class SetUpAndTearDownWhenExtendingTestCaseTest extends TestCase { 9 | private static final String INITIAL_MESSAGE = ""; 10 | private static final String SET_UP_MESSAGE = "setUp"; 11 | private static final String TEST_MESSAGE = "test"; 12 | 13 | private static String CURRENT_MESSAGE = INITIAL_MESSAGE; 14 | 15 | @Override 16 | protected void setUp() throws Exception { 17 | assertEquals(INITIAL_MESSAGE, CURRENT_MESSAGE); 18 | CURRENT_MESSAGE = SET_UP_MESSAGE; 19 | } 20 | 21 | @Override 22 | protected void tearDown() throws Exception { 23 | assertEquals(TEST_MESSAGE, CURRENT_MESSAGE); 24 | } 25 | 26 | public void testSomething() throws Exception { 27 | assertEquals(SET_UP_MESSAGE, CURRENT_MESSAGE); 28 | CURRENT_MESSAGE = TEST_MESSAGE; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/abstractmocking/AbstractMethodMocking.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.abstractmocking; 17 | 18 | /** 19 | * Demonstrates that PowerMock can mock abstract methods. This was previously a 20 | * bug in PowerMock. 21 | */ 22 | public abstract class AbstractMethodMocking { 23 | 24 | public String getValue() { 25 | return getIt(); 26 | } 27 | 28 | protected abstract String getIt(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /classloading/classloading-objenesis/src/test/java/powermock/classloading/classes/MyPrimitiveArrayHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyPrimitiveArrayHolder { 19 | 20 | private final int[] myArray; 21 | 22 | public MyPrimitiveArrayHolder(int[] myArray) { 23 | super(); 24 | this.myArray = myArray; 25 | } 26 | 27 | public int[] getMyArray() { 28 | return myArray; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/spring-mockito/src/main/java/powermock/examples/spring/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.examples.spring; 17 | 18 | /** 19 | * The purpose of the IdGenerator is to generate ID's based on the system time. 20 | */ 21 | public class IdGenerator { 22 | 23 | /** 24 | * @return A new ID based on the current time. 25 | */ 26 | public static long generateNewId() { 27 | return System.currentTimeMillis(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/interfacemethodfinding/WsUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.interfacemethodfinding; 17 | 18 | import java.sql.Connection; 19 | 20 | /** 21 | * Dummy class that is used to setup expectations for the 22 | * {@link InterfaceMethodHierarchyUsage}. 23 | */ 24 | public class WsUtil { 25 | 26 | public static Connection getConnection() throws Exception { 27 | 28 | Connection conn = null; 29 | 30 | return conn; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /api/support/src/main/java/org/powermock/api/support/SafeExceptionRethrower.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.api.support; 17 | 18 | public class SafeExceptionRethrower { 19 | 20 | public static void safeRethrow(Throwable t) { 21 | SafeExceptionRethrower. safeRethrow0(t); 22 | } 23 | 24 | @SuppressWarnings("unchecked") 25 | private static void safeRethrow0(Throwable t) throws T { 26 | throw (T) t; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /examples/DocumentationExamples/src/main/java/powermock/examples/suppress/constructorhierarchy/EvilGrandParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.examples.suppress.constructorhierarchy; 17 | 18 | /** 19 | * Example that demonstrates PowerMock's ability to suppress constructor 20 | * hierarchies. 21 | */ 22 | public class EvilGrandParent { 23 | 24 | public EvilGrandParent() { 25 | System.loadLibrary("evil grand parent.dll"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/reflection/ReflectionInstantiator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.reflection; 17 | 18 | public class ReflectionInstantiator { 19 | 20 | public boolean instantiateUseMe() throws ClassNotFoundException { 21 | Class reflectionClass = Class.forName( 22 | "samples.reflection.UseMeInterface", true, Thread 23 | .currentThread().getContextClassLoader()); 24 | return reflectionClass.isAssignableFrom(UseMe.class); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /classloading/classloading-objenesis/src/test/java/powermock/classloading/classes/MyHierarchicalOverloadedFieldHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyHierarchicalOverloadedFieldHolder extends MyReferenceFieldHolder { 19 | public static final MyArgument MY_ARGUMENT = new MyArgument("testing"); 20 | private MyArgument myArgument3 = MY_ARGUMENT; 21 | 22 | public MyArgument getMyArgument3() { 23 | return myArgument3; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /classloading/classloading-xstream/src/test/java/powermock/classloading/classes/MyHierarchicalOverloadedFieldHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.classloading.classes; 17 | 18 | public class MyHierarchicalOverloadedFieldHolder extends MyReferenceFieldHolder { 19 | public static final MyArgument MY_ARGUMENT = new MyArgument("testing"); 20 | private MyArgument myArgument3 = MY_ARGUMENT; 21 | 22 | public MyArgument getMyArgument3() { 23 | return myArgument3; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/DocumentationExamples/src/main/java/powermock/examples/suppress/constructorhierarchy/EvilParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.examples.suppress.constructorhierarchy; 17 | 18 | /** 19 | * Example that demonstrates PowerMock's ability to suppress constructor 20 | * hierarchies. 21 | */ 22 | public class EvilParent extends EvilGrandParent { 23 | 24 | public EvilParent() { 25 | System.loadLibrary("evil parent.dll"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/spring-mockito-xml-agent/src/main/java/powermock/examples/spring/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.examples.spring; 17 | 18 | /** 19 | * The purpose of the IdGenerator is to generate ID's based on the system time. 20 | */ 21 | public class IdGenerator { 22 | 23 | /** 24 | * @return A new ID based on the current time. 25 | */ 26 | public static long generateNewId() { 27 | return System.currentTimeMillis(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/spring-mockito-xml/src/main/java/powermock/examples/spring/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.examples.spring; 17 | 18 | /** 19 | * The purpose of the IdGenerator is to generate ID's based on the system time. 20 | */ 21 | public final class IdGenerator { 22 | 23 | /** 24 | * @return A new ID based on the current time. 25 | */ 26 | public static long generateNewId() { 27 | return System.currentTimeMillis(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /modules/module-test/mockito/junit4/src/test/java/samples/powermockito/junit4/FinalEqualsClass.java: -------------------------------------------------------------------------------- 1 | package samples.powermockito.junit4; 2 | 3 | /* 4 | * Copyright 2011 the original author or authors. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * Just a testclass with a final-equals method. 21 | */ 22 | public class FinalEqualsClass { 23 | 24 | @Override 25 | public final boolean equals(Object obj) { 26 | return super.equals(obj); 27 | } 28 | 29 | public final String foo() { 30 | return "foo"; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithVarArgsConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.powermock.reflect.testclasses; 18 | 19 | public class ClassWithVarArgsConstructor { 20 | 21 | 22 | private final String[] strings; 23 | 24 | private ClassWithVarArgsConstructor(String...strings) { 25 | this.strings = strings; 26 | } 27 | 28 | public String[] getStrings() { 29 | return strings; 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/privateandfinal/PrivateFinal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.privateandfinal; 17 | 18 | /** 19 | * A class used to test the functionality to mock private methods that are also 20 | * final. 21 | * 22 | * @author Johan Haleby 23 | */ 24 | public class PrivateFinal { 25 | public String say(String name) { 26 | return sayIt(name); 27 | } 28 | 29 | private final String sayIt(String name) { 30 | return "Hello " + name; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-legacy-test/src/test/java/samples/junit4/legacy/noannotation/SetUpAndTearDownWhenExtendingTestCaseTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.legacy.noannotation; 2 | 3 | import junit.framework.TestCase; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.modules.junit4.legacy.PowerMockRunner; 6 | 7 | @RunWith(PowerMockRunner.class) 8 | public class SetUpAndTearDownWhenExtendingTestCaseTest extends TestCase { 9 | private static final String INITIAL_MESSAGE = ""; 10 | private static final String SET_UP_MESSAGE = "setUp"; 11 | private static final String TEST_MESSAGE = "test"; 12 | 13 | private static String CURRENT_MESSAGE = INITIAL_MESSAGE; 14 | 15 | @Override 16 | protected void setUp() throws Exception { 17 | assertEquals(INITIAL_MESSAGE, CURRENT_MESSAGE); 18 | CURRENT_MESSAGE = SET_UP_MESSAGE; 19 | } 20 | 21 | @Override 22 | protected void tearDown() throws Exception { 23 | assertEquals(TEST_MESSAGE, CURRENT_MESSAGE); 24 | } 25 | 26 | public void testSomething() throws Exception { 27 | assertEquals(SET_UP_MESSAGE, CURRENT_MESSAGE); 28 | CURRENT_MESSAGE = TEST_MESSAGE; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/partialmocking/MockSelfWithNoDefaultConstructorDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.partialmocking; 17 | 18 | public class MockSelfWithNoDefaultConstructorDemo { 19 | 20 | private int hello; 21 | 22 | public MockSelfWithNoDefaultConstructorDemo(int hello) { 23 | this.hello = hello; 24 | } 25 | 26 | public String aMethod() { 27 | aMethod2(); 28 | return "hello = " + hello; 29 | } 30 | 31 | public void aMethod2() { 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/tests/utils/TestChunk.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.tests.utils; 17 | 18 | import java.lang.reflect.Method; 19 | import java.util.List; 20 | 21 | /** 22 | * A test chunk consists of a list of methods that should be executed by a 23 | * particular classloader. 24 | * */ 25 | public interface TestChunk { 26 | 27 | ClassLoader getClassLoader(); 28 | 29 | List getTestMethodsToBeExecutedByThisClassloader(); 30 | 31 | } -------------------------------------------------------------------------------- /examples/DocumentationExamples/src/main/java/powermock/examples/staticmocking/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package powermock.examples.staticmocking; 17 | 18 | /** 19 | * The purpose of the IdGenerator is to generate ID's based on the system time. 20 | */ 21 | public class IdGenerator { 22 | 23 | /** 24 | * @return A new ID based on the current time. 25 | */ 26 | public static long generateNewId() { 27 | return System.currentTimeMillis(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/partialmocking/MockSelfDemoWithSubClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.partialmocking; 17 | 18 | public class MockSelfDemoWithSubClass extends MockSelfDemoSubClass { 19 | 20 | public String getMessage() { 21 | return getInternalMessage() + getAMessage(); 22 | } 23 | 24 | public String getSecondMessage() { 25 | return getAProtectedMessage(); 26 | } 27 | 28 | private String getInternalMessage() { 29 | return "Internal message"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/staticinitializer/SimpleStaticInitializerExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.staticinitializer; 17 | 18 | public class SimpleStaticInitializerExample { 19 | 20 | private static final String string; 21 | 22 | static { 23 | string = "static world!"; 24 | } 25 | 26 | public String getString() { 27 | return string; 28 | } 29 | 30 | public final String getConcatenatedString(String concat) { 31 | return concat + " " + string; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/suppressconstructor/SuppressConstructorDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.suppressconstructor; 17 | 18 | public class SuppressConstructorDemo extends 19 | SuppressConstructorSubclassDemo { 20 | 21 | public SuppressConstructorDemo(String message) { 22 | super(message); 23 | } 24 | 25 | public String getMyOwnMessage() { 26 | return returnAMessage(); 27 | } 28 | 29 | private String returnAMessage() { 30 | return "my message"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/expectnew/ExpectNewOfFinalSystemClassTest.java: -------------------------------------------------------------------------------- 1 | package samples.junit4.expectnew; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.powermock.core.classloader.annotations.PrepareForTest; 6 | import org.powermock.modules.junit4.PowerMockRunner; 7 | import samples.expectnew.ExpectNewOfFinalSystemClassDemo; 8 | 9 | import static org.easymock.EasyMock.expect; 10 | import static org.junit.Assert.assertEquals; 11 | import static org.powermock.api.easymock.PowerMock.*; 12 | 13 | @RunWith(PowerMockRunner.class) 14 | @PrepareForTest(ExpectNewOfFinalSystemClassDemo.class) 15 | public class ExpectNewOfFinalSystemClassTest { 16 | 17 | @Test 18 | public void assertThatExpectNewWorksForFinalSystemClasses() throws Exception { 19 | String mock = createMock(String.class); 20 | 21 | expectNew(String.class, "My String").andReturn(mock); 22 | expect(mock.charAt(0)).andReturn('o'); 23 | 24 | replayAll(); 25 | assertEquals('o', new ExpectNewOfFinalSystemClassDemo().getFirstChar()); 26 | verifyAll(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/site/apt/docs/installing.apt: -------------------------------------------------------------------------------- 1 | ------------------------------ 2 | Installing 3 | ------------------------------ 4 | 5 | Binary release 6 | 7 | Not yet available... 8 | 9 | Installing from the trunk 10 | 11 | +----------------------------------------------------------------------------------+ 12 | svn checkout https://powermock.svn.sourceforge.net/svnroot/powermock/trunk powermock 13 | cd powermock 14 | mvn install 15 | +----------------------------------------------------------------------------------+ 16 | 17 | Installing a specific version 18 | 19 | +----------------------------------------------------------------------------------------------------------------+ 20 | svn checkout https://powermock.svn.sourceforge.net/svnroot/powermock/tags/powermock-${version} powermock-${version} 21 | cd powermock-${version} 22 | mvn install 23 | +----------------------------------------------------------------------------------------------------------------+ 24 | Note: Replace ${version} with the version number, such as 0.5. 25 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/suppressmethod/SuppressMethodExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.suppressmethod; 17 | 18 | public class SuppressMethodExample extends SuppressMethodParent { 19 | 20 | public static final Object OBJECT = new Object(); 21 | 22 | public Object getObject() { 23 | return OBJECT; 24 | } 25 | 26 | public Object getStringObject() { 27 | return "test"; 28 | } 29 | 30 | public static Object getStringObjectStatic() { 31 | return "test"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/core/classloader/ClassPathAdjuster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Jonas Berlin 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.powermock.core.classloader; 18 | 19 | import javassist.ClassPool; 20 | 21 | import org.powermock.core.classloader.annotations.UseClassPathAdjuster; 22 | 23 | /** 24 | * This interface can be used to adjust the classpath used by powermock to locate 25 | * class files. Use the @{@link UseClassPathAdjuster} to activate. 26 | */ 27 | public interface ClassPathAdjuster { 28 | void adjustClassPath(ClassPool classPool); 29 | } 30 | -------------------------------------------------------------------------------- /core/src/main/java/org/powermock/core/spi/listener/AnnotationEnablerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.core.spi.listener; 17 | 18 | import org.powermock.core.spi.PowerMockTestListener; 19 | 20 | import java.lang.annotation.Annotation; 21 | 22 | public interface AnnotationEnablerListener extends PowerMockTestListener { 23 | 24 | /** 25 | * @return The mock annotations considered by this annotation enabler. 26 | */ 27 | Class[] getMockAnnotations(); 28 | } 29 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/injectmocks/DependencyHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.injectmocks; 17 | 18 | import samples.finalmocking.FinalDemo; 19 | 20 | /** 21 | * Simple class used to demonstrate setter injection.. 22 | */ 23 | public class DependencyHolder { 24 | 25 | private FinalDemo finalDemo; 26 | 27 | public FinalDemo getFinalDemo() { 28 | return finalDemo; 29 | } 30 | 31 | public void setFinalDemo(FinalDemo finalDemo) { 32 | this.finalDemo = finalDemo; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/tutorial/src/main/java/demo/org/powermock/examples/tutorial/staticmocking/osgi/BundleContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo.org.powermock.examples.tutorial.staticmocking.osgi; 17 | 18 | /** 19 | * Copied method declaration from the OSGi BundleContext interface. It's just 20 | * here for demonstration purposes. 21 | */ 22 | public interface BundleContext { 23 | 24 | ServiceRegistration registerService(String name, Object serviceImplementation, String filter); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /modules/module-test/easymock/junit4-test/src/test/java/samples/junit4/stackoverflow/EvilHashCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.junit4.stackoverflow; 17 | 18 | public class EvilHashCode { 19 | //Required to produce error 20 | public String s = returnS(); 21 | 22 | public String returnS() 23 | { 24 | return "s"; 25 | } 26 | 27 | @Override 28 | public int hashCode() { 29 | return evilHashCode(); 30 | } 31 | 32 | public int evilHashCode() { 33 | return 3; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/dom4j/src/main/java/org/powermock/examples/dom4j/XMLProtocol.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.examples.dom4j; 17 | 18 | public final class XMLProtocol { 19 | 20 | private XMLProtocol() { 21 | } 22 | 23 | public static final String ENCODE_ELEMENT = "EncodeElement"; 24 | 25 | public static final String HEADER_ELEMENT = "MyHeader"; 26 | 27 | public static final String HEADER_MSG_ID_ATTRIBUTE = "MyMsgIdAttribute"; 28 | 29 | public static final String BODY_ELEMENT = "BodyElement"; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /modules/module-impl/junit4-common/src/main/java/org/powermock/modules/junit4/common/internal/PowerMockJUnitRunnerDelegate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.modules.junit4.common.internal; 17 | 18 | import org.junit.runner.Description; 19 | import org.junit.runner.notification.RunNotifier; 20 | 21 | public interface PowerMockJUnitRunnerDelegate { 22 | 23 | void run(final RunNotifier notifier); 24 | 25 | Description getDescription(); 26 | 27 | int getTestCount(); 28 | 29 | Class getTestClass(); 30 | } 31 | -------------------------------------------------------------------------------- /examples/spring-mockito-xml/src/main/java/powermock/examples/spring/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package powermock.examples.spring; 18 | 19 | public class Message { 20 | private final long id; 21 | private final String content; 22 | 23 | public Message(long id, String content) { 24 | this.id = id; 25 | this.content = content; 26 | } 27 | 28 | public long getId() { 29 | return id; 30 | } 31 | 32 | public String getContent() { 33 | return content; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/spring-mockito/src/main/java/powermock/examples/spring/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package powermock.examples.spring; 18 | 19 | public class Message { 20 | private final long id; 21 | private final String content; 22 | 23 | public Message(long id, String content) { 24 | this.id = id; 25 | this.content = content; 26 | } 27 | 28 | public long getId() { 29 | return id; 30 | } 31 | 32 | public String getContent() { 33 | return content; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithSeveralMethodsWithSameNameOneWithoutParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.powermock.reflect.testclasses; 17 | 18 | public class ClassWithSeveralMethodsWithSameNameOneWithoutParameters { 19 | 20 | public double getDouble() { 21 | return Double.MAX_VALUE; 22 | } 23 | 24 | public double getDouble(double value) { 25 | return value; 26 | } 27 | 28 | public double getDouble(double value1, double value2) { 29 | return value1 + value2; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/methodhierarchy/MethodInvocationDemoParent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.methodhierarchy; 17 | 18 | public class MethodInvocationDemoParent extends MethodInvocationDemoGrandParent { 19 | 20 | @Override 21 | protected String getTheString() { 22 | return "MethodInvocationDemoParent wrapped " + super.getTheString(); 23 | } 24 | 25 | @SuppressWarnings("unused") 26 | private String getString() { 27 | return "MethodInvocationDemoParent"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/tutorial/src/main/java/demo/org/powermock/examples/tutorial/staticmocking/impl/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package demo.org.powermock.examples.tutorial.staticmocking.impl; 17 | 18 | /** 19 | * The purpose of the IdGenerator is to generate ID's based on the system time. 20 | */ 21 | public class IdGenerator { 22 | 23 | /** 24 | * @return A new ID based on the current time. 25 | */ 26 | public static long generateNewId() { 27 | return System.currentTimeMillis(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /reflect/src/test/java/org/powermock/reflect/testclasses/ClassWithSimpleStateOfSameType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.powermock.reflect.testclasses; 18 | 19 | public class ClassWithSimpleStateOfSameType { 20 | 21 | private String someStringState = "-1"; 22 | private String someOtherStringState = "-1"; 23 | 24 | public String getSomeStringState() { 25 | return someStringState; 26 | } 27 | 28 | public String getSomeOtherStringState() { 29 | return someOtherStringState; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/newmocking/StupidNew.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.newmocking; 17 | 18 | public class StupidNew { 19 | 20 | public String getMessage() { 21 | MyClass myClass = new MyClass(); 22 | return myClass.getMessage(); 23 | } 24 | 25 | public String getMessageWithArgument() { 26 | MyClass myClass = new MyClass(); 27 | return myClass.getMessage("test"); 28 | } 29 | 30 | public void invokeVoidMethod() { 31 | MyClass myClass = new MyClass(); 32 | myClass.voidMethod(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/partialmocking/PartialMockingExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package samples.partialmocking; 17 | 18 | /** 19 | * Simple partial mocking example that should need no byte-code manipulation. 20 | */ 21 | public class PartialMockingExample { 22 | 23 | public String methodToTest() { 24 | return methodToMock(); 25 | } 26 | 27 | public String methodToMock() { 28 | System.out.println("If you see this the test is failing!"); 29 | return "REAL VALUE"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/utils/src/main/java/samples/rule/ThingToTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package samples.rule; 18 | 19 | public class ThingToTest { 20 | private final SimpleThing simpleThing; 21 | 22 | public ThingToTest() { 23 | simpleThing = SimpleThingCreator.createSimpleThing(); 24 | } 25 | 26 | public String getName() { 27 | // uncomment the line below and the test passes 28 | // return simpleThing.getThingName(); 29 | return "Smith"; 30 | } 31 | } 32 | --------------------------------------------------------------------------------