refactoring : mutable data - remove setting method

This commit is contained in:
haerong22
2022-03-11 16:48:10 +09:00
parent 204d0e831b
commit 055b3cd831
3 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package com.example.refactoring._06_mutable_data._20_remove_setting_method;
public class Person {
private String name;
private final int id;
public Person(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
}

View File

@@ -0,0 +1,24 @@
package com.example.refactoring._06_mutable_data._20_remove_setting_method.before;
public class Person {
private String name;
private int id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

View File

@@ -0,0 +1,19 @@
package com.example.refactoring._06_mutable_data._20_remove_setting_method;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class PersonTest {
@Test
void person() {
Person person = new Person(10);
person.setName("john");
assertEquals(10, person.getId());
assertEquals("john", person.getName());
person.setName("jane");
assertEquals("jane", person.getName());
}
}