Skip to content
Open
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
227 changes: 149 additions & 78 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,89 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.bootexample4</groupId>
<artifactId>products</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>products</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- mockserver -->
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<version>3.10.8</version>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>3.10.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Cucumber Spring Boot Starter -->
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.bootexample4</groupId>
<artifactId>products</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>products</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>7.0.0</version>
<scope>test</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- mockserver -->
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<version>3.10.8</version>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>3.10.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Cucumber Spring Boot Starter -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!-- Cucumber Java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.0.0</version>
<scope>test</scope>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!-- Cucumber JUnit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.0.0</version>
<scope>test</scope>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<!-- AssertJ -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.19.0</version>
<scope>test</scope>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-formatter</artifactId>
<version>0.0.40</version>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.6.1</version>
<scope>compile</scope>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.6.1</version>
<scope>compile</scope>
<!--Dependency added by RoostGPT-->
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
<scope>compile</scope>
<!--Dependency added by RoostGPT-->
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<outputDirectory>coverageReport</outputDirectory>
</configuration>
</execution>
</executions>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<outputDirectory>testReport</outputDirectory>
</configuration>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.1</version>
<configuration>
<outputDirectory>testReport</outputDirectory>
</configuration>
<!--Plugin added by RoostGPT-->
</plugin>
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.40</version>
<!--Plugin added by RoostGPT-->
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

// ********RoostGPT********
/*
Test generated by RoostGPT for test dbrx-java using AI Type DBRX and AI Model meta-llama-3-70b-instruct-041824

ROOST_METHOD_HASH=createProduct_60409495d0
ROOST_METHOD_SIG_HASH=createProduct_5b0158b3eb

Here are the test scenarios for the `createProduct` method:

**Scenario 1: Successful Product Creation**

Details:
TestName: successfulProductCreation
Description: Verifies that a product is successfully created and saved to the database.

Execution:
Arrange: Create a valid `Product` object with required fields.
Act: Invoke the `createProduct` method with the prepared `Product` object.
Assert: Verify that the returned `Product` object is not null and its ID is not null.

Validation:
This test ensures that the `createProduct` method correctly saves a product to the database. A valid `ProductRepository is set up a mock of `ProductRepository` to return a saved `Product` object.

**Scenario 2: Null Product Object**

Details:
TestName: nullProductObject
Description: Checks that the method throws an exception when a null `Product` object is passed.

Execution:
Arrange: Pass a null `Product` object to the `createProduct` method.
Act: Invoke the `createProduct` method with the null `Product` object.
Assert: Verify that a `NullPointerException` is thrown.

Validation:
This test ensures that the `createProduct` method handles null input correctly and throws an exception to prevent unexpected behavior.

**Scenario 3: Invalid Product Object**

Details:
TestName: invalidProductObject
Description: Verifies that the method throws an exception when an invalid `Product` object is passed.

Execution:
Arrange: Create an invalid `Product` object (e.g., with empty or null fields).
Act: Invoke the `createProduct` method with the invalid `Product` object.
Assert: Verify that a `ConstraintViolationException` is thrown.

Validation:
This test ensures that the `createProduct` method correctly handles invalid input and throws an exception to prevent data inconsistencies.

**Scenario 4: ProductRepository Save Failure**

Details:
TestName: productRepositorySaveFailure
Description: Checks that the method throws an exception when the `ProductRepository` save operation fails.

Execution:
Arrange: Set up a mock `ProductRepository` to throw a `RuntimeException` when `save` is called.
Act: Invoke the `createProduct` method with a valid `Product` object.
Assert: Verify that a `RuntimeException` is thrown.

Validation:
This test ensures that the `createProduct` method correctly propagates exceptions from the `ProductRepository` and handles unexpected errors.

**Scenario 5: Product Already Exists**

Details:
TestName: productAlreadyExists
Description: Verifies that the method returns the existing product when a product with the same identifier already exists.

Execution:
Arrange: Create a `Product` object with an existing identifier and set up the `ProductRepository` to return an existing product.
Act: Invoke the `createProduct` method with the prepared `Product` object.
Assert: Verify that the returned `Product` object is the existing one.

Validation:
This test ensures that the `createProduct` method correctly handles cases where a product already exists and returns the existing product instead of creating a new one.

These test scenarios cover various cases, including successful product creation, invalid input, and error handling.

roost_feedback [5/22/2024, 9:06:26 AM]:the Product class only has a default constructor and so does not accept arguments.
Use setter methods like setId(Long Id) and setName(String name) and setDescription(String description) and setPrice(double price) to initialise the product member attributes instead

roost_feedback [5/22/2024, 9:31:01 AM]:remove the definition of public class Product {}
*/

// ********RoostGPT********


package com.bootexample4.products.model;

public class ProductTest {

@Test
public void successfulProductCreation() {
// Arrange
Product product = new Product();
product.setId(1L);
product.setName("Test Product");
product.setDescription("Test Description");
product.setPrice(10.99);
// Act
// Assert
assertNotNull(product);
assertNotNull(product.getId());
assertEquals("Test Product", product.getName());
assertEquals("Test Description", product.getDescription());
assertEquals(10.99, product.getPrice(), 0.01);
}

@Test
public void nullProductObject() {
// Act and Assert
Product product = null;
assertThrows(NullPointerException.class, () -> product.setId(1L));
}

@Test
public void invalidProductObject() {
// Arrange
Product product = new Product();
product.setName(null);
product.setDescription(null);
product.setPrice(0.0);
// Act and Assert
assertThrows(NullPointerException.class, () -> product.getName());
assertThrows(NullPointerException.class, () -> product.getDescription());
assertEquals(0.0, product.getPrice(), 0.01);
}
}
Loading