This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.escola.modelo; | |
public class Aluno { | |
public Aluno(String nome, Integer idade, String cidade) { | |
this.nome = nome; | |
this.idade = idade; | |
this.cidade = cidade; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.escola.modelo; | |
public class Aluno { | |
public Aluno(String nome, Integer idade, String cidade, double notaDeCorte, Integer dividirPor) { | |
this.nome = nome; | |
this.idade = idade; | |
this.cidade = cidade; | |
this.notaDeCorte = notaDeCorte; | |
this.dividirPor = dividirPor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.httpmurilo.sales.mock; | |
import io.httpmurilo.sales.dto.UserDTO; | |
import io.httpmurilo.sales.entity.User; | |
import io.httpmurilo.sales.mapper.UserMapper; | |
import org.springframework.beans.factory.annotation.Autowired; | |
public class FakeService { | |
@Autowired |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.httpmurilo.sales.mapper; | |
import io.httpmurilo.sales.dto.UserDTO; | |
import io.httpmurilo.sales.entity.User; | |
import org.mapstruct.Mapper; | |
import org.mapstruct.factory.Mappers; | |
@Mapper(componentModel = "spring") //define que é um Spring bean e pode ser injetado via @Autowired | |
public abstract class UserMapper { //impedimos de instanciar diretamente | |
public static final UserMapper INSTANCE = Mappers.getMapper(UserMapper.class); //singleton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.httpmurilo.sales.dto; | |
import io.httpmurilo.sales.entity.User; | |
public class UserDTO { | |
//Esse construtor nunca irá parar de crescer X_X | |
public UserDTO convertToUser(User user) { | |
UserDTO dto = new UserDTO(); | |
dto.setName(user.getName()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.httpmurilo.sales.dto; | |
import io.httpmurilo.sales.entity.User; | |
public class UserDTO { | |
public UserDTO convertToUser(User user) { | |
UserDTO dto = new UserDTO(); | |
dto.setName(user.getName()); | |
dto.setAge(user.getAge()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.httpmurilo.sales.entity; | |
public class User { | |
private Integer id; | |
private String name; | |
private Integer age; | |
private String email; | |
private boolean active; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.murilo.school.model; | |
public class Student { | |
private static final Student INSTANCE = new Student(); | |
private Student() { | |
... | |
public static Student getInstance(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.murilo.school.model; | |
public class Student { | |
public static final Student INSTANCE = new Student(); | |
private Integer id; | |
private String name; | |
private Integer age; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Order(1) | |
@Test | |
void testPostAction() throws Exception { | |
mvc.perform(MockMvcRequestBuilders | |
.post("/customer") | |
.content(jsonString(new Customer("Antony", 12, true))) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().isCreated()); | |
} |