Permalink
Browse files

Move module-tests to a new module.

  • Loading branch information...
1 parent 56cc72a commit e82e7f27dee1fe8c73bbce447774607c399ab261 @thekingnothing thekingnothing committed with thekingnothing Jan 15, 2017
Showing 1,182 changed files with 16,156 additions and 16,446 deletions.
@@ -1,80 +0,0 @@
-package org.powermock.api.easymock.annotation;
-
-import org.powermock.core.classloader.annotations.PowerMockListener;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * This annotation can be placed on those fields in your test class that should
- * be mocked. This eliminates the need to setup and tear-down mocks manually
- * which minimizes repetitive test code and makes the test more readable. In
- * order for PowerMock to control the life-cycle of the mocks you must supply
- * the {@link PowerMockListener} annotation to the class-level of the test case.
- * For example:
- *
- * <pre>
- * ...
- * &#064;PowerMockListener(AnnotationEnabler.class)
- * public class PersonServiceTest {
- *
- * &#064;Mock
- * private PersonDao personDaoMock;
- *
- * private PersonService classUnderTest;
- *
- * &#064;Before
- * public void setUp() {
- * classUnderTest = new PersonService(personDaoMock);
- * }
- * ...
- * }
- * </pre>
- * <p>
- *
- * Note that you can also create partial mocks by using the annotation. Let's
- * say that the PersonService has a method called "getPerson" and another method
- * called "savePerson" and these are the only two methods that you'd like to
- * mock. Rewriting the previous example to accommodate this will give us the
- * following test:
- *
- * <pre>
- * ...
- * &#064;PowerMockListener(AnnotationEnabler.class)
- * public class PersonServiceTest {
- *
- * &#064;Mock({&quot;getPerson&quot;, &quot;savePerson&quot;})
- * private PersonDao personDaoMock;
- *
- * private PersonService classUnderTest;
- *
- * &#064;Before
- * public void setUp() {
- * classUnderTest = new PersonService(personDaoMock);
- * }
- * ...
- * }
- * </pre>
- * <p>
- */
-
-@Target( { ElementType.FIELD })
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-public @interface Mock {
- String[] value() default "";
-
- /**
- * Name of the test subject field to which this mock will be assigned. Use to disambiguate the case where
- * a mock may be assigned to multiple fields of the same type.
- * When set, this mock will be assigned to the given field name in any test subject with a matching field name.
- * If not set, injection is to all type-compatible fields in all test subjects.
- * A given field name may only be used once, and there must be a matching field in at least one test subject.
- *
- * @return name of the field to inject to
- **/
- String fieldName() default "";
-}
@@ -1,67 +0,0 @@
-package org.powermock.api.easymock.annotation;
-
-import org.powermock.core.classloader.annotations.PowerMockListener;
-
-import java.lang.annotation.*;
-
-/**
- * This annotation can be placed on those fields in your test class that should
- * be mocked in a nice manner (i.e. by default allows all method calls and
- * returns appropriate empty values (0, {@code null} or {@code false}
- * )). This eliminates the need to setup and tear-down mocks manually which
- * minimizes repetitive test code and makes the test more readable. In order for
- * PowerMock to control the life-cycle of the mocks you must supply the
- * {@link PowerMockListener} annotation to the class-level of the test case. For
- * example when using the EasyMock API:
- *
- * <pre>
- * &#064;PowerMockListener(EasyMockAnnotationEnabler.class)
- * public class PersonServiceTest {
- *
- * &#064;MockNice
- * private PersonDao personDaoMock;
- *
- * private PersonService classUnderTest;
- *
- * &#064;Before
- * public void setUp() {
- * classUnderTest = new PersonService(personDaoMock);
- * }
- * ...
- * }
- * </pre>
- * <p>
- *
- * Note that you can also create partial mocks by using the annotation. Let's
- * say that the PersonService has a method called "getPerson" and another method
- * called "savePerson" and these are the only two methods that you'd like to
- * mock. Rewriting the previous example to accommodate this will give us the
- * following test:
- *
- * <pre>
- * &#064;PowerMockListener(EasyMockAnnotationEnabler.class)
- * public class PersonServiceTest {
- *
- * &#064;MockNice({&quot;getPerson&quot;, &quot;savePerson&quot;})
- * private PersonDao personDaoMock;
- *
- * private PersonService classUnderTest;
- *
- * &#064;Before
- * public void setUp() {
- * classUnderTest = new PersonService(personDaoMock);
- * }
- * ...
- * }
- * </pre>
- * <p>
- *
- */
-
-@Target( { ElementType.FIELD })
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Inherited
-public @interface MockNice {
- String[] value() default "";
-}
@@ -1,66 +0,0 @@
-package org.powermock.api.easymock.annotation;
-
-import org.powermock.core.classloader.annotations.PowerMockListener;
-
-import java.lang.annotation.*;
-
-/**
- * This annotation can be placed on those fields in your test class that should
- * be mocked in a strict manner (i.e. the order of method calls are checked).
- * This eliminates the need to setup and tear-down mocks manually which
- * minimizes repetitive test code and makes the test more readable. In order for
- * PowerMock to control the life-cycle of the mocks you must supply the
- * {@link PowerMockListener} annotation to the class-level of the test case. For
- * example when using the EasyMock API:
- *
- * <pre>
- * &#064;PowerMockListener(EasyMockAnnotationEnabler.class)
- * public class PersonServiceTest {
- *
- * &#064;MockStrict
- * private PersonDao personDaoMock;
- *
- * private PersonService classUnderTest;
- *
- * &#064;Before
- * public void setUp() {
- * classUnderTest = new PersonService(personDaoMock);
- * }
- * ...
- * }
- * </pre>
- * <p>
- *
- * Note that you can also create partial mocks by using the annotation. Let's
- * say that the PersonService has a method called "getPerson" and another method
- * called "savePerson" and these are the only two methods that you'd like to
- * mock. Rewriting the previous example to accommodate this will give us the
- * following test:
- *
- * <pre>
- * &#064;PowerMockListener(EasyMockAnnotationEnabler.class)
- * public class PersonServiceTest {
- *
- * &#064;MockStrict({&quot;getPerson&quot;, &quot;savePerson&quot;})
- * private PersonDao personDaoMock;
- *
- * private PersonService classUnderTest;
- *
- * &#064;Before
- * public void setUp() {
- * classUnderTest = new PersonService(personDaoMock);
- * }
- * ...
- * }
- * </pre>
- * <p>
- *
- */
-
-@Target( { ElementType.FIELD })
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Inherited
-public @interface MockStrict {
- String[] value() default "";
-}
@@ -1,104 +0,0 @@
-/*
- * Copyright 2008 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.powermock.api.easymock.internal.invocationcontrol;
-
-import org.easymock.EasyMock;
-import org.easymock.IExpectationSetters;
-import org.easymock.internal.MocksControl;
-import org.powermock.core.MockRepository;
-import org.powermock.core.spi.NewInvocationControl;
-import org.powermock.core.spi.support.InvocationSubstitute;
-import org.powermock.reflect.internal.WhiteboxImpl;
-
-import java.lang.reflect.Constructor;
-
-public class NewInvocationControlImpl<T> implements NewInvocationControl<IExpectationSetters<T>> {
- private final InvocationSubstitute<T> substitute;
- private final Class<T> subsitutionType;
- private boolean hasReplayed;
- private boolean hasVerified;
-
- public NewInvocationControlImpl(InvocationSubstitute<T> substitute, Class<T> type) {
- if (substitute == null) {
- throw new IllegalArgumentException("Internal error: substitute cannot be null.");
- }
- this.subsitutionType = type;
- this.substitute = substitute;
- }
-
- @Override
- public Object invoke(Class<?> type, Object[] args, Class<?>[] sig) throws Exception {
- Constructor<?> constructor = WhiteboxImpl.getConstructor(type, sig);
- if (constructor.isVarArgs()) {
- /*
- * Get the last argument because this contains the actual varargs
- * arguments.
- */
- int length = constructor.getParameterTypes().length;
- args = (Object[]) args[length-1];
- }
- try {
- final MocksControl.MockType mockType = ((EasyMockMethodInvocationControl<?>) MockRepository.getInstanceMethodInvocationControl(substitute))
- .getMockType();
- Object result = substitute.performSubstitutionLogic(args);
-
- if (result == null) {
- if (mockType == MocksControl.MockType.NICE) {
- result = EasyMock.createNiceMock(subsitutionType);
- } else {
- throw new IllegalStateException("Must replay class " + type.getName() + " to get configured expectation.");
- }
- }
- return result;
- } catch (AssertionError e) {
- NewInvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type);
- }
-
- // Won't happen
- return null;
- }
-
- @Override
- public IExpectationSetters<T> expectSubstitutionLogic(Object... arguments) throws Exception {
- return EasyMock.expect(substitute.performSubstitutionLogic(arguments));
- }
-
- @Override
- public synchronized Object replay(Object... mocks) {
- if (!hasReplayed) {
- EasyMock.replay(substitute);
- hasReplayed = true;
- }
- return null;
- }
-
- @Override
- public synchronized Object verify(Object... mocks) {
- if (!hasVerified) {
- EasyMock.verify(substitute);
- hasVerified = true;
- }
- return null;
- }
-
- @Override
- public synchronized Object reset(Object... mocks) {
- EasyMock.reset(substitute);
- hasReplayed = false;
- hasVerified = false;
- return null;
- }
-}
@@ -1,9 +0,0 @@
-package org.powermock.api.easymock.internal.mockstrategy;
-
-import org.easymock.IMocksControl;
-
-public interface MockStrategy {
-
- IMocksControl createMockControl(Class<?> type);
-
-}
@@ -1,27 +0,0 @@
-package org.powermock.api.easymock.internal.mockstrategy.impl;
-
-import org.easymock.IMocksControl;
-import org.easymock.internal.MocksControl;
-import org.easymock.internal.MocksControl.MockType;
-import org.powermock.api.easymock.internal.mockstrategy.MockStrategy;
-
-/**
- * Base class that should be used by all mock strategies. Enables mocking of
- * signed classes.
- */
-public abstract class AbstractMockStrategyBase implements MockStrategy {
-
- private final MockType mockType;
-
- public AbstractMockStrategyBase(MockType mockType) {
- if (mockType == null) {
- throw new IllegalArgumentException("Internal error: mockType cannot be null");
- }
- this.mockType = mockType;
- }
-
- @Override
- public IMocksControl createMockControl(Class<?> type) {
- return new MocksControl(mockType);
- }
-}
@@ -1,10 +0,0 @@
-package org.powermock.api.easymock.internal.mockstrategy.impl;
-
-import org.easymock.internal.MocksControl.MockType;
-
-public class DefaultMockStrategy extends AbstractMockStrategyBase {
-
- public DefaultMockStrategy() {
- super(MockType.DEFAULT);
- }
-}
@@ -1,10 +0,0 @@
-package org.powermock.api.easymock.internal.mockstrategy.impl;
-
-import org.easymock.internal.MocksControl.MockType;
-
-public class NiceMockStrategy extends AbstractMockStrategyBase {
-
- public NiceMockStrategy() {
- super(MockType.NICE);
- }
-}
@@ -1,10 +0,0 @@
-package org.powermock.api.easymock.internal.mockstrategy.impl;
-
-import org.easymock.internal.MocksControl.MockType;
-
-public class StrictMockStrategy extends AbstractMockStrategyBase {
-
- public StrictMockStrategy() {
- super(MockType.STRICT);
- }
-}
Oops, something went wrong.

0 comments on commit e82e7f2

Please sign in to comment.