Skip to content

Commit 5d9442d

Browse files
Replace lambda expressions with method references (#304)
* Replace lambda expressions with method references in test files Replaced () -> builder.build() with builder::build in 36 occurrences across 10 test files to improve code readability and align with Java best practices. Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com> * Replace lambda expressions with method references in sample applications Replaced forEach(s -> System.out.println(s)) and forEach(id -> System.out.println(id)) with forEach(System.out::println) in 9 occurrences across 6 sample application files. Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
1 parent d93fa6c commit 5d9442d

16 files changed

Lines changed: 45 additions & 45 deletions

File tree

samples/get-activity-profiles/src/main/java/dev/learning/xapi/samples/getactivityprofiles/GetActivityProfilesApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void run(String... args) throws Exception {
4545
.block();
4646

4747
// Print the each returned activity profile id to the console
48-
response.getBody().stream().forEach(id -> System.out.println(id));
48+
response.getBody().stream().forEach(System.out::println);
4949
}
5050

5151
private void postActivityProfile() {

samples/get-agent-profiles/src/main/java/dev/learning/xapi/samples/getagentprofiles/GetAgentProfilesApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void run(String... args) throws Exception {
4040
.block();
4141

4242
// Print the each returned profile id to the console
43-
response.getBody().stream().forEach(id -> System.out.println(id));
43+
response.getBody().stream().forEach(System.out::println);
4444

4545
}
4646

samples/get-more-statements/src/main/java/dev/learning/xapi/samples/getmorestatements/GetMoreStatementsApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public void run(String... args) throws Exception {
4040
StatementResult result = response.getBody();
4141

4242
// Print the returned statements to the console
43-
Arrays.asList(result.getStatements()).forEach(s -> System.out.println(s));
43+
Arrays.asList(result.getStatements()).forEach(System.out::println);
4444

4545
if (result.hasMore()) {
4646
// Get More Statements
4747
ResponseEntity<StatementResult> more =
4848
client.getMoreStatements(r -> r.more(result.getMore())).block();
4949

5050
// Print the returned statements to the console
51-
Arrays.asList(more.getBody().getStatements()).forEach(s -> System.out.println(s));
51+
Arrays.asList(more.getBody().getStatements()).forEach(System.out::println);
5252
}
5353
}
5454

samples/get-statement-iterator/src/main/java/dev/learning/xapi/samples/getstatements/GetStatementIteratorApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ public void run(String... args) throws Exception {
3737
var statements = client.getStatementIterator().block();
3838

3939
// Print the returned statements to the console
40-
statements.toStream().forEach(s -> System.out.println(s));
40+
statements.toStream().forEach(System.out::println);
4141

4242
// Get Statements with Verb filter as StatementIterator
4343
var filteredStatements =
4444
client.getStatementIterator(r -> r.verb(Verb.ATTEMPTED)).block();
4545

4646
// Print the returned statements to the console
47-
filteredStatements.toStream().forEach(s -> System.out.println(s));
47+
filteredStatements.toStream().forEach(System.out::println);
4848

4949
}
5050

samples/get-statements/src/main/java/dev/learning/xapi/samples/getstatements/GetStatementsApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void run(String... args) throws Exception {
3838
ResponseEntity<StatementResult> response = client.getStatements().block();
3939

4040
// Print the returned statements to the console
41-
response.getBody().getStatements().forEach(s -> System.out.println(s));
41+
response.getBody().getStatements().forEach(System.out::println);
4242

4343

4444

@@ -47,7 +47,7 @@ public void run(String... args) throws Exception {
4747
client.getStatements(r -> r.verb(Verb.ATTEMPTED.getId())).block();
4848

4949
// Print the returned statements to the console
50-
filteredResponse.getBody().getStatements().forEach(s -> System.out.println(s));
50+
filteredResponse.getBody().getStatements().forEach(System.out::println);
5151

5252
}
5353

samples/get-states/src/main/java/dev/learning/xapi/samples/getstates/GetStatesApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void run(String... args) throws Exception {
4949
.block();
5050

5151
// Print the each returned state id to the console
52-
response.getBody().stream().forEach(id -> System.out.println(id));
52+
response.getBody().stream().forEach(System.out::println);
5353

5454
}
5555

xapi-client/src/test/java/dev/learning/xapi/client/DeleteActivityProfileRequestTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void whenBuildingDeleteActivityProfileRequestWithAllParametersThenNoExceptionIsT
3535
.profileId("bookmark");
3636

3737
// Then No Exception Is Thrown
38-
assertDoesNotThrow(() -> builder.build());
38+
assertDoesNotThrow(builder::build);
3939

4040
}
4141

@@ -50,7 +50,7 @@ void whenBuildingDeleteActivityProfileRequestWithoutRegistrationThenNoExceptionI
5050
.profileId("bookmark");
5151

5252
// Then No Exception Is Thrown
53-
assertDoesNotThrow(() -> builder.build());
53+
assertDoesNotThrow(builder::build);
5454

5555
}
5656

@@ -63,7 +63,7 @@ void whenBuildingDeleteActivityProfileRequestWithoutActivityIdThenExceptionIsThr
6363
.profileId("bookmark");
6464

6565
// Then NullPointerException Is Thrown
66-
assertThrows(NullPointerException.class, () -> builder.build());
66+
assertThrows(NullPointerException.class, builder::build);
6767

6868
}
6969

@@ -76,7 +76,7 @@ void whenBuildingDeleteActivityProfileRequestWithoutStateIdThenExceptionIsThrown
7676
.activityId(URI.create("https://example.com/activity/1"));
7777

7878
// Then NullPointerException Is Thrown
79-
assertThrows(NullPointerException.class, () -> builder.build());
79+
assertThrows(NullPointerException.class, builder::build);
8080

8181
}
8282

xapi-client/src/test/java/dev/learning/xapi/client/DeleteStateRequestTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void whenBuildingDeleteStateRequestWithAllParametersThenNoExceptionIsThrown() {
3939
.stateId("bookmark");
4040

4141
// Then No Exception Is Thrown
42-
assertDoesNotThrow(() -> builder.build());
42+
assertDoesNotThrow(builder::build);
4343

4444
}
4545

@@ -56,7 +56,7 @@ void whenBuildingDeleteStateRequestWithoutRegistrationThenNoExceptionIsThrown()
5656
.stateId("bookmark");
5757

5858
// Then No Exception Is Thrown
59-
assertDoesNotThrow(() -> builder.build());
59+
assertDoesNotThrow(builder::build);
6060

6161
}
6262

@@ -73,7 +73,7 @@ void whenBuildingDeleteStateRequestWithoutActivityIdThenExceptionIsThrown() {
7373
.stateId("bookmark");
7474

7575
// Then NullPointerException Is Thrown
76-
assertThrows(NullPointerException.class, () -> builder.build());
76+
assertThrows(NullPointerException.class, builder::build);
7777

7878
}
7979

@@ -90,7 +90,7 @@ void whenBuildingDeleteStateRequestWithoutAgentThenExceptionIsThrown() {
9090
.stateId("bookmark");
9191

9292
// Then NullPointerException Is Thrown
93-
assertThrows(NullPointerException.class, () -> builder.build());
93+
assertThrows(NullPointerException.class, builder::build);
9494

9595
}
9696

@@ -107,7 +107,7 @@ void whenBuildingDeleteStateRequestWithoutStateIdThenExceptionIsThrown() {
107107
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6");
108108

109109
// Then NullPointerException Is Thrown
110-
assertThrows(NullPointerException.class, () -> builder.build());
110+
assertThrows(NullPointerException.class, builder::build);
111111

112112
}
113113

xapi-client/src/test/java/dev/learning/xapi/client/DeleteStatesRequestTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void whenBuildingDeleteStatesRequestWithAllParametersThenNoExceptionIsThrown() {
3838
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6");
3939

4040
// Then No Exception Is Thrown
41-
assertDoesNotThrow(() -> builder.build());
41+
assertDoesNotThrow(builder::build);
4242

4343
}
4444

@@ -55,7 +55,7 @@ void whenBuildingDeleteStatesRequestWithRegistrationAsUUIDTypeThenNoExceptionIsT
5555
.registration(UUID.fromString("67828e3a-d116-4e18-8af3-2d2c59e27be6"));
5656

5757
// Then No Exception Is Thrown
58-
assertDoesNotThrow(() -> builder.build());
58+
assertDoesNotThrow(builder::build);
5959

6060
}
6161

@@ -72,7 +72,7 @@ void whenBuildingDeleteStatesRequestWithActivityIdAsURITypeThenNoExceptionIsThro
7272
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6");
7373

7474
// Then No Exception Is Thrown
75-
assertDoesNotThrow(() -> builder.build());
75+
assertDoesNotThrow(builder::build);
7676

7777
}
7878

@@ -87,7 +87,7 @@ void whenBuildingDeleteStatesRequestWithoutRegistrationThenNoExceptionIsThrown()
8787
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"));
8888

8989
// Then No Exception Is Thrown
90-
assertDoesNotThrow(() -> builder.build());
90+
assertDoesNotThrow(builder::build);
9191

9292
}
9393

@@ -102,7 +102,7 @@ void whenBuildingDeleteStatesRequestWithoutActivityIdThenExceptionIsThrown() {
102102
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6");
103103

104104
// Then NullPointerException Is Thrown
105-
assertThrows(NullPointerException.class, () -> builder.build());
105+
assertThrows(NullPointerException.class, builder::build);
106106

107107
}
108108

@@ -117,7 +117,7 @@ void whenBuildingDeleteStatesRequestWithoutAgentThenExceptionIsThrown() {
117117
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6");
118118

119119
// Then NullPointerException Is Thrown
120-
assertThrows(NullPointerException.class, () -> builder.build());
120+
assertThrows(NullPointerException.class, builder::build);
121121

122122
}
123123

xapi-client/src/test/java/dev/learning/xapi/client/GetActivityProfilesRequestTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void whenBuildingGetActivityProfilesRequestWithAllParametersThenNoExceptionIsThr
3636
.since(Instant.parse("2016-01-01T00:00:00Z"));
3737

3838
// Then No Exception Is Thrown
39-
assertDoesNotThrow(() -> builder.build());
39+
assertDoesNotThrow(builder::build);
4040

4141
}
4242

@@ -49,7 +49,7 @@ void whenBuildingGetActivityProfilesRequestWithActivityIdAsURITypeThenNoExceptio
4949
.activityId(URI.create("https://example.com/activity/1"));
5050

5151
// Then No Exception Is Thrown
52-
assertDoesNotThrow(() -> builder.build());
52+
assertDoesNotThrow(builder::build);
5353

5454
}
5555

@@ -62,7 +62,7 @@ void whenBuildingGetActivityProfilesRequestWithoutRegistrationThenNoExceptionIsT
6262
.activityId("https://example.com/activity/1");
6363

6464
// Then No Exception Is Thrown
65-
assertDoesNotThrow(() -> builder.build());
65+
assertDoesNotThrow(builder::build);
6666

6767
}
6868

@@ -73,7 +73,7 @@ void whenBuildingGetActivityProfilesRequestWithoutActivityIdThenExceptionIsThrow
7373
Builder builder = GetActivityProfilesRequest.builder();
7474

7575
// Then NullPointerException Is Thrown
76-
assertThrows(NullPointerException.class, () -> builder.build());
76+
assertThrows(NullPointerException.class, builder::build);
7777

7878
}
7979

0 commit comments

Comments
 (0)