From 4b81797f82d209e97cce50fb6112660400c543da Mon Sep 17 00:00:00 2001 From: ksan Date: Wed, 28 May 2025 12:37:01 +0100 Subject: [PATCH 1/4] TG-23050 Specifying returnValueFactory for @InTestsMock for Creating a Mocked Object --- .../java/com/diffblue/cover/annotations/InTestsMock.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/diffblue/cover/annotations/InTestsMock.java b/src/main/java/com/diffblue/cover/annotations/InTestsMock.java index 5fc0fd6..432aa7c 100644 --- a/src/main/java/com/diffblue/cover/annotations/InTestsMock.java +++ b/src/main/java/com/diffblue/cover/annotations/InTestsMock.java @@ -81,4 +81,10 @@ /** @return String value or values to return from the {@link #method()} */ String[] stringReturnValues() default {}; + + /** + * @return name of the factory method used to create the object returned by the mocked {@link + * #method()} + */ + String returnValueFactory() default ""; } From 1449aeb8950699941aecfd86710d659ee51cb95f Mon Sep 17 00:00:00 2001 From: thomasperkins1123 Date: Tue, 3 Jun 2025 16:04:10 +0100 Subject: [PATCH 2/4] Use new maven central portal --- .github/settings.xml | 6 +++--- pom.xml | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/settings.xml b/.github/settings.xml index 4c687a0..67f2297 100644 --- a/.github/settings.xml +++ b/.github/settings.xml @@ -8,9 +8,9 @@ ${env.GPG_PASSPHRASE} - ossrh - ${env.MAVEN_USERNAME} - ${env.MAVEN_PASSWORD} + central + ${env.MAVEN_USERNAME} + ${env.MAVEN_PASSWORD} diff --git a/pom.xml b/pom.xml index 3a51e16..6a44738 100644 --- a/pom.xml +++ b/pom.xml @@ -71,14 +71,13 @@ - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.13 + org.sonatype.central + central-publishing-maven-plugin + 0.7.0 true - ossrh - https://oss.sonatype.org/ - true + central + true From 17f88455af7480d2926f1562c454261a197d3e9f Mon Sep 17 00:00:00 2001 From: ksan Date: Wed, 4 Jun 2025 09:11:44 +0100 Subject: [PATCH 3/4] TG-23051 Specifying throwException and throwExceptionFactory for @InTestsMock when the mocked method is called --- .../cover/annotations/InTestsMock.java | 13 ++++++++++ .../annotations/exceptions/NoException.java | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/com/diffblue/cover/annotations/exceptions/NoException.java diff --git a/src/main/java/com/diffblue/cover/annotations/InTestsMock.java b/src/main/java/com/diffblue/cover/annotations/InTestsMock.java index 432aa7c..eb944d5 100644 --- a/src/main/java/com/diffblue/cover/annotations/InTestsMock.java +++ b/src/main/java/com/diffblue/cover/annotations/InTestsMock.java @@ -20,6 +20,7 @@ import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; +import com.diffblue.cover.annotations.exceptions.NoException; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -87,4 +88,16 @@ * #method()} */ String returnValueFactory() default ""; + + /** + * @return exception type to throw when the mocked {@link #method()} is called. Defaults to {@link + * NoException} to indicate no exception should be thrown. + */ + Class throwException() default NoException.class; + + /** + * @return fully qualified name of the factory method used to create the exception to throw when + * the mocked {@link #method()} is called. + */ + String throwExceptionFactory() default ""; } diff --git a/src/main/java/com/diffblue/cover/annotations/exceptions/NoException.java b/src/main/java/com/diffblue/cover/annotations/exceptions/NoException.java new file mode 100644 index 0000000..6249ef7 --- /dev/null +++ b/src/main/java/com/diffblue/cover/annotations/exceptions/NoException.java @@ -0,0 +1,25 @@ +/* + * Copyright 2025 Diffblue Limited. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file 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 com.diffblue.cover.annotations.exceptions; + +/** + * Marker class used to indicate that no exception should be thrown by default in {@link + * com.diffblue.cover.annotations.InTestsMock#throwException()}. + */ +public final class NoException extends Throwable { + private NoException() { + // This class should not be instantiated. + } +} From 1c4f51818dc617edbd447ef097a911bbfbbf5f52 Mon Sep 17 00:00:00 2001 From: ksan Date: Wed, 4 Jun 2025 09:13:28 +0100 Subject: [PATCH 4/4] TG-23051 update version 1.6.0 --- README.md | 4 ++-- pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 570e232..87331f2 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ For installation into a Gradle project the `compileOnly` and `testImplementation ``` dependencies { - compileOnly("com.diffblue.cover:cover-annotations:1.5.0") + compileOnly("com.diffblue.cover:cover-annotations:1.6.0") - testImplementation("com.diffblue.cover:cover-annotations:1.5.0") + testImplementation("com.diffblue.cover:cover-annotations:1.6.0") } ``` diff --git a/pom.xml b/pom.xml index 6a44738..4752e23 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ 4.0.0 com.diffblue.cover cover-annotations - 1.5.0 + 1.6.0 jar Cover Annotations