-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Mockito Public API to create a mock
- Loading branch information
Arthur Zagretdinov
committed
Jul 15, 2017
1 parent
e056fc6
commit 9c63613
Showing
14 changed files
with
357 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...src/main/java/org/powermock/api/mockito/expectation/ConstructorAwareExpectationSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2016 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.mockito.expectation; | ||
|
||
import org.mockito.stubbing.OngoingStubbing; | ||
import org.powermock.api.mockito.expectation.DefaultConstructorExpectationSetup; | ||
import org.powermock.api.mockito.expectation.WithOrWithoutExpectedArguments; | ||
|
||
import java.lang.reflect.Constructor; | ||
|
||
public class ConstructorAwareExpectationSetup<T> implements WithOrWithoutExpectedArguments<T> { | ||
|
||
private final Constructor<T> ctor; | ||
private final DefaultConstructorExpectationSetup<T> expectationSetup; | ||
|
||
public ConstructorAwareExpectationSetup(Constructor<T> ctor) { | ||
if (ctor == null) { | ||
throw new IllegalArgumentException("Constructor to expect cannot be null"); | ||
} | ||
this.ctor = ctor; | ||
this.expectationSetup = setupExpectation(); | ||
} | ||
|
||
@Override | ||
public OngoingStubbing<T> withArguments(Object firstArgument, Object... additionalArguments) throws Exception { | ||
return expectationSetup.withArguments(firstArgument, additionalArguments); | ||
} | ||
|
||
@Override | ||
public OngoingStubbing<T> withNoArguments() throws Exception { | ||
return expectationSetup.withNoArguments(); | ||
} | ||
|
||
private DefaultConstructorExpectationSetup<T> setupExpectation() { | ||
DefaultConstructorExpectationSetup<T> setup = new DefaultConstructorExpectationSetup<T>(ctor.getDeclaringClass()); | ||
setup.setParameterTypes(ctor.getParameterTypes()); | ||
return setup; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
...java/org/powermock/api/mockito/internal/expectation/ConstructorAwareExpectationSetup.java
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
...va/org/powermock/api/mockito/internal/expectation/DefaultConstructorExpectationSetup.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.