From 5c05337f38f32b74161180833b9bb3ea7ee482f6 Mon Sep 17 00:00:00 2001 From: Maria Kusber Date: Thu, 7 Nov 2024 11:40:46 +0000 Subject: [PATCH 1/5] Add a new annotation @MethodUnderTest Defined in a new subpackage "generated" to emphasise that this is not to be used by the user but assigned by Diffblue Cover itself. Using runtime retention - as I'm not sure is class would be enough for our purposes. The value parameter has no default value, to make sure that the annotation is only ever used with a value. Note: some of the other annotations are repeatable, this one should not be (only one annotation per test method should be used) --- .../generated/MethodUnderTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java diff --git a/src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java b/src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java new file mode 100644 index 0000000..d9436e4 --- /dev/null +++ b/src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java @@ -0,0 +1,32 @@ +/* + * Copyright 2024 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.generated; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Indicates the method being tested in the annotated test method. Diffblue Cover attaches this + * annotation to all tests that it creates. + */ +@Retention(RUNTIME) +@Target(METHOD) +public @interface MethodUnderTest { + + String[] value(); +} From ca586b06ec5ad9d6a3448b3e1d60ec72aa921020 Mon Sep 17 00:00:00 2001 From: Maria Kusber Date: Thu, 7 Nov 2024 16:37:14 +0000 Subject: [PATCH 2/5] Change retention to source This info is only needed on source code level --- .../diffblue/cover/annotations/generated/MethodUnderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java b/src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java index d9436e4..3862627 100644 --- a/src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java +++ b/src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java @@ -15,7 +15,7 @@ package com.diffblue.cover.annotations.generated; import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.RetentionPolicy.SOURCE; import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -24,7 +24,7 @@ * Indicates the method being tested in the annotated test method. Diffblue Cover attaches this * annotation to all tests that it creates. */ -@Retention(RUNTIME) +@Retention(SOURCE) @Target(METHOD) public @interface MethodUnderTest { From 5102bec91fe7436d10c6568131b52a0d7c509fa5 Mon Sep 17 00:00:00 2001 From: Maria Kusber Date: Fri, 8 Nov 2024 12:40:25 +0000 Subject: [PATCH 3/5] Rename the class to use plural --- .../generated/{MethodUnderTest.java => MethodsUnderTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/diffblue/cover/annotations/generated/{MethodUnderTest.java => MethodsUnderTest.java} (96%) diff --git a/src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java b/src/main/java/com/diffblue/cover/annotations/generated/MethodsUnderTest.java similarity index 96% rename from src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java rename to src/main/java/com/diffblue/cover/annotations/generated/MethodsUnderTest.java index 3862627..f391e23 100644 --- a/src/main/java/com/diffblue/cover/annotations/generated/MethodUnderTest.java +++ b/src/main/java/com/diffblue/cover/annotations/generated/MethodsUnderTest.java @@ -26,7 +26,7 @@ */ @Retention(SOURCE) @Target(METHOD) -public @interface MethodUnderTest { +public @interface MethodsUnderTest { String[] value(); } From 9dce00576ba7322f8d3fae999094868c6608fcd8 Mon Sep 17 00:00:00 2001 From: Maria Kusber Date: Fri, 8 Nov 2024 12:54:10 +0000 Subject: [PATCH 4/5] Move the annotation to the same package Javadoc explains the difference between this one and the testing-advice-ones enough, and "generated" was questionable --- .../cover/annotations/{generated => }/MethodsUnderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/diffblue/cover/annotations/{generated => }/MethodsUnderTest.java (95%) diff --git a/src/main/java/com/diffblue/cover/annotations/generated/MethodsUnderTest.java b/src/main/java/com/diffblue/cover/annotations/MethodsUnderTest.java similarity index 95% rename from src/main/java/com/diffblue/cover/annotations/generated/MethodsUnderTest.java rename to src/main/java/com/diffblue/cover/annotations/MethodsUnderTest.java index f391e23..42e3b9a 100644 --- a/src/main/java/com/diffblue/cover/annotations/generated/MethodsUnderTest.java +++ b/src/main/java/com/diffblue/cover/annotations/MethodsUnderTest.java @@ -12,7 +12,7 @@ * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package com.diffblue.cover.annotations.generated; +package com.diffblue.cover.annotations; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.SOURCE; From f02db7882ce3b1bcc9681791cf1eb08ce19a9a7e Mon Sep 17 00:00:00 2001 From: Maria Kusber Date: Fri, 8 Nov 2024 12:57:14 +0000 Subject: [PATCH 5/5] Fix typo in javadoc --- .../java/com/diffblue/cover/annotations/MethodsUnderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/diffblue/cover/annotations/MethodsUnderTest.java b/src/main/java/com/diffblue/cover/annotations/MethodsUnderTest.java index 42e3b9a..328ae8b 100644 --- a/src/main/java/com/diffblue/cover/annotations/MethodsUnderTest.java +++ b/src/main/java/com/diffblue/cover/annotations/MethodsUnderTest.java @@ -21,7 +21,7 @@ import java.lang.annotation.Target; /** - * Indicates the method being tested in the annotated test method. Diffblue Cover attaches this + * Indicates the methods being tested in the annotated test method. Diffblue Cover attaches this * annotation to all tests that it creates. */ @Retention(SOURCE)