Skip to content

Instantly share code, notes, and snippets.

View httpmurilo's full-sized avatar
💭
I may be slow to respond.

Murilo Eduardo httpmurilo

💭
I may be slow to respond.
View GitHub Profile
package com.escola.modelo;
public class Aluno {
public Aluno(String nome, Integer idade, String cidade) {
this.nome = nome;
this.idade = idade;
this.cidade = cidade;
}
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;
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
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
@httpmurilo
httpmurilo / UserDTO.java
Created February 9, 2022 23:49
Default Dto
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());
@httpmurilo
httpmurilo / UserDTO.java
Created February 9, 2022 23:40
Default DTO
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());
@httpmurilo
httpmurilo / User.java
Created February 9, 2022 23:34
Default user
package io.httpmurilo.sales.entity;
public class User {
private Integer id;
private String name;
private Integer age;
private String email;
private boolean active;
@httpmurilo
httpmurilo / Student.java
Created January 23, 2022 21:40
Singleton static factory
package io.murilo.school.model;
public class Student {
private static final Student INSTANCE = new Student();
private Student() {
...
public static Student getInstance();
}
@httpmurilo
httpmurilo / Student.java
Created January 23, 2022 21:11
Singleton final
package io.murilo.school.model;
public class Student {
public static final Student INSTANCE = new Student();
private Integer id;
private String name;
private Integer age;
}
@httpmurilo
httpmurilo / ControllerCustomerTests.java
Created January 22, 2022 20:25
ControllerCustomerTests
@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());
}