Skip to content

Commit 1043a10

Browse files
author
Maria Kusber
authored
Merge pull request #17 from diffblue/develop
Release 1.2.0
2 parents 7360adb + 6b13dad commit 1043a10

File tree

3 files changed

+70
-58
lines changed

3 files changed

+70
-58
lines changed

README.md

+29-49
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,21 @@
1-
# Cover Annotations
1+
<h1 align="center">Cover Annotations</h1>
22

3-
Cover Annotations allows users to annotate their Java codebase with advice on how best to test it.
4-
In turn this can be used by [Diffblue Cover](https://diffblue.com/cover) to tune the tests it writes.
5-
6-
## Installation
3+
<div align="center">
74

8-
### Maven
5+
[![Apache 2.0](https://img.shields.io/github/license/diffblue/cover-annotations)](https://www.apache.org/licenses/LICENSE-2.0)
6+
[![Maven Central](https://img.shields.io/maven-central/v/com.diffblue.cover/cover-annotations.svg)](https://central.sonatype.com/artifact/com.diffblue.cover/cover-annotations/overview)
97

10-
In order to use the annotations in your Maven project then the Diffblue repository and `cover-annotations` dependency will need to be added into your `pom.xml`:
8+
</div>
119

12-
```xml
13-
<dependencies>
14-
<dependency>
15-
<groupId>com.diffblue.cover</groupId>
16-
<artifactId>cover-annotations</artifactId>
17-
<version>1.0.0</version>
18-
</dependency>
19-
</dependencies>
20-
```
21-
22-
### Gradle
23-
24-
In order to use the annotations in your Gradle project then the Diffblue repository and `cover-annotations` dependency will need to be added into your `build.gradle`:
10+
Cover Annotations allows users to annotate their Java codebase with advice on how best to test it.
11+
In turn this can be used by [Diffblue Cover](https://diffblue.com/cover) to tune the tests it writes.
2512

26-
```gradle
27-
dependencies {
28-
implementation("com.diffblue.cover:cover-annotations:1.0.0")
29-
}
30-
```
13+
## Installation
3114

32-
Or similarly for `build.gradle.kts`:
15+
Cover Annotations is published in the [Maven central repository](https://central.sonatype.com/artifact/com.diffblue.cover/cover-annotations/overview).
16+
In order to use the annotations simply add `cover-annotations` as a dependency to your project, for example copying the snippet for Maven or Gradle from the repository page.
3317

34-
```
35-
dependencies {
36-
implementation("com.diffblue.cover:cover-annotations:1.0.0")
37-
}
38-
```
18+
## Usage
3919

4020
Annotations placed on packages affect tests for all classes and methods under test in that package.
4121
Annotations placed on classes affect tests for that class and all its methods under test, overriding package level annotations.
@@ -44,11 +24,11 @@ Annotations placed on methods affect just that method under test, overriding pac
4424
The annotations will be respected by Diffblue Cover via both command line and IntelliJ Plugin.
4525
When used from the command line in conjunction with equivalent options then the command line options take priority over the annotations found.
4626

47-
## Mocking Annotations
27+
### Mocking Annotations
4828

4929
Mocking annotations allow fine grained control over what mocking should be preferred when testing.
5030

51-
### Using `@InTestsMock`
31+
#### Using `@InTestsMock`
5232

5333
Perhaps you have a method that Diffblue Cover would ordinarily test using an `Integer` but you'd prefer to see it tested using `Mockito.mock(..)`.
5434
In this case you could annotate the method (or class, or package) to recommend mocking `Number`:
@@ -80,7 +60,7 @@ public class ClassUnderTest {
8060
> dcover create --mock ClassToMock --disable-mock-inputs ClassToForbidMocking
8161
> ```
8262
83-
### Using `@InTestsMockConstruction`
63+
#### Using `@InTestsMockConstruction`
8464
8565
Perhaps you have a method that Diffblue Cover is unable to test, and you think it could make more progress using `Mockito.mockConstruction(Random.class)`.
8666
In this case you could annotate the method (or class, or package) to recommend mocking construction of `Random`:
@@ -101,7 +81,7 @@ public class ClassUnderTest {
10181
> dcover create --mock-construction ClassToMockConstruction
10282
> ```
10383
104-
### Using `@InTestsMockStatic`
84+
#### Using `@InTestsMockStatic`
10585
10686
Perhaps you have a method that Diffblue Cover is unable to test, and you think it could make more progress using `Mockito.mockStatic(UUID.class)`.
10787
In this case you could annotate the method (or class, or package) to recommend mocking static methods of `UUID`:
@@ -122,13 +102,13 @@ public class ClassUnderTest {
122102
> dcover create --mock-static ClassToMockStatic
123103
> ```
124104
125-
## Custom Input Annotations
105+
### Custom Input Annotations
126106
127107
Custom input annotations allow particular inputs to be recommended to Diffblue Cover when writing tests.
128108
129-
### Using `@InTestsUseEnum`
109+
#### Using `@InTestsUseEnums`
130110
131-
The `@InTestsUseEnum` annotation allows the user to recommend specific `enum` literal values to use in tests.
111+
The `@InTestsUseEnums` annotation allows the user to recommend specific `enum` literal values to use in tests.
132112
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
133113
134114
```java
@@ -137,7 +117,7 @@ public static boolean isDateOrTimeBased(@InTestsUseEnums({"SECONDS", "YEARS", "F
137117
}
138118
```
139119
140-
### Using `@InTestsUseClasses`
120+
#### Using `@InTestsUseClasses`
141121

142122
The `@InTestsUseClasses` annotation allows the user to recommend specific `Class` literal values to use in tests.
143123
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
@@ -149,7 +129,7 @@ public static boolean isAnnotation(@InTestsUseClasses(Nullable.class) Class<?> t
149129
}
150130
```
151131

152-
### Using `@InTestsUseStrings`
132+
#### Using `@InTestsUseStrings`
153133

154134
The `@InTestsUseStrings` annotation allows the user to recommend specific `String` values to use in tests.
155135
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
@@ -164,7 +144,7 @@ public static boolean isDayRelatedSongTitle(@InTestsUseStrings({"I Don't Like Mo
164144
}
165145
```
166146

167-
### Using `@InTestsUseCharacters`
147+
#### Using `@InTestsUseCharacters`
168148

169149
The `@InTestsUseCharacters` annotation allows the user to recommend specific `char` values to use in tests.
170150
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
@@ -182,7 +162,7 @@ public static Integer toNullableCodePoint(
182162
}
183163
```
184164

185-
### Using `@InTestsUseBytes`
165+
#### Using `@InTestsUseBytes`
186166

187167
The `@InTestsUseBytes` annotation allows the user to recommend specific `byte` values to use in tests.
188168
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
@@ -194,7 +174,7 @@ public static String toUpperHexString(@InTestsUseBytes((byte)0xD1) byte input) {
194174
}
195175
```
196176

197-
### Using `@InTestsUseShorts`
177+
#### Using `@InTestsUseShorts`
198178

199179
The `@InTestsUseShorts` annotation allows the user to recommend specific `short` values to use in tests.
200180
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
@@ -206,7 +186,7 @@ public static String toUpperHexString(@InTestsUseShorts((short)0xD1FF) short inp
206186
}
207187
```
208188

209-
### Using `@InTestsUseIntegers`
189+
#### Using `@InTestsUseIntegers`
210190

211191
The `@InTestsUseIntegers` annotation allows the user to recommend specific `int` values to use in tests.
212192
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
@@ -218,7 +198,7 @@ public static String toUpperHexString(@InTestsUseIntegers(0xD1FFB) int input) {
218198
}
219199
```
220200

221-
### Using `@InTestsUseLongs`
201+
#### Using `@InTestsUseLongs`
222202

223203
The `@InTestsUseLongs` annotation allows the user to recommend specific `long` values to use in tests.
224204
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
@@ -230,7 +210,7 @@ public static String toUpperHexString(@InTestsUseLongs(0xD1FFBL) long input) {
230210
}
231211
```
232212

233-
### Using `@InTestsUseFloats`
213+
#### Using `@InTestsUseFloats`
234214

235215
The `@InTestsUseFloats` annotation allows the user to recommend specific `float` values to use in tests.
236216
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
@@ -242,7 +222,7 @@ public static boolean isNearPi(@InTestsUseFloats(3.14159f) float input) {
242222
}
243223
```
244224

245-
### Using `@InTestsUseDoubles`
225+
#### Using `@InTestsUseDoubles`
246226

247227
The `@InTestsUseDoubles` annotation allows the user to recommend specific `double` values to use in tests.
248228
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
@@ -254,11 +234,11 @@ public static boolean isNearPi(@InTestsUseDoubles(Math.PI) float input) {
254234
}
255235
```
256236

257-
## Interesting Value Annotations
237+
### Interesting Value Annotations
258238

259239
Interesting value annotations allow users to promote existing fields and methods to be identified and used in particular roles by Diffblue Cover when writing tests.
260240

261-
### Using `@InterestingTestFactory`
241+
#### Using `@InterestingTestFactory`
262242

263243
Indicates the annotated method as a useful factory method for use in tests.
264244
Cover will automatically recognise factory methods that simply return a newly created instance, but may not identify more complicated factories.

pom.xml

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<modelVersion>4.0.0</modelVersion>
1717
<groupId>com.diffblue.cover</groupId>
1818
<artifactId>cover-annotations</artifactId>
19-
<version>1.1.0</version>
19+
<version>1.2.0</version>
2020
<packaging>jar</packaging>
2121

2222
<name>Cover Annotations</name>
@@ -46,15 +46,15 @@
4646
</scm>
4747

4848
<distributionManagement>
49+
<repository>
50+
<id>ossrh</id>
51+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
52+
</repository>
4953
<snapshotRepository>
5054
<id>ossrh</id>
5155
<!-- nb this must be the same as the 'id' field in 'settings.xml' -->
5256
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
5357
</snapshotRepository>
54-
<repository>
55-
<id>ossrh</id>
56-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
57-
</repository>
5858
</distributionManagement>
5959

6060
<properties>
@@ -63,8 +63,8 @@
6363
<maven.compiler.plugin.version>3.13.0</maven.compiler.plugin.version>
6464
<maven.javadoc.plugin.version>3.6.3</maven.javadoc.plugin.version>
6565
<maven.source.plugin.version>3.3.0</maven.source.plugin.version>
66-
<maven.spotless.plugin.version>2.10.0</maven.spotless.plugin.version>
67-
<google.java.format.version>1.17.0</google.java.format.version>
66+
<maven.spotless.plugin.version>2.30.0</maven.spotless.plugin.version>
67+
<google.java.format.version>1.7</google.java.format.version>
6868
<gpg.plugin.version>3.2.1</gpg.plugin.version>
6969
</properties>
7070

@@ -111,10 +111,10 @@
111111
<executions>
112112
<execution>
113113
<id>attach-sources</id>
114-
<phase>verify</phase>
115114
<goals>
116115
<goal>jar</goal>
117116
</goals>
117+
<phase>verify</phase>
118118
</execution>
119119
</executions>
120120
</plugin>
@@ -127,10 +127,10 @@
127127
<executions>
128128
<execution>
129129
<id>attach-javadocs</id>
130-
<phase>verify</phase>
131130
<goals>
132131
<goal>jar</goal>
133132
</goals>
133+
<phase>verify</phase>
134134
<configuration>
135135
<source>8</source>
136136
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2024 Diffblue Limited.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
package com.diffblue.cover.annotations;
16+
17+
import static java.lang.annotation.ElementType.METHOD;
18+
import static java.lang.annotation.RetentionPolicy.SOURCE;
19+
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.Target;
22+
23+
/**
24+
* Indicates the methods being tested in the annotated test method. Diffblue Cover attaches this
25+
* annotation to all tests that it creates.
26+
*/
27+
@Retention(SOURCE)
28+
@Target(METHOD)
29+
public @interface MethodsUnderTest {
30+
31+
String[] value();
32+
}

0 commit comments

Comments
 (0)