More Related Content Similar to No Hate on Java 8, But 9–14 Reign Supreme (20) More from VMware Tanzu (20) No Hate on Java 8, But 9–14 Reign Supreme1. Beyond Java 8
Angie Jones
https://angiejones.tech
https://TestAutomationU.com
@techgirl1908
Principal Developer Advocate
Director, Test Automation University
Applitools, San Francisco, CA, USA
6. @Test
public void accountsListed() {
AccountsOverviewPage accountsOverviewPage =
page.login(username, password);
List<String> actualAccounts =
accountsOverviewPage.getAccounts();
List<Account> accounts = APIUtil.getAccounts(
Customers.getCustomerId(username));
List<String> expectedAccounts = new ArrayList();
for(Account account : accounts){
expectedAccounts
.add(String.valueOf(account.id()));
}
assertEquals(expectedAccounts, actualAccounts);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
AccountsOverviewPage accountsOverviewPage =
page.login(username, password);
@Test1
public void accountsListed() {2
3
4
5
6
List<String> actualAccounts =7
accountsOverviewPage.getAccounts();8
9
List<Account> accounts = APIUtil.getAccounts(10
Customers.getCustomerId(username));11
12
List<String> expectedAccounts = new ArrayList();13
for(Account account : accounts){14
expectedAccounts15
.add(String.valueOf(account.id()));16
}17
18
assertEquals(expectedAccounts, actualAccounts);19
}20
List<String> actualAccounts =
accountsOverviewPage.getAccounts();
@Test1
public void accountsListed() {2
3
AccountsOverviewPage accountsOverviewPage =4
page.login(username, password);5
6
7
8
9
List<Account> accounts = APIUtil.getAccounts(10
Customers.getCustomerId(username));11
12
List<String> expectedAccounts = new ArrayList();13
for(Account account : accounts){14
expectedAccounts15
.add(String.valueOf(account.id()));16
}17
18
assertEquals(expectedAccounts, actualAccounts);19
}20
List<Account> accounts = APIUtil.getAccounts(
Customers.getCustomerId(username));
@Test1
public void accountsListed() {2
3
AccountsOverviewPage accountsOverviewPage =4
page.login(username, password);5
6
List<String> actualAccounts =7
accountsOverviewPage.getAccounts();8
9
10
11
12
List<String> expectedAccounts = new ArrayList();13
for(Account account : accounts){14
expectedAccounts15
.add(String.valueOf(account.id()));16
}17
18
assertEquals(expectedAccounts, actualAccounts);19
}20
List<String> expectedAccounts = new ArrayList();
@Test1
public void accountsListed() {2
3
AccountsOverviewPage accountsOverviewPage =4
page.login(username, password);5
6
List<String> actualAccounts =7
accountsOverviewPage.getAccounts();8
9
List<Account> accounts = APIUtil.getAccounts(10
Customers.getCustomerId(username));11
12
13
for(Account account : accounts){14
expectedAccounts15
.add(String.valueOf(account.id()));16
}17
18
assertEquals(expectedAccounts, actualAccounts);19
}20
for(Account account : accounts){
@Test1
public void accountsListed() {2
3
AccountsOverviewPage accountsOverviewPage =4
page.login(username, password);5
6
List<String> actualAccounts =7
accountsOverviewPage.getAccounts();8
9
List<Account> accounts = APIUtil.getAccounts(10
Customers.getCustomerId(username));11
12
List<String> expectedAccounts = new ArrayList();13
14
expectedAccounts15
.add(String.valueOf(account.id()));16
}17
18
assertEquals(expectedAccounts, actualAccounts);19
}20
expectedAccounts
.add(String.valueOf(account.id()));
@Test1
public void accountsListed() {2
3
AccountsOverviewPage accountsOverviewPage =4
page.login(username, password);5
6
List<String> actualAccounts =7
accountsOverviewPage.getAccounts();8
9
List<Account> accounts = APIUtil.getAccounts(10
Customers.getCustomerId(username));11
12
List<String> expectedAccounts = new ArrayList();13
for(Account account : accounts){14
15
16
}17
18
assertEquals(expectedAccounts, actualAccounts);19
}20
assertEquals(expectedAccounts, actualAccounts);
@Test1
public void accountsListed() {2
3
AccountsOverviewPage accountsOverviewPage =4
page.login(username, password);5
6
List<String> actualAccounts =7
accountsOverviewPage.getAccounts();8
9
List<Account> accounts = APIUtil.getAccounts(10
Customers.getCustomerId(username));11
12
List<String> expectedAccounts = new ArrayList();13
for(Account account : accounts){14
expectedAccounts15
.add(String.valueOf(account.id()));16
}17
18
19
}20
@Test
public void accountsListed() {
AccountsOverviewPage accountsOverviewPage =
page.login(username, password);
List<String> actualAccounts =
accountsOverviewPage.getAccounts();
List<Account> accounts = APIUtil.getAccounts(
Customers.getCustomerId(username));
List<String> expectedAccounts = new ArrayList();
for(Account account : accounts){
expectedAccounts
.add(String.valueOf(account.id()));
}
assertEquals(expectedAccounts, actualAccounts);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@techgirl1908
7. AccountsOverviewPage accountsOverviewPage =
page.login(username, password);
@Test1
public void accountsListed() {2
3
4
5
6
List<String> actualAccounts =7
accountsOverviewPage.getAccounts();8
9
List<Account> accounts = APIUtil.getAccounts(10
Customers.getCustomerId(username));11
12
List<String> expectedAccounts = new ArrayList();13
for(Account account : accounts){14
expectedAccounts15
.add(String.valueOf(account.id()));16
}17
18
assertEquals(expectedAccounts, actualAccounts);19
}20
@techgirl1908
8. var accountsOverviewPage =
page.login(username, password);
@Test1
public void accountsListed() {2
3
4
5
6
List<String> actualAccounts =7
accountsOverviewPage.getAccounts();8
9
List<Account> accounts = APIUtil.getAccounts(10
Customers.getCustomerId(username));11
12
List<String> expectedAccounts = new ArrayList();13
for(Account account : accounts){14
expectedAccounts15
.add(String.valueOf(account.id()));16
}17
18
assertEquals(expectedAccounts, actualAccounts);19
}20
TYPE INFERENCE FOR LOCAL VARIABLES
@techgirl1908
11. Only works for
local variables
public class MyTests {
var accountsOverviewPage =
page. login(username, password);
@Test
public void accountsListed() {}
} @techgirl1908
15. var accountsOverviewPage =
page.login(username, password);
@Test1
public void accountsListed() {2
3
4
5
6
var actualAccountIdsList =7
accountsOverviewPage.getAccounts();8
9
var accountsList =10
APIUtil.getAccounts(11
Customers.getCustomerId(username));12
13
var expectedAccountIdsList = new ArrayList<String>();14
for(var account : accountsList){15
expectedAccountIdsList16
.add(String.valueOf(account.id()));17
}18
19
assertEquals(expectedAccountIdsList, actualAccountIdsList20
}21
var actualAccountIdsList =
accountsOverviewPage.getAccounts();
@Test1
public void accountsListed() {2
3
var accountsOverviewPage =4
page.login(username, password);5
6
7
8
9
var accountsList =10
APIUtil.getAccounts(11
Customers.getCustomerId(username));12
13
var expectedAccountIdsList = new ArrayList<String>();14
for(var account : accountsList){15
expectedAccountIdsList16
.add(String.valueOf(account.id()));17
}18
19
assertEquals(expectedAccountIdsList, actualAccountIdsList20
}21
var accountsList =
APIUtil.getAccounts(
Customers.getCustomerId(username));
@Test1
public void accountsListed() {2
3
var accountsOverviewPage =4
page.login(username, password);5
6
var actualAccountIdsList =7
accountsOverviewPage.getAccounts();8
9
10
11
12
13
var expectedAccountIdsList = new ArrayList<String>();14
for(var account : accountsList){15
expectedAccountIdsList16
.add(String.valueOf(account.id()));17
}18
19
assertEquals(expectedAccountIdsList, actualAccountIdsList20
}21
var expectedAccountIdsList = new ArrayList<String>();
@Test1
public void accountsListed() {2
3
var accountsOverviewPage =4
page.login(username, password);5
6
var actualAccountIdsList =7
accountsOverviewPage.getAccounts();8
9
var accountsList =10
APIUtil.getAccounts(11
Customers.getCustomerId(username));12
13
14
for(var account : accountsList){15
expectedAccountIdsList16
.add(String.valueOf(account.id()));17
}18
19
assertEquals(expectedAccountIdsList, actualAccountIdsList20
}21
for(var account : accountsList){
@Test1
public void accountsListed() {2
3
var accountsOverviewPage =4
page.login(username, password);5
6
var actualAccountIdsList =7
accountsOverviewPage.getAccounts();8
9
var accountsList =10
APIUtil.getAccounts(11
Customers.getCustomerId(username));12
13
var expectedAccountIdsList = new ArrayList<String>();14
15
expectedAccountIdsList16
.add(String.valueOf(account.id()));17
}18
19
assertEquals(expectedAccountIdsList, actualAccountIdsList20
}21
TYPE INFERENCE FOR LOCAL VARIABLES
16. @Test
public void accountsListed() {
var accountsOverviewPage =
page.login(username, password);
var actualAccountIdsList =
accountsOverviewPage.getAccounts();
var accountsList =
APIUtil.getAccounts(
Customers.getCustomerId(username));
var expectedAccountIdsList = new ArrayList<String>();
for(var account : accountsList){
expectedAccountIdsList
.add(String.valueOf(account.id()));
}
assertEquals(expectedAccountIdsList, actualAccountIdsList
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
accountsOverviewPage.getAccounts();
@Test1
public void accountsListed() {2
3
var accountsOverviewPage =4
page.login(username, password);5
6
var actualAccountIdsList =7
8
9
var accountsList =10
APIUtil.getAccounts(11
Customers.getCustomerId(username));12
13
var expectedAccountIdsList = new ArrayList<String>();14
for(var account : accountsList){15
expectedAccountIdsList16
.add(String.valueOf(account.id()));17
}18
19
assertEquals(expectedAccountIdsList, actualAccountIdsList20
}21
@techgirl1908
18. public List<String> getAccounts(){
List<WebElement> accountCells =
driver.findElements(accountColumn);
List<String> accounts = new ArrayList();
for(WebElement element : accountCells){
accounts.add(element.getText());
}
return accounts;
}
1
2
3
4
5
6
7
8
9
10
11
List<WebElement> accountCells =
driver.findElements(accountColumn);
public List<String> getAccounts(){1
2
3
4
5
List<String> accounts = new ArrayList();6
for(WebElement element : accountCells){7
accounts.add(element.getText());8
}9
return accounts;10
}11
List<String> accounts = new ArrayList();
public List<String> getAccounts(){1
2
List<WebElement> accountCells =3
driver.findElements(accountColumn);4
5
6
for(WebElement element : accountCells){7
accounts.add(element.getText());8
}9
return accounts;10
}11
for(WebElement element : accountCells){
accounts.add(element.getText());
}
public List<String> getAccounts(){1
2
List<WebElement> accountCells =3
driver.findElements(accountColumn);4
5
List<String> accounts = new ArrayList();6
7
8
9
return accounts;10
}11
public List<String> getAccounts(){
List<WebElement> accountCells =
driver.findElements(accountColumn);
List<String> accounts = new ArrayList();
for(WebElement element : accountCells){
accounts.add(element.getText());
}
return accounts;
}
1
2
3
4
5
6
7
8
9
10
11
@techgirl1908
19. public List<String> getAccounts(){
return driver.findElements(accountColumn)
.stream()
.map(WebElement::getText)
.collect(Collectors.toList());
}
1
2
3
4
5
6
7
return driver.findElements(accountColumn)
public List<String> getAccounts(){1
2
3
.stream()4
.map(WebElement::getText)5
.collect(Collectors.toList());6
}7
.stream()
public List<String> getAccounts(){1
2
return driver.findElements(accountColumn)3
4
.map(WebElement::getText)5
.collect(Collectors.toList());6
}7
.map(WebElement::getText)
public List<String> getAccounts(){1
2
return driver.findElements(accountColumn)3
.stream()4
5
.collect(Collectors.toList());6
}7
.collect(Collectors.toList());
public List<String> getAccounts(){1
2
return driver.findElements(accountColumn)3
.stream()4
.map(WebElement::getText)5
6
}7
@techgirl1908
22. New line for
each method call
driver.findElements(accountColumn).stream().map(WebElement::getText).collect(Collectors.toList());
driver.findElements(accountColumn)
.stream()
.map(WebElement::getText)
.collect(Collectors.toList());
@techgirl1908
23. var accountsList = APIUtil.getAccounts(customerId);
var checkingAccountsList = accountsList
.stream()
.takeWhile(account -> account.type().equals("CHECKING"))
.collect(Collectors.toList());
1
2
3
4
5
.takeWhile(account -> account.type().equals("CHECKING"))
var accountsList = APIUtil.getAccounts(customerId);1
var checkingAccountsList = accountsList2
.stream()3
4
.collect(Collectors.toList());5
takeWhile()
24. var accountsList = APIUtil.getAccounts(customerId);
var checkingAccountsList = accountsList
.stream()
.takeWhile(account -> account.type().equals("CHECKING"))
.collect(Collectors.toList());
1
2
3
4
5
takeWhile()
25. var accountsList = APIUtil.getAccounts(customerId);
var checkingAccountsList = accountsList
.stream()
.dropWhile(account -> account.type().equals("CHECKING"))
.collect(Collectors.toList());
1
2
3
4
5
.dropWhile(account -> account.type().equals("CHECKING"))
var accountsList = APIUtil.getAccounts(customerId);1
var checkingAccountsList = accountsList2
.stream()3
4
.collect(Collectors.toList());5
dropWhile()
26. var accountsList = APIUtil.getAccounts(customerId);
var checkingAccountsList = accountsList
.stream()
.dropWhile(account -> account.type().equals("CHECKING"))
.collect(Collectors.toList());
1
2
3
4
5
.dropWhile(account -> account.type().equals("CHECKING"))
var accountsList = APIUtil.getAccounts(customerId);1
var checkingAccountsList = accountsList2
.stream()3
4
.collect(Collectors.toList());5
dropWhile()
28. Sort for
deterministic results
var accountsList = APIUtil.getAccounts(customerId);
var checkingAccountsList = accountsList
.stream()
.sorted(Comparator.comparing(Account::type))
.takeWhile(account -> account.type().equals("CHECKING"))
.collect(Collectors.toList());
1
2
3
4
5
6
7
.sorted(Comparator.comparing(Account::type))
var accountsList = APIUtil.getAccounts(customerId);1
2
var checkingAccountsList = accountsList3
.stream()4
5
.takeWhile(account -> account.type().equals("CHECKING"))6
.collect(Collectors.toList());7
@techgirl1908
31. @Test
public void accountsListed() {
var accountsOverviewPage =
page.login(username, password);
var actualAccountIdsList =
accountsOverviewPage.getAccounts();
String customerId = Customers.getCustomerId(username);
var expectedAccountIdsList =
APIUtil.getAccounts(customerId)
.stream()
.map(Account::getId)
.map(String::valueOf)
.collect(Collectors.toList());
assertEquals(expectedAccountIdsList, actualAccountIdsList
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
String customerId = Customers.getCustomerId(username);
@Test1
public void accountsListed() {2
3
var accountsOverviewPage =4
page.login(username, password);5
6
var actualAccountIdsList =7
accountsOverviewPage.getAccounts();8
9
10
11
var expectedAccountIdsList =12
APIUtil.getAccounts(customerId)13
.stream()14
.map(Account::getId)15
.map(String::valueOf)16
.collect(Collectors.toList());17
18
assertEquals(expectedAccountIdsList, actualAccountIdsList19
}20
@techgirl1908
32. public static String getCustomerId(String name){
String id;
switch(name){
case "john":
id = "12212";
break;
case "mary":
id = "4847474";
break;
case "tom":
id = "293743";
break;
default:
id = "";
break;
}
return id;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
String id;
public static String getCustomerId(String name){1
2
3
4
switch(name){5
case "john":6
id = "12212";7
break;8
case "mary":9
id = "4847474";10
break;11
case "tom":12
id = "293743";13
break;14
default:15
id = "";16
break;17
}18
19
return id;20
}21
case "john":
id = "12212";
break;
public static String getCustomerId(String name){1
2
String id;3
4
switch(name){5
6
7
8
case "mary":9
id = "4847474";10
break;11
case "tom":12
id = "293743";13
break;14
default:15
id = "";16
break;17
}18
19
return id;20
}21
public static String getCustomerId(String name){
String id;
switch(name){
case "john":
id = "12212";
break;
case "mary":
id = "4847474";
break;
case "tom":
id = "293743";
break;
default:
id = "";
break;
}
return id;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 @techgirl1908
33. public static String getCustomerId(String name){
String id = switch(name){
case "john" -> "12212";
case "mary" -> "4847474";
case "tom" -> "293743";
default -> "";
};
return id;
}
1
2
3
4
5
6
7
8
9
10
11
String id = switch(name){
public static String getCustomerId(String name){1
2
3
case "john" -> "12212";4
case "mary" -> "4847474";5
case "tom" -> "293743";6
default -> "";7
};8
9
return id;10
}11
case "john" -> "12212";
public static String getCustomerId(String name){1
2
String id = switch(name){3
4
case "mary" -> "4847474";5
case "tom" -> "293743";6
default -> "";7
};8
9
return id;10
}11
String id = switch(name){
return id;
public static String getCustomerId(String name){1
2
3
case "john" -> "12212";4
case "mary" -> "4847474";5
case "tom" -> "293743";6
default -> "";7
};8
9
10
}11
SWITCH EXPRESSIONS
@techgirl1908
34. return switch(name){
public static String getCustomerId(String name){1
2
3
case "john" -> "12212";4
case "mary" -> "4847474";5
case "tom" -> "293743";6
default -> "";7
};8
}9
case "john" -> "12212";
case "mary" -> "4847474";
case "tom" -> "293743";
default -> "";
public static String getCustomerId(String name){1
2
return switch(name){3
4
5
6
7
};8
}9
SWITCH EXPRESSIONS
@techgirl1908
35. case "john": yield "12212";
case "mary": yield "4847474";
case "tom" : yield "293743";
default : yield "";
public static String getCustomerId(String name) {1
return switch (name) {2
3
4
5
6
};7
}8
public static String getCustomerId(String name) {
return switch (name) {
case "john": yield "12212";
case "mary": yield "4847474";
case "tom" : yield "293743";
default : yield "";
};
}
1
2
3
4
5
6
7
8
SWITCH EXPRESSIONS
@techgirl1908
36. public static String getCustomerId(String name){
return switch(name){
case "john", "demo" -> "12212";
case "mary" -> "4847474";
case "tom" -> "293743";
default -> "";
};
}
1
2
3
4
5
6
7
8
9
case "john", "demo" -> "12212";
public static String getCustomerId(String name){1
2
return switch(name){3
4
case "mary" -> "4847474";5
case "tom" -> "293743";6
default -> "";7
};8
}9
SWITCH EXPRESSIONS
@techgirl1908
37. public static String getCustomerId(String name){
return switch(name){
case "john" -> {
System.out.println("Hi John");
yield "12212";
}
case "mary" -> "4847474";
case "tom" -> "293743";
default -> "";
};
}
1
2
3
4
5
6
7
8
9
10
11
12
case "john" -> {
System.out.println("Hi John");
yield "12212";
}
public static String getCustomerId(String name){1
2
return switch(name){3
4
5
6
7
case "mary" -> "4847474";8
case "tom" -> "293743";9
default -> "";10
};11
}12
System.out.println("Hi John");
public static String getCustomerId(String name){1
2
return switch(name){3
case "john" -> {4
5
yield "12212";6
}7
case "mary" -> "4847474";8
case "tom" -> "293743";9
default -> "";10
};11
}12
yield "12212";
public static String getCustomerId(String name){1
2
return switch(name){3
case "john" -> {4
System.out.println("Hi John");5
6
}7
case "mary" -> "4847474";8
case "tom" -> "293743";9
default -> "";10
};11
}12
SWITCH EXPRESSIONS
@techgirl1908
38. Cannot mix and
match -> and :yield
return switch(name){
case "john" -> "12212";
case "mary": yield "4847474";
case "tom" -> "293743";
default -> "";
};
1
2
3
4
5
6
@techgirl1908
41. @Test
public void accountsListed() {
var accountsOverviewPage =
page.login(username, password);
var actualAccountIdsList =
accountsOverviewPage.getAccounts();
String customerId = Customers.getCustomerId(username);
var expectedAccountIdsList =
APIUtil.getAccounts(customerId)
.stream()
.map(Account::getId)
.map(String::valueOf)
.collect(Collectors.toList());
assertEquals(expectedAccountIdsList, actualAccountIdsList
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
APIUtil.getAccounts(customerId)
@Test1
public void accountsListed() {2
3
var accountsOverviewPage =4
page.login(username, password);5
6
var actualAccountIdsList =7
accountsOverviewPage.getAccounts();8
9
String customerId = Customers.getCustomerId(username);10
11
var expectedAccountIdsList =12
13
.stream()14
.map(Account::getId)15
.map(String::valueOf)16
.collect(Collectors.toList());17
18
assertEquals(expectedAccountIdsList, actualAccountIdsList19
}20
@techgirl1908
42. public class APIUtil {
public static List<Account> getAccounts(String customerId){
return Arrays.asList(given()
.header(new Header("Accept", "application/json"))
.get(format(GET_ACCOUNTS, customerId))
.as(Account[].class));
}
}
1
2
3
4
5
6
7
8
9
.as(Account[].class));
public class APIUtil {1
2
public static List<Account> getAccounts(String customerId){3
return Arrays.asList(given()4
.header(new Header("Accept", "application/json"))5
.get(format(GET_ACCOUNTS, customerId))6
7
}8
}9
@techgirl1908
44. public class Account {
private int id;
private int customerId;
private String type;
private double balance;
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public int getCustomerId() { return customerId; }
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public double getBalance() { return balance; }
public void setBalance(double balance) {
this.balance = balance;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@techgirl1908
45. public record Account(
int id,
int customerId,
String type,
double balance){}
1
2
3
4
5
public record Account(1
int id,2
int customerId,3
String type,4
double balance){}5
int id,
int customerId,
String type,
double balance){}
public record Account(1
2
3
4
5
RECORDS
@techgirl1908
46. public record Account(
int id,
int customerId,
String type,
double balance
){
@Override
public String toString(){
return "I've overriden this!";
}
}
1
2
3
4
5
6
7
8
9
10
11
){
@Override
public String toString(){
return "I've overriden this!";
}
}
public record Account(1
int id,2
int customerId,3
String type,4
double balance5
6
7
8
9
10
11
RECORDS
@techgirl1908
49. Accessors don't start
with get
Account account = new Account(
13344, 12212, "CHECKING", 4033.93);
double balance = account.balance();
1
2
3
4 double balance = account.balance();
Account account = new Account(1
13344, 12212, "CHECKING", 4033.93);2
3
4
@techgirl1908
50. Still in preview
public record Account(
int id,
int customerId,
String type,
double balance){}
1
2
3
4
5
@techgirl1908
51. Still in preview
public record Account(
@JsonProperty("id") int id,
@JsonProperty("customerId") int customerId,
@JsonProperty("type") String type,
@JsonProperty("balance") double balance){}
1
2
3
4
5
@techgirl1908
52. @Test
public void accountsListed() {
var accountsOverviewPage =
page.login(username, password);
var actualAccountIdsList =
accountsOverviewPage.getAccounts();
String customerId = Customers.getCustomerId(username);
var expectedAccountIdsList =
APIUtil.getAccounts(customerId)
.stream()
.map(Account::getId)
.map(String::valueOf)
.collect(Collectors.toList());
assertEquals(expectedAccountIdsList, actualAccountIdsList
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
APIUtil.getAccounts(customerId)
@Test1
public void accountsListed() {2
3
var accountsOverviewPage =4
page.login(username, password);5
6
var actualAccountIdsList =7
accountsOverviewPage.getAccounts();8
9
String customerId = Customers.getCustomerId(username);10
11
var expectedAccountIdsList =12
13
.stream()14
.map(Account::getId)15
.map(String::valueOf)16
.collect(Collectors.toList());17
18
assertEquals(expectedAccountIdsList, actualAccountIdsList19
}20
@techgirl1908
54. String response =
"[n" +
" {n" +
" "id": 13344,n" +
" "customerId": 12212,n" +
" "type": "CHECKING",n" +
" "balance": 4022.93n" +
" },n" +
" {n" +
" "id": 13455,n" +
" "customerId": 12212,n" +
" "type": "CHECKING",n" +
" "balance": 1000n" +
" }n" +
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@techgirl1908
55. public String getAccounts_mocked(){
return """
[
{
"id": 13344,
"customerId": 12212,
"type": "CHECKING",
"balance": 3821.93
},
{
"id": 13455,
"customerId": 12212,
"type": "LOAN",
"balance": 989
}
]
""";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"id": 13344,
"customerId": 12212,
"type": "CHECKING",
"balance": 3821.93
public String getAccounts_mocked(){1
return """2
[3
{4
5
6
7
8
},9
{10
"id": 13455,11
"customerId": 12212,12
"type": "LOAN",13
"balance": 98914
}15
]16
""";17
TEXT BLOCKS
@techgirl1908
56. Text cannot begin on
same line as """
System.out.println(""" Hey y'all! """);
1
2
3
4
5
System.out.println("""6
Hey y'all!""");7
8
9
System.out.println("""10
Hey y'all!11
""");12
System.out.println("""
Hey y'all!""");
1
2
System.out.println(""" Hey y'all! """);3
4
5
6
7
8
9
System.out.println("""10
Hey y'all!11
""");12
System.out.println("""
Hey y'all!
""");
1
2
System.out.println(""" Hey y'all! """);3
4
5
System.out.println("""6
Hey y'all!""");7
8
9
10
11
12
57. APIUtil.getAccounts(customerId)
@Test1
public void accountsListed() {2
3
var accountsOverviewPage =4
page.login(username, password);5
6
var actualAccountIdsList =7
accountsOverviewPage.getAccounts();8
9
String customerId = Customers.getCustomerId(username);10
11
var expectedAccountIdsList =12
13
.stream()14
.map(Account::getId)15
.map(String::valueOf)16
.collect(Collectors.toList());17
18
assertEquals(expectedAccountIdsList, actualAccountIdsList19
}20
@techgirl1908
58. public static List<String> getAccountIds_mocked(){
return Arrays.asList("13344", "13455", "13566", "14010");
}
1
2
3
return Arrays.asList("13344", "13455", "13566", "14010");
public static List<String> getAccountIds_mocked(){1
2
}3
public static List<String> getAccountIds_mocked(){
return List.of("13344", "13455", "13566", "14010");
}
COLLECTION CONVENIENCE METHOD
@techgirl1908
59. Map users = new HashMap();
users.put("john", 123);
users.put("alice", 456);
users.put("sue", 789);
1
2
3
4
Map users = Map.of("john", 123, "alice", 456, "sue", 789);1
COLLECTION CONVENIENCE METHOD
@techgirl1908
61. Map users = Map.of(
"john", 123,
"alice", 456,
"sue", 789);
1
2
3
4
users.put("bob", 000);
users.remove("alice");
COLLECTION CONVENIENCE METHOD
@techgirl1908
63. Beyond Java 8
Angie Jones
https://angiejones.tech
https://TestAutomationU.com
@techgirl1908
Principal Developer Advocate
Director, Test Automation University
Applitools, San Francisco, CA, USA