From 48753b45b2f775463234c1c5cd32bec6ef759eb7 Mon Sep 17 00:00:00 2001 From: rivo Date: Sun, 1 Dec 2024 11:57:15 +0800 Subject: [PATCH] FEAT:add unit test --- .../app/repository/ClientRepositoryTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/java/com/pos/app/repository/ClientRepositoryTest.java diff --git a/src/test/java/com/pos/app/repository/ClientRepositoryTest.java b/src/test/java/com/pos/app/repository/ClientRepositoryTest.java new file mode 100644 index 0000000..e57a5ac --- /dev/null +++ b/src/test/java/com/pos/app/repository/ClientRepositoryTest.java @@ -0,0 +1,49 @@ +package com.pos.app.repository; + + +import com.github.javafaker.Faker; +import com.pos.app.entities.Client; +import com.pos.app.repositories.ClientRepository; +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.runner.RunWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@DataJpaTest +@ExtendWith(MockitoExtension.class) +public class ClientRepositoryTest { + Faker faker = new Faker(); + String name = faker.name().fullName(); + + @Autowired + private ClientRepository clientRepository; + + @Test + public void contextLoads() { + Assertions.assertThat(clientRepository).isNotNull(); + } + + @Test + public void testSave() { + Client client = saveClient(); + Assertions.assertThat(client).isNotNull(); + Assertions.assertThat(client.getId()).isNotNull(); + Assertions.assertThat(client.getName()).isEqualTo(name); + } + + + + private Client saveClient() { + Client client = Client.builder() + .name(name) + .createdBy(name) + .build(); + return clientRepository.save(client); + } + +}