refactoring : mutable data - remove setting method
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user