Skip to content

Commit

Permalink
[skip ci] code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sergi-Jr committed Aug 16, 2024
1 parent 0071f8a commit 713e403
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions src/test/java/sergi/example/api/UserControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package sergi.example.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import net.datafaker.Faker;
import org.instancio.Instancio;
import org.instancio.Select;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.openapitools.jackson.nullable.JsonNullable;
Expand All @@ -16,6 +12,7 @@
import sergi.example.user.User;
import sergi.example.user.dal.UserRepository;
import sergi.example.user.dto.UserCreateDTO;
import utils.InitData;

import java.util.Map;
import java.util.Optional;
Expand All @@ -33,29 +30,18 @@ class UserControllerTest {
private MockMvc mockMvc;

@Autowired
private Faker faker;
private InitData init;

@Autowired
private UserRepository userRepository;

@Autowired
private ObjectMapper mapper;

private User generateUser() {
return Instancio.of(User.class)
.ignore(Select.field(User::getId))
.ignore(Select.field(User::getCreatedAt))
.ignore(Select.field(User::getUpdatedAt))
.ignore(Select.field(User::getTasks))
.supply(Select.field(User::getName), () -> faker.name().name())
.supply(Select.field(User::getEmail), () -> faker.internet().emailAddress())
.create();
}

@Test
@Order(1)
void testCreate() throws Exception {
User user = generateUser();
User user = init.user();
UserCreateDTO dto = new UserCreateDTO();
dto.setEmail(user.getEmail());
dto.setName(JsonNullable.of(user.getName()));
Expand All @@ -77,7 +63,7 @@ void testCreate() throws Exception {
@Test
@Order(2)
void testUpdate() throws Exception {
User user = generateUser();
User user = init.user();
userRepository.save(user);

Map<String, String> data = Map.of("email", "[email protected]", "name", "John Doe");
Expand Down

0 comments on commit 713e403

Please sign in to comment.