mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-18 00:23:32 +00:00
* Issue #2377: The repository code has been refactored to use the record class * Issue #2377: Refactored according to the rules defined for the repo code * Issue #2377: Refactored according to the rules defined for the repo code * Issue #2377: Refactored according to the rules defined for the repo code
This commit is contained in:
@@ -27,23 +27,7 @@ package com.iluwatar.registry;
|
||||
/**
|
||||
* Customer entity used in registry pattern example.
|
||||
*/
|
||||
public class Customer {
|
||||
|
||||
private final String id;
|
||||
private final String name;
|
||||
|
||||
public Customer(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public record Customer(String id, String name) {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -45,7 +45,7 @@ public final class CustomerRegistry {
|
||||
}
|
||||
|
||||
public Customer addCustomer(Customer customer) {
|
||||
return customerMap.put(customer.getId(), customer);
|
||||
return customerMap.put(customer.id(), customer);
|
||||
}
|
||||
|
||||
public Customer getCustomer(String id) {
|
||||
|
||||
@@ -50,13 +50,13 @@ class CustomerRegistryTest {
|
||||
|
||||
Customer customerWithId1 = customerRegistry.getCustomer("1");
|
||||
assertNotNull(customerWithId1);
|
||||
assertEquals("1", customerWithId1.getId());
|
||||
assertEquals("john", customerWithId1.getName());
|
||||
assertEquals("1", customerWithId1.id());
|
||||
assertEquals("john", customerWithId1.name());
|
||||
|
||||
Customer customerWithId2 = customerRegistry.getCustomer("2");
|
||||
assertNotNull(customerWithId2);
|
||||
assertEquals("2", customerWithId2.getId());
|
||||
assertEquals("julia", customerWithId2.getName());
|
||||
assertEquals("2", customerWithId2.id());
|
||||
assertEquals("julia", customerWithId2.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user