-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MockitoMockMaker provides mocking of static methods
MockitoMockMaker supports to mock static methods of Java classes with the new Spec API: `MockStatic()` `StubStatic()` `SpyStatic()` This also supports Java callers of the static methods. Added MockUtil.isStaticMock() Added code to use public Mockito API introduced with mockito/mockito#3129 Moved IMockMakerSettings and MockMakerId to package spock.mock. Co-authored-by: Leonard Brünings <[email protected]>
- Loading branch information
Showing
41 changed files
with
2,128 additions
and
326 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
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
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
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
54 changes: 54 additions & 0 deletions
54
spock-core/src/main/java/org/spockframework/mock/IStaticMockController.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,54 @@ | ||
/* | ||
* Copyright 2023 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 | ||
* | ||
* https://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.spockframework.mock; | ||
|
||
import org.spockframework.mock.runtime.IMockMaker; | ||
import org.spockframework.util.Beta; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* The {@code IStaticMockController} provides API to activate a static mocks on non-test {@link Thread Threads}. | ||
* | ||
* @since 2.4 | ||
*/ | ||
@Beta | ||
public interface IStaticMockController { | ||
/** | ||
* Runs the code with the static mocks activated on the current {@link Thread}. | ||
* | ||
* <p>Note: You only need this if your current {@code Thread} is not the test thread. | ||
* On the test {@code Thread}, the static mocks is automatically activated.</p> | ||
* | ||
* @param code the code to execute | ||
*/ | ||
void runWithActiveStaticMocks(Runnable code); | ||
|
||
/** | ||
* Runs the code with the static mocks activated on the current {@link Thread}. | ||
* | ||
* <p>Note: You only need this if your current {@code Thread} is not the test thread. | ||
* On the test {@code Thread}, the static mocks is automatically activated.</p> | ||
* | ||
* @param <R> the return type | ||
* @param code the code to execute | ||
* @return the return value of the executed code | ||
*/ | ||
<R> R withActiveStaticMocks(Callable<R> code); | ||
|
||
void registerStaticMock(IMockMaker.IStaticMock staticMock); | ||
} |
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
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.