Skip to content

Commit

Permalink
Diffblue Cover created unit tests for module spring-petclinic
Browse files Browse the repository at this point in the history
  • Loading branch information
db-ci-pipeline committed Feb 13, 2024
1 parent 21bdf53 commit 1189aa7
Show file tree
Hide file tree
Showing 21 changed files with 2,602 additions and 0 deletions.
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

0 comments on commit 1189aa7

Please sign in to comment.