refactoring: Issue #2377: The repository code has been refactored to use the recor… (#2505)

* 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:
Mughees Qasim
2023-05-06 12:08:12 +03:00
committed by GitHub
parent c0e1603f90
commit 3ae6b07590
26 changed files with 244 additions and 293 deletions
@@ -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