Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Diffblue workflow #1

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/diffblue-cover.yml
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
29 changes: 0 additions & 29 deletions .github/workflows/maven-build.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ build/*
_site/
*.css
!petclinic.css
# Diffblue Cover files
**/.diffblue/

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());
}
}
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());
}
}
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);
}
}
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);
}
}
Loading