-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathDefaultMethodTest.java
55 lines (36 loc) · 1.07 KB
/
DefaultMethodTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package defaultmethod;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.*;
import org.junit.Ignore;
import org.junit.Test;
public class DefaultMethodTest {
/**
* In this example, we don't need to use the default method send() from PaymentService interface
*/
@Ignore
@Test
public void shouldRetrieveTheDefaultFees() throws Exception {
PaymentService service = new PayPalPaymentService();
double fees = service.retrieveDefaultFees();
assertThat(fees, equalTo(10.9));
}
@Test
public void shouldInvokeTheDefaultMethodFromPaymentService() throws Exception {
PaymentService paymentService = new PayPalPaymentService();
double valueSent = paymentService.send(20);
assertThat(valueSent, equalTo(20.0));
}
}
interface PaymentService {
double retrieveDefaultFees();
default double send(double value) {
System.out.println("Sending the value: " + value);
return value;
}
}
class PayPalPaymentService implements PaymentService {
@Override
public double retrieveDefaultFees() {
return 10.9;
}
}