У меня есть два квеста для вас. Я добавил свои тестовые методы в строку кода. Какими должны быть значения «ожидаемый» и «фактический» для метода испытаний? И как я могу по-настоящему проверить свое пользовательское исключение в методе test с помощью try-catch или чего-нибудь еще? Не могли бы вы помочь?
I define "customerList" on top
приватный список customerList = new ArrayList <> ();
`````````There is a "getCustomer" method in the "Bank" class`````````
public Customer getCustomer(int ID) throws CustomerNotFoundException {
for (int i = 0; i < customerList.size(); i++) {
if (customerList.get(i).getId() == ID) {
return customerList.get(i);
}
}
throw new CustomerNotFoundException(ID);
}
```````
`````````There is a "addCustomer" method`````````
public void addCustomer(int id, String name){
customerList.add(new Customer(name, id));
}
`````````There is a "getCustomer" test that I ask`````````
/** Test getCustomer()**/
@Test public void tc504_Bank(){
try {
Bank b = new Bank("Test Name", "Test Address");
b.addCustomer(1, "Test Name");
b.getCustomer(1);
Assert.assertEquals("Customer Not Found", b.getCustomerList().get(0), ??? );
}catch (CustomerNotFoundException e){
Assert.assertEquals("PIN not all digits", 0, 1);
}
}
````````
`````````There is a custom expection class````````
public class CustomerNotFoundException extends RuntimeException {
private String name;
private int id;
public CustomerNotFoundException(String name, int id) {
this.name = name;
this.id = id;
}
public CustomerNotFoundException(String name) {
this.name = name;
}
public CustomerNotFoundException(int id) {
this.id = id;
}
@Override
public String toString() {
return "CustomerNotFoundException: id - " + id + " name - " + name;
}
}