forked from spring-projects/spring-petclinic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TGWDB/Add-Diffblue-Workflow
Add Diffblue workflow
- Loading branch information
Showing
24 changed files
with
2,657 additions
and
29 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# This template is provided and maintained by Diffblue. | ||
# You can copy and paste this template into a new `diffblue-cover.yml` file. | ||
# This template is designed to be used with the Cover Pipeline for Github integration from Diffblue. | ||
# It will download the latest version of Diffblue Cover, build the associated project, and | ||
# automatically write Java unit tests for the project. | ||
|
||
name: Automated Test Creation with Diffblue Cover | ||
|
||
# Diffblue Cover runs on pull_request events for now. | ||
on: pull_request | ||
|
||
jobs: | ||
RunDiffblueCoverAutomatedTestCreation: | ||
runs-on: ubuntu-latest | ||
|
||
# Select the Cover CLI docker image to use with your CI tool. | ||
# Tag variations are produced for each supported JDK version. | ||
# Go to https://hub.docker.com/r/diffblue/cover-cli for details. | ||
# Note: To use the latest version of Diffblue Cover, use one of the latest-jdk<nn> tags. | ||
# To use a specific release version, use one of the yyyy.mm.dd-jdk<nn> tags | ||
container: diffblue/internal-cover-cli:202401-github-2024.01.02-snapshot-jdk17 | ||
|
||
steps: | ||
- name: Checkout project | ||
uses: actions/checkout@v4 | ||
with: | ||
set-safe-directory: true | ||
fetch-depth: 0 | ||
# Diffblue Cover requires the project to be built before creating any tests. | ||
# Either specify the build command here (one of the following), or provide | ||
# prebuilt artifacts via a job dependency. | ||
- name: Build Project | ||
run: mvn test-compile --batch-mode --no-transfer-progress | ||
|
||
# Diffblue Cover commands and options to run. | ||
# dcover – the core Diffblue Cover command | ||
# ci – enable CI/CD integration via environment variables | ||
# activate - activate the license key | ||
# validate - remove non-compiling and failing tests | ||
# create - create new tests for your project | ||
# --maven – use the maven build tool | ||
# For detailed information on Cover CLI commands and options, see | ||
# https://docs.diffblue.com/features/cover-cli/commands-and-arguments | ||
- name: Run Diffblue Cover | ||
env: | ||
DIFFBLUE_ACCESS_TOKEN: ${{ secrets.DIFFBLUE_ACCESS_TOKEN }} | ||
GITHUB_PR_NUMBER: ${{ github.event.number }} | ||
GITHUB_REPO_NAME: spring-petclinic-GitHub-demo-1 | ||
JVM_ARGS: -Xmx4g | ||
run: | | ||
git config --global --add safe.directory /__w/$GITHUB_REPO_NAME/$GITHUB_REPO_NAME | ||
dcover ci activate ${{ secrets.DIFFBLUE_LICENSE }} validate create |
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 |
---|---|---|
|
@@ -15,3 +15,6 @@ build/* | |
_site/ | ||
*.css | ||
!petclinic.css | ||
# Diffblue Cover files | ||
**/.diffblue/ | ||
|
39 changes: 39 additions & 0 deletions
39
src/test/java/org/springframework/samples/petclinic/PetClinicRuntimeHintsDiffblueTest.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,39 @@ | ||
package org.springframework.samples.petclinic; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.net.URLStreamHandlerFactory; | ||
import java.nio.file.Paths; | ||
import javax.management.loading.MLet; | ||
import org.apache.catalina.webresources.ClasspathURLStreamHandler; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import org.springframework.aot.hint.RuntimeHints; | ||
|
||
class PetClinicRuntimeHintsDiffblueTest { | ||
/** | ||
* Method under test: | ||
* {@link PetClinicRuntimeHints#registerHints(RuntimeHints, ClassLoader)} | ||
*/ | ||
@Test | ||
void testRegisterHints() throws MalformedURLException { | ||
// Arrange | ||
PetClinicRuntimeHints petClinicRuntimeHints = new PetClinicRuntimeHints(); | ||
RuntimeHints hints = new RuntimeHints(); | ||
URLStreamHandlerFactory urlStreamHandlerFactory = mock(URLStreamHandlerFactory.class); | ||
when(urlStreamHandlerFactory.createURLStreamHandler(Mockito.<String>any())) | ||
.thenReturn(new ClasspathURLStreamHandler()); | ||
|
||
// Act | ||
petClinicRuntimeHints.registerHints(hints, | ||
new URLClassLoader(new URL[]{Paths.get(System.getProperty("java.io.tmpdir"), "test.txt").toUri().toURL()}, | ||
new MLet(), urlStreamHandlerFactory)); | ||
|
||
// Assert | ||
verify(urlStreamHandlerFactory).createURLStreamHandler(Mockito.<String>any()); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/org/springframework/samples/petclinic/model/BaseEntityDiffblueTest.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,49 @@ | ||
package org.springframework.samples.petclinic.model; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class BaseEntityDiffblueTest { | ||
/** | ||
* Methods under test: | ||
* | ||
* <ul> | ||
* <li>default or parameterless constructor of {@link BaseEntity} | ||
* <li>{@link BaseEntity#setId(Integer)} | ||
* <li>{@link BaseEntity#getId()} | ||
* </ul> | ||
*/ | ||
@Test | ||
void testGettersAndSetters() { | ||
// Arrange and Act | ||
BaseEntity actualBaseEntity = new BaseEntity(); | ||
actualBaseEntity.setId(1); | ||
|
||
// Assert that nothing has changed | ||
assertEquals(1, actualBaseEntity.getId().intValue()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link BaseEntity#isNew()} | ||
*/ | ||
@Test | ||
void testIsNew() { | ||
// Arrange, Act and Assert | ||
assertTrue((new BaseEntity()).isNew()); | ||
} | ||
|
||
/** | ||
* Method under test: {@link BaseEntity#isNew()} | ||
*/ | ||
@Test | ||
void testIsNew2() { | ||
// Arrange | ||
BaseEntity baseEntity = new BaseEntity(); | ||
baseEntity.setId(1); | ||
|
||
// Act and Assert | ||
assertFalse(baseEntity.isNew()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/org/springframework/samples/petclinic/model/NamedEntityDiffblueTest.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,28 @@ | ||
package org.springframework.samples.petclinic.model; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class NamedEntityDiffblueTest { | ||
/** | ||
* Methods under test: | ||
* | ||
* <ul> | ||
* <li>default or parameterless constructor of {@link NamedEntity} | ||
* <li>{@link NamedEntity#setName(String)} | ||
* <li>{@link NamedEntity#toString()} | ||
* <li>{@link NamedEntity#getName()} | ||
* </ul> | ||
*/ | ||
@Test | ||
void testGettersAndSetters() { | ||
// Arrange and Act | ||
NamedEntity actualNamedEntity = new NamedEntity(); | ||
actualNamedEntity.setName("Bella"); | ||
String actualToStringResult = actualNamedEntity.toString(); | ||
|
||
// Assert that nothing has changed | ||
assertEquals("Bella", actualNamedEntity.getName()); | ||
assertEquals("Bella", actualToStringResult); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/org/springframework/samples/petclinic/model/PersonDiffblueTest.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,30 @@ | ||
package org.springframework.samples.petclinic.model; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class PersonDiffblueTest { | ||
/** | ||
* Methods under test: | ||
* | ||
* <ul> | ||
* <li>default or parameterless constructor of {@link Person} | ||
* <li>{@link Person#setFirstName(String)} | ||
* <li>{@link Person#setLastName(String)} | ||
* <li>{@link Person#getFirstName()} | ||
* <li>{@link Person#getLastName()} | ||
* </ul> | ||
*/ | ||
@Test | ||
void testGettersAndSetters() { | ||
// Arrange and Act | ||
Person actualPerson = new Person(); | ||
actualPerson.setFirstName("Jane"); | ||
actualPerson.setLastName("Doe"); | ||
String actualFirstName = actualPerson.getFirstName(); | ||
|
||
// Assert that nothing has changed | ||
assertEquals("Doe", actualPerson.getLastName()); | ||
assertEquals("Jane", actualFirstName); | ||
} | ||
} |
Oops, something went wrong.