Skip to content

Commit 61592f2

Browse files
Copilotcommjoen
andcommitted
Revert Java 17 compatibility fixes - restore Java 21+ List methods for Java 23
Co-authored-by: commjoen <[email protected]>
1 parent d76c744 commit 61592f2

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

src/main/java/org/owasp/wrongsecrets/Challenges.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ public boolean isFirstChallenge(ChallengeDefinition challengeDefinition) {
100100
}
101101

102102
public boolean isLastChallenge(ChallengeDefinition challengeDefinition) {
103-
var challenges = definitions.challenges();
104-
return challengeDefinition.equals(challenges.get(challenges.size() - 1));
103+
return challengeDefinition.equals(definitions.challenges().getLast());
105104
}
106105

107106
public List<ChallengeDefinition> getChallengeDefinitions() {

src/main/java/org/owasp/wrongsecrets/challenges/ChallengeUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private String documentation(Function<ChallengeSource, String> extractor) {
109109
return challengeDefinition.source(runtimeEnvironment).map(extractor).orElse("");
110110
} else {
111111
// We cannot run the challenge but showing documentation should still be possible
112-
return extractor.apply(challengeDefinition.sources().get(0));
112+
return extractor.apply(challengeDefinition.sources().getFirst());
113113
}
114114
}
115115

src/main/java/org/owasp/wrongsecrets/challenges/ChallengesController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ public String spoiler(@PathVariable("short-name") String shortName, Model model)
9797
Supplier<Spoiler> spoilerFromRandomChallenge =
9898
() -> {
9999
var challengeDefinition = findByShortName(shortName);
100-
var challengeList = challenges.getChallenge(challengeDefinition);
101-
return challengeList.get(0).spoiler();
100+
return challenges.getChallenge(challengeDefinition).getFirst().spoiler();
102101
};
103102

104103
// We always want to show the spoiler even if we run in a non-supported environment

src/test/java/org/owasp/wrongsecrets/ctftests/ChallengesControllerCTFClientModeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ class ChallengesControllerCTFClientModeTest {
3636

3737
@Test
3838
void shouldNotSpoilWhenInCTFMode() throws Exception {
39-
var randomChallenge = challenges.getChallengeDefinitions().get(0);
39+
var randomChallenge = challenges.getChallengeDefinitions().getFirst();
4040
mvc.perform(get("/spoil/%s".formatted(randomChallenge.name().shortName())))
4141
.andExpect(status().isOk())
4242
.andExpect(content().string(containsString("Spoils are disabled in CTF mode")));
4343
}
4444

4545
@Test
4646
void shouldNotSpoilWhenInCTFModeEvenWhenChallengeUnsupported() throws Exception {
47-
var firstChallenge = challenges.getChallengeDefinitions().get(0);
47+
var firstChallenge = challenges.getChallengeDefinitions().getFirst();
4848
mvc.perform(get("/spoil/%s".formatted(firstChallenge.name().shortName())))
4949
.andExpect(status().isOk())
5050
.andExpect(content().string(containsString("Spoils are disabled in CTF mode")));
5151
}
5252

5353
@Test
5454
void challenge0SshouldSShowTheAddressRightAnswersNeedToBeSubmittedTo() throws Exception {
55-
var firstChallenge = challenges.getChallengeDefinitions().get(0);
55+
var firstChallenge = challenges.getChallengeDefinitions().getFirst();
5656
mvc.perform(get("/challenge/%s".formatted(firstChallenge.name().shortName())))
5757
.andExpect(status().isOk())
5858
.andExpect(content().string(containsString("https://www.google.nl")));

src/test/java/org/owasp/wrongsecrets/ctftests/ChallengesControllerCTFModeWithPresetCloudValuesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ChallengesControllerCTFModeWithPresetCloudValuesTest {
4242

4343
@Test
4444
void shouldNotSpoilWhenInCTFMode() throws Exception {
45-
var firstChallenge = challenges.getChallengeDefinitions().get(0);
45+
var firstChallenge = challenges.getChallengeDefinitions().getFirst();
4646
mvc.perform(get("/spoil/%s".formatted(firstChallenge.name().shortName())))
4747
.andExpect(status().isOk())
4848
.andExpect(content().string(containsString("Spoils are disabled in CTF mode")));
@@ -51,7 +51,7 @@ void shouldNotSpoilWhenInCTFMode() throws Exception {
5151
@Test
5252
void shouldShowFlagWhenRespondingWithSuccessInCTFModeChallenge9() throws Exception {
5353
var challenge9Definition = challenges.findByShortName("challenge-9").orElseThrow();
54-
var challenge9 = challenges.getChallenge(challenge9Definition).get(0);
54+
var challenge9 = challenges.getChallenge(challenge9Definition).getFirst();
5555
var spoil = challenge9.spoiler().solution();
5656
mvc.perform(
5757
post("/challenge/%s".formatted(challenge9Definition.name().shortName()))

src/test/java/org/owasp/wrongsecrets/definitions/NavigationTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,24 @@ void navigatePreviousWhenOnFirstChallenge() {
1616
var navigation =
1717
new Navigator(
1818
challengeDefinitionsConfiguration.challenges(),
19-
challengeDefinitionsConfiguration.challenges().get(0));
19+
challengeDefinitionsConfiguration.challenges().getFirst());
2020

2121
assertThat(navigation.previous()).isEmpty();
2222
}
2323

2424
@Test
2525
void navigateNextWhenOnLastChallenge() {
26-
var challenges = challengeDefinitionsConfiguration.challenges();
2726
var navigation =
2827
new Navigator(
29-
challenges,
30-
challenges.get(challenges.size() - 1));
28+
challengeDefinitionsConfiguration.challenges(),
29+
challengeDefinitionsConfiguration.challenges().getLast());
3130

3231
assertThat(navigation.next()).isEmpty();
3332
}
3433

3534
@Test
3635
void navigatePreviousAndNextOnSecondChallenge() {
37-
var first = challengeDefinitionsConfiguration.challenges().get(0);
36+
var first = challengeDefinitionsConfiguration.challenges().getFirst();
3837
var second = challengeDefinitionsConfiguration.challenges().get(1);
3938
var third = challengeDefinitionsConfiguration.challenges().get(2);
4039

0 commit comments

Comments
 (0)