forked from michaelangelo2288/Functional-Interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupplierTest.java
More file actions
39 lines (34 loc) · 1.25 KB
/
Copy pathSupplierTest.java
File metadata and controls
39 lines (34 loc) · 1.25 KB
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
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
public class SupplierTest {
// Pass Supplier function interface as an argument to printAccess(Supplier<Boolean> supplier) method
@Test
public void supplierTest1() {
String password = "valid";
printAccess(() -> { // anonymous interface implementation. not an anonymous function
if (password.equals("valid"))
return true;
else
return false;
});
}
private void printAccess(Supplier<Boolean> supplier) {
if(supplier.get() == true) // get just executes the body of anonymous interface implementation defined (if-else statement) above? YES
System.out.println("Correct password - unlocked");
else
System.out.println("Incorrect password - locked");
}
// Override Supplier get() method
@Test
public void supplierOverrideTest2() {
Supplier<String> supplier = new Supplier() {
@Override
public String get() {
return "supplier get() override";
}
};
System.out.println(supplier.get());
}
}