-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial migration of code * Moved build.gradle.kts to correct location in root * build.gradle.kts: fixed wrapper reference
- Loading branch information
1 parent
07085ee
commit 6bb58cd
Showing
14 changed files
with
605 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,72 @@ | ||
# Mockito Support for jqwik | ||
|
||
Provides `net.jqwik.api.lifecycle.LifecycleHook`s to enable usage of Mockito with jqwik. | ||
- Creates mocks for any fields with Mockito annotations such as `org.mockito.Mock` or `org.mockito.Spy`. | ||
- Resets all mocks between each try, whether those mocks were created programmatically (eg: via calls to `Mockito.mock()`}) or via annotations. | ||
|
||
## How to use | ||
|
||
### Maven and Gradle configuration | ||
Maven: | ||
```xml | ||
<dependency> | ||
<group>net.jqwik.mockito</group> | ||
<artifactId>jqwik-mockito</artifactId> | ||
<version>$LATEST_VERSION</version> | ||
<scope>test</scope> | ||
</dependency> | ||
``` | ||
|
||
Gradle: | ||
``` | ||
testImplementation("net.jqwik.mockito:jqwik-mockito:$LATEST_VERSION") | ||
``` | ||
|
||
### Usage in Tests | ||
```java | ||
import net.jqwik.api.lifecycle.AddLifecycleHook; | ||
import net.jqwik.api.*; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.Spy; | ||
|
||
## Compatibility | ||
import static org.mockito.Mockito.*; | ||
|
||
@AddLifecycleHook(MockitoLifecycleHooks.class) | ||
class OrderServiceTest { | ||
// Either @Mock or Mockito.mock() can be used. | ||
@Mock | ||
private OrderRepository orderRepository; | ||
private OrderRepository orderRepository2 = Mockito.mock(); | ||
|
||
// Either @Spy or Mockito.spy() can be used. | ||
@Spy | ||
private ConsoleLoggingServiceImpl loggingService; | ||
private LoggingService loggingService2 = Mockito.spy(new ConsoleLoggingServiceImpl()); | ||
|
||
- Which Mockito versions are supported? | ||
@InjectMock | ||
private OrderService orderService; | ||
|
||
@Group | ||
class BasicExamples { | ||
@Example | ||
void testBasicExample() { | ||
when(orderRepository.getOrder(any())).thenReturn(null); | ||
// testing code | ||
} | ||
} | ||
|
||
@Group | ||
class SomeProperties { | ||
@Property | ||
void testProperty() { | ||
when(orderRepository.getOrder(any())).thenReturn("orderId"); | ||
// testing code | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Compatibility | ||
This is built against Mockito v4, and should support for all versions. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
plugins { | ||
id("java-library") | ||
id("maven-publish") | ||
id("signing") | ||
id("com.diffplug.spotless") version "6.13.0" | ||
} | ||
|
||
fun isSnapshotRelease(versionString: String): Boolean { | ||
return versionString.endsWith("SNAPSHOT") | ||
} | ||
|
||
val githubProjectName = "jqwik-team" | ||
val artifactId = "jqwik-mockito" | ||
val moduleGroupId = "net.jqwik" | ||
val moduleName = "net.jqwik.mockito" | ||
val junitPlatformVersion = "1.11.2" | ||
val junitJupiterVersion = "5.11.2" | ||
val opentest4jVersion = "1.3.0" | ||
val assertJVersion = "3.26.3" | ||
val mockitoVersion = "4.11.0" // Mockito 5+ no longer supports Java 8 | ||
val jqwikVersion = "1.9.1" | ||
val lombokVersion = "1.18.34" | ||
val jqwikMockitoVersion = "0.0.1-SNAPSHOT" | ||
val isSnapshotRelease = isSnapshotRelease(jqwikMockitoVersion) | ||
|
||
group = moduleName | ||
version = jqwikMockitoVersion | ||
description = "Jqwik Mockito support module" | ||
|
||
repositories { | ||
mavenCentral() | ||
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots") | ||
} | ||
|
||
tasks.jar { | ||
archiveBaseName.set(artifactId) | ||
archiveVersion.set(jqwikMockitoVersion) | ||
manifest { | ||
attributes("Automatic-Module-Name" to moduleName) | ||
} | ||
} | ||
|
||
spotless { | ||
java { | ||
palantirJavaFormat("1.1.0") | ||
|
||
importOrder("", "java|javax", "\\#") | ||
removeUnusedImports() | ||
} | ||
} | ||
|
||
java { | ||
withJavadocJar() | ||
withSourcesJar() | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(8) | ||
} | ||
} | ||
|
||
tasks.compileTestJava { | ||
options.compilerArgs.add("-parameters") | ||
options.encoding = "UTF-8" | ||
} | ||
|
||
tasks.named("check") { | ||
dependsOn(tasks.named("spotlessApply")) | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform { | ||
includeEngines("jqwik") | ||
} | ||
} | ||
|
||
dependencies { | ||
api("org.opentest4j:opentest4j:${opentest4jVersion}") | ||
api("net.jqwik:jqwik:${jqwikVersion}") | ||
compileOnly("org.mockito:mockito-core:${mockitoVersion}") | ||
compileOnly("org.mockito:mockito-junit-jupiter:${mockitoVersion}") | ||
|
||
testCompileOnly("org.projectlombok:lombok:${lombokVersion}") | ||
testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}") | ||
|
||
testImplementation("org.junit.jupiter:junit-jupiter:${junitJupiterVersion}") | ||
testImplementation("org.assertj:assertj-core:${assertJVersion}") | ||
testImplementation("org.mockito:mockito-junit-jupiter:${mockitoVersion}") | ||
} | ||
|
||
publishing { | ||
repositories { | ||
maven { | ||
// hint: password is in ~/.gradle/gradle.properties | ||
val ossrhUsername: String = project.findProperty("ossrhUsername") as? String ?: "" | ||
val ossrhPassword: String = project.findProperty("ossrhPassword") as? String ?: "" | ||
|
||
credentials { | ||
username = ossrhUsername | ||
password = ossrhPassword | ||
} | ||
|
||
// change URLs to point to your repos, e.g. http://my.org/repo | ||
val releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" | ||
val snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" | ||
url = uri(if (isSnapshotRelease) { snapshotsRepoUrl } else { releasesRepoUrl }) | ||
} | ||
} | ||
publications { | ||
create<MavenPublication>("jqwikMockito") { | ||
groupId = moduleGroupId | ||
artifactId = artifactId | ||
from(components["java"]) | ||
pom { | ||
groupId = moduleGroupId | ||
name = artifactId | ||
description = "Jqwik Mockito support module" | ||
url = "https://github.org/$githubProjectName/$artifactId" | ||
licenses { | ||
license { | ||
name = "Eclipse Public License - v 2.0" | ||
url = "http://www.eclipse.org/legal/epl-v20.html" | ||
} | ||
} | ||
developers { | ||
developer { | ||
id = "agustafson-atl" | ||
name = "Andrew Gustafson" | ||
email = "[email protected]" | ||
} | ||
developer { | ||
id = githubProjectName | ||
name = "Johannes Link" | ||
email = "[email protected]" | ||
} | ||
} | ||
scm { | ||
connection = "scm:git:git://github.com/$githubProjectName/$artifactId.git" | ||
developerConnection = "scm:git:git://github.com/$githubProjectName/$artifactId.git" | ||
url = "https://github.com/$githubProjectName/$artifactId" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
signing { | ||
if (!isSnapshotRelease) { | ||
sign(publishing.publications["jqwikMockito"]) | ||
} | ||
} | ||
|
||
tasks.wrapper { | ||
gradleVersion = "8.11.1" // upgrade with: ./gradlew wrapper | ||
} |
File renamed without changes.
Oops, something went wrong.