SlideShare a Scribd company logo
1 of 63
Download to read offline
Beyond Java 8
Angie Jones
https://angiejones.tech
https://TestAutomationU.com
@techgirl1908
Principal Developer Advocate
Director, Test Automation University
Applitools, San Francisco, CA, USA
@techgirl1908
@techgirl1908
@techgirl1908
@techgirl1908
@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
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
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
Java is still a
statically typed
language
@techgirl1908
Initialization is
required
var accountsOverviewPage;
@techgirl1908
Only works for
local variables
public class MyTests {
var accountsOverviewPage =
page. login(username, password);
@Test
public void accountsListed() {}
} @techgirl1908
Not allowed in
headers
public class MyTests {
public MyTests(var data){}
}
@techgirl1908
Naming is even
more important
now
var x = getX();
@techgirl1908
Everything doesn't
need to be a var!
var numberOfAccounts = 5;
@techgirl1908
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
@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
@techgirl1908
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
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
.map(WebElement::getText)
public List<String> getAccounts(){1
2
return driver.findElements(accountColumn)3
.stream()4
5
.collect(Collectors.toList());6
}7
.map(e -> e.getText())
return driver.findElements(accountColumn)1
.stream()2
3
.collect(Collectors.toList());4
@techgirl1908
var expectedAccountIdsList =
APIUtil.getAccounts(customerId)
.stream()
.map(Account::getId)
.map(String::valueOf)
.collect(Collectors.toList());
@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
12
13
14
15
16
17
18
assertEquals(expectedAccountIdsList, actualAccountIdsList19
}20
@techgirl1908
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
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()
var accountsList = APIUtil.getAccounts(customerId);
var checkingAccountsList = accountsList
.stream()
.takeWhile(account -> account.type().equals("CHECKING"))
.collect(Collectors.toList());
1
2
3
4
5
takeWhile()
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()
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()
dropWhile()
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
takeWhile() on sorted collection
dropWhile() on sorted collection
@techgirl1908
@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
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
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
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
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
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
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
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
Can throw
Exceptions
return switch(name){
case "john" -> "12212";
case "mary" -> "4847474";
case "tom" -> "293743";
default -> throw new InvalidNameException();
};
1
2
3
4
5
6
@techgirl1908
When to use
expressions vs
statements?
@techgirl1908
@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
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
[
{
"id": 13344,
"customerId": 12212,
"type": "CHECKING",
"balance": 4022.93
},
{
"id": 13455,
"customerId": 12212,
"type": "CHECKING",
"balance": 1000
}
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@techgirl1908
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
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
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
Records can be
instantiated
Account account = new Account(
13344, 12212, "CHECKING", 4033.93);
@techgirl1908
Records are
immutable
Account account = new Account(
13344, 12212, "CHECKING", 4033.93);
account.setType("SAVINGS");
1
2
3
4
@techgirl1908
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
Still in preview
public record Account(
int id,
int customerId,
String type,
double balance){}
1
2
3
4
5
@techgirl1908
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
@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
[
{
"id": 13344,
"customerId": 12212,
"type": "CHECKING",
"balance": 4022.93
},
{
"id": 13455,
"customerId": 12212,
"type": "CHECKING",
"balance": 1000
}
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@techgirl1908
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
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
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
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
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
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
The of() method
creates immutable
collections
@techgirl1908
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
Questions?
@techgirl1908
Beyond Java 8
Angie Jones
https://angiejones.tech
https://TestAutomationU.com
@techgirl1908
Principal Developer Advocate
Director, Test Automation University
Applitools, San Francisco, CA, USA

More Related Content

Similar to No Hate on Java 8, But 9–14 Reign Supreme

SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
ARORACOCKERY2111
 
Java programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdfJava programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdf
fathimafancy
 
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdfBank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
izabellejaeden956
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
Rajeev Sharan
 
I need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdfI need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdf
rajeshjangid1865
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Roel Hartman
 
The java class Account that simultes the Account class.pdf
   The java class Account that simultes  the Account class.pdf   The java class Account that simultes  the Account class.pdf
The java class Account that simultes the Account class.pdf
akshay1213
 
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterWho Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniter
ciconf
 

Similar to No Hate on Java 8, But 9–14 Reign Supreme (20)

Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developers
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
 
How to write clean tests
How to write clean testsHow to write clean tests
How to write clean tests
 
A Mock to far - GeeCon
A Mock to far -  GeeConA Mock to far -  GeeCon
A Mock to far - GeeCon
 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java script
 
Java programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdfJava programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdf
 
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdfBank Program in JavaBelow is my code(havent finished, but it be .pdf
Bank Program in JavaBelow is my code(havent finished, but it be .pdf
 
Mock geecon2
Mock geecon2Mock geecon2
Mock geecon2
 
Ecom lec4 fall16_jpa
Ecom lec4 fall16_jpaEcom lec4 fall16_jpa
Ecom lec4 fall16_jpa
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
Ditching JQuery
Ditching JQueryDitching JQuery
Ditching JQuery
 
I need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdfI need help creating a basic and simple Java program. Here is the ex.pdf
I need help creating a basic and simple Java program. Here is the ex.pdf
 
Slawomir Kluz - ScalaTest from QA perspective (Quality Questions Conference)
Slawomir Kluz - ScalaTest from QA perspective (Quality Questions Conference)Slawomir Kluz - ScalaTest from QA perspective (Quality Questions Conference)
Slawomir Kluz - ScalaTest from QA perspective (Quality Questions Conference)
 
Detroit ELEVATE Track 2
Detroit ELEVATE Track 2Detroit ELEVATE Track 2
Detroit ELEVATE Track 2
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
 
Sql Injection Myths and Fallacies
Sql Injection Myths and FallaciesSql Injection Myths and Fallacies
Sql Injection Myths and Fallacies
 
The java class Account that simultes the Account class.pdf
   The java class Account that simultes  the Account class.pdf   The java class Account that simultes  the Account class.pdf
The java class Account that simultes the Account class.pdf
 
Data-Driven Unit Testing for Java
Data-Driven Unit Testing for JavaData-Driven Unit Testing for Java
Data-Driven Unit Testing for Java
 
Avoiding to Reinvent the flat tire
Avoiding to Reinvent the flat tireAvoiding to Reinvent the flat tire
Avoiding to Reinvent the flat tire
 
Who Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniterWho Needs Ruby When You've Got CodeIgniter
Who Needs Ruby When You've Got CodeIgniter
 

More from VMware Tanzu

More from VMware Tanzu (20)

What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About It
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at Scale
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a Product
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - French
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - English
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software Engineer
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs Practice
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

No Hate on Java 8, But 9–14 Reign Supreme

  • 1. 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
  • 9. Java is still a statically typed language @techgirl1908
  • 11. Only works for local variables public class MyTests { var accountsOverviewPage = page. login(username, password); @Test public void accountsListed() {} } @techgirl1908
  • 12. Not allowed in headers public class MyTests { public MyTests(var data){} } @techgirl1908
  • 13. Naming is even more important now var x = getX(); @techgirl1908
  • 14. Everything doesn't need to be a var! var numberOfAccounts = 5; @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
  • 20. .map(WebElement::getText) public List<String> getAccounts(){1 2 return driver.findElements(accountColumn)3 .stream()4 5 .collect(Collectors.toList());6 }7 .map(e -> e.getText()) return driver.findElements(accountColumn)1 .stream()2 3 .collect(Collectors.toList());4 @techgirl1908
  • 21. var expectedAccountIdsList = APIUtil.getAccounts(customerId) .stream() .map(Account::getId) .map(String::valueOf) .collect(Collectors.toList()); @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 12 13 14 15 16 17 18 assertEquals(expectedAccountIdsList, actualAccountIdsList19 }20 @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
  • 29. takeWhile() on sorted collection
  • 30. dropWhile() on sorted collection @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
  • 39. Can throw Exceptions return switch(name){ case "john" -> "12212"; case "mary" -> "4847474"; case "tom" -> "293743"; default -> throw new InvalidNameException(); }; 1 2 3 4 5 6 @techgirl1908
  • 40. When to use expressions vs statements? @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
  • 43. [ { "id": 13344, "customerId": 12212, "type": "CHECKING", "balance": 4022.93 }, { "id": 13455, "customerId": 12212, "type": "CHECKING", "balance": 1000 } ] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 @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
  • 47. Records can be instantiated Account account = new Account( 13344, 12212, "CHECKING", 4033.93); @techgirl1908
  • 48. Records are immutable Account account = new Account( 13344, 12212, "CHECKING", 4033.93); account.setType("SAVINGS"); 1 2 3 4 @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
  • 53. [ { "id": 13344, "customerId": 12212, "type": "CHECKING", "balance": 4022.93 }, { "id": 13455, "customerId": 12212, "type": "CHECKING", "balance": 1000 } ] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 @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
  • 60. The of() method creates immutable collections @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