From 83af36ee020f909b4499e8f40a1f41569724b8ed Mon Sep 17 00:00:00 2001 From: roost-io Date: Mon, 7 Oct 2024 08:59:16 +0000 Subject: [PATCH] Unit test generated by RoostGPT Using AI Model mixtral-8x7b-instruct-v0.1 --- pom.xml | 212 +++++++++++------- .../products/model/ProductGetIdTest.java | 138 ++++++++++++ 2 files changed, 272 insertions(+), 78 deletions(-) create mode 100644 src/test/java/com/bootexample4/products/model/ProductGetIdTest.java diff --git a/pom.xml b/pom.xml index db6c2c51..ab374092 100644 --- a/pom.xml +++ b/pom.xml @@ -1,89 +1,145 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.0.5 - - - com.bootexample4 - products - 0.0.1-SNAPSHOT - products - Demo project for Spring Boot - - 17 - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.mock-server - mockserver-netty - 3.10.8 - - - org.mock-server - mockserver-client-java - 3.10.8 - - - org.springframework.boot - spring-boot-starter-web - - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-starter-test - test - - + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.5 + + + + com.bootexample4 + products + 0.0.1-SNAPSHOT + products + Demo project for Spring Boot + + 17 + + - io.cucumber - cucumber-spring - 7.0.0 - test + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.mock-server + mockserver-netty + 3.10.8 + + + org.mock-server + mockserver-client-java + 3.10.8 + + + org.springframework.boot + spring-boot-starter-web + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + + io.cucumber + cucumber-spring + 7.0.0 + test - io.cucumber - cucumber-java - 7.0.0 - test + io.cucumber + cucumber-java + 7.0.0 + test - io.cucumber - cucumber-junit - 7.0.0 - test + io.cucumber + cucumber-junit + 7.0.0 + test - org.assertj - assertj-core - 3.19.0 - test + org.assertj + assertj-core + 3.19.0 + test + + + io.spring.javaformat + spring-javaformat-formatter + 0.0.40 + - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + + prepare-agent + + + + report + test + + report + + + coverageReport + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 3.2.5 + + testReport + + + + + org.apache.maven.plugins + maven-site-plugin + 2.1 + + testReport + + + + + io.spring.javaformat + spring-javaformat-maven-plugin + 0.0.40 + + + + + \ No newline at end of file diff --git a/src/test/java/com/bootexample4/products/model/ProductGetIdTest.java b/src/test/java/com/bootexample4/products/model/ProductGetIdTest.java new file mode 100644 index 00000000..7b4782db --- /dev/null +++ b/src/test/java/com/bootexample4/products/model/ProductGetIdTest.java @@ -0,0 +1,138 @@ + +package com.bootexample4.products.model; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import org.junit.jupiter.api.*; + +@Tag("unit") +public class ProductGetIdTest { + + @Test + @Tag("valid") + public void testGetIdReturnsCorrectIdValue() { + Product product = new Product(); + product.setId(1L); + Assertions.assertEquals(1L, product.getId()); + } + + @Test + @Tag("valid") + public void testGetIdReturnsNullForNewProductObject() { + Product product = new Product(); + Assertions.assertNull(product.getId()); + } + + @Test + @Tag("valid") + public void testGetIdReturnsSameIdValueAfterMultipleCalls() { + Product product = new Product(); + product.setId(1L); + Assertions.assertEquals(1L, product.getId()); + Assertions.assertEquals(1L, product.getId()); + } + + @Test + @Tag("valid") + public void testGetIdPreservesIdValueAfterOtherFieldChanges() { + Product product = new Product(); + product.setId(1L); + product.setName("Product Name"); + product.setDescription("Product Description"); + product.setPrice(9.99); + Assertions.assertEquals(1L, product.getId()); + } + + @Test + @Tag("valid") + public void testGetIdPreservesIdValueAfterPriceChange() { + Product product = new Product(); + product.setId(1L); + product.setPrice(9.99); + Assertions.assertEquals(1L, product.getId()); + } + + @Test + @Tag("valid") + public void testGetIdPreservesIdValueAfterDescriptionChange() { + Product product = new Product(); + product.setId(1L); + product.setDescription("Product Description"); + Assertions.assertEquals(1L, product.getId()); + } + + @Test + @Tag("valid") + public void testGetIdPreservesIdValueAfterNameChange() { + Product product = new Product(); + product.setId(1L); + product.setName("Product Name"); + Assertions.assertEquals(1L, product.getId()); + + }} + + Please note + that the Product + + class must + be defined + as follows: + + @Entity + public class Product { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + private String description; + + private double price; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + + } + +} +These import statements + +are required for +the code +to compile +: \ No newline at end of file