Skip to content

Commit

Permalink
FEAT:add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rivopelu committed Dec 1, 2024
1 parent 9ec1bd0 commit 48753b4
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/test/java/com/pos/app/repository/ClientRepositoryTest.java
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 48753b4

Please sign in to comment.