File tree Expand file tree Collapse file tree 5 files changed +122
-0
lines changed
java/test/com/craftcoder/java8/defaultmethod
test/java/com/craftcoder/java8/suppliers Expand file tree Collapse file tree 5 files changed +122
-0
lines changed Original file line number Diff line number Diff line change 1+ /target /
2+ build /
3+ .classpath
4+ .project
5+ .settings
Original file line number Diff line number Diff line change 1+ # java8-guides-tutorials
2+ Java 8 - Guides and Tutorias
Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
3+ <modelVersion >4.0.0</modelVersion >
4+
5+ <groupId >com.craftcoder.java8</groupId >
6+ <artifactId >java8-suppliers</artifactId >
7+ <version >0.0.1-SNAPSHOT</version >
8+ <packaging >jar</packaging >
9+
10+ <name >java8-suppliers</name >
11+ <url >http://maven.apache.org</url >
12+
13+ <properties >
14+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
15+ </properties >
16+
17+ <dependencies >
18+ <!-- TESTING DEPENDENCIES -->
19+ <dependency >
20+ <groupId >org.hamcrest</groupId >
21+ <artifactId >hamcrest-all</artifactId >
22+ <version >1.3</version >
23+ </dependency >
24+
25+ <dependency >
26+ <groupId >junit</groupId >
27+ <artifactId >junit</artifactId >
28+ <version >4.12</version >
29+ <scope >test</scope >
30+ </dependency >
31+ <!-- TESTING DEPENDENCIES -->
32+
33+ </dependencies >
34+
35+ <build >
36+ <plugins >
37+ <plugin >
38+ <groupId >org.apache.maven.plugins</groupId >
39+ <artifactId >maven-eclipse-plugin</artifactId >
40+ <configuration >
41+ <downloadSources >true</downloadSources >
42+ <downloadJavadocs >true</downloadJavadocs >
43+ </configuration >
44+ </plugin >
45+ </plugins >
46+ </build >
47+
48+ </project >
Original file line number Diff line number Diff line change 1+ package com .craftcoder .java8 .defaultmethod ;
2+
3+ import static org .hamcrest .MatcherAssert .assertThat ;
4+ import static org .hamcrest .Matchers .equalTo ;
5+
6+ import org .junit .Ignore ;
7+ import org .junit .Test ;
8+
9+ public class DefaultMethodTest {
10+
11+ /**
12+ * In this example, we don't need to use the default method send() from PaymentService interface
13+ */
14+ @ Ignore
15+ @ Test
16+ public void shouldRetrieveTheDefaultFees () throws Exception {
17+ PaymentService service = new PayPalPaymentService ();
18+
19+ double fees = service .retrieveDefaultFees ();
20+
21+ assertThat (fees , equalTo (10.9 ));
22+ }
23+
24+ @ Test
25+ public void shouldInvokeTheDefaultMethodFromPaymentService () throws Exception {
26+ PaymentService paymentService = new PayPalPaymentService ();
27+
28+ double valueSent = paymentService .send (20 );
29+
30+ assertThat (valueSent , equalTo (20.0 ));
31+ }
32+
33+ }
34+
35+
36+ interface PaymentService {
37+
38+ double retrieveDefaultFees ();
39+
40+ default double send (double value ) {
41+ System .out .println ("Sending the value: " + value );
42+
43+ return value ;
44+ }
45+
46+ }
47+
48+ class PayPalPaymentService implements PaymentService {
49+
50+ @ Override
51+ public double retrieveDefaultFees () {
52+ return 10.9 ;
53+ }
54+
55+ }
Original file line number Diff line number Diff line change 1+ package com .craftcoder .java8 .suppliers ;
2+
3+ import static org .hamcrest .MatcherAssert .assertThat ;
4+ import static org .hamcrest .Matchers .equalTo ;
5+
6+ import java .util .function .Function ;
7+
8+ import org .junit .Test ;
9+
10+ public class SupplierFunctionalInterfaceTest {
11+
12+ }
You can’t perform that action at this time.
0 commit comments