Skip to content

Commit 0e41602

Browse files
authored
Merge branch 'master' into feat/2.0.0/failable-dynamic-defaults
2 parents a28c743 + 3d937b3 commit 0e41602

3 files changed

Lines changed: 76 additions & 2 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ jobs:
1313
runs-on: "ubuntu-latest"
1414
steps:
1515
- uses: actions/checkout@v4
16-
- uses: gradle/wrapper-validation-action@v1
16+
- uses: gradle/wrapper-validation-action@v2
1717
- name: Set up JDK
1818
uses: actions/setup-java@v4
1919
with:
2020
distribution: 'temurin'
2121
java-version: 17
22-
- uses: gradle/gradle-build-action@v2
22+
- uses: gradle/actions/setup-gradle@v3
2323
with:
2424
# allow master and *-dev branches to write caches (default is only master/main)
2525
cache-read-only: ${{ github.ref != 'refs/heads/master' && !(endsWith(github.ref, '-dev') && startsWith(github.ref, 'refs/heads/')) }}

cloud-core/src/main/java/org/incendo/cloud/Command.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,18 @@ private Builder(
20242024
);
20252025
}
20262026

2027+
/**
2028+
* Specifies the command execution handler.
2029+
*
2030+
* @param commandExecutionHandler New execution handler
2031+
* @return new builder instance using the command execution handler
2032+
*/
2033+
public @NonNull Builder<C> futureHandler(
2034+
final CommandExecutionHandler.@NonNull FutureCommandExecutionHandler<C> commandExecutionHandler
2035+
) {
2036+
return this.handler(commandExecutionHandler);
2037+
}
2038+
20272039
/**
20282040
* Returns the current command execution handler.
20292041
*
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// MIT License
3+
//
4+
// Copyright (c) 2024 Incendo
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
//
24+
package org.incendo.cloud.execution;
25+
26+
import java.util.concurrent.CompletableFuture;
27+
import org.checkerframework.checker.nullness.qual.NonNull;
28+
import org.incendo.cloud.CommandManager;
29+
import org.incendo.cloud.TestCommandSender;
30+
import org.incendo.cloud.context.CommandContext;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
33+
34+
import static com.google.common.truth.Truth.assertThat;
35+
import static org.incendo.cloud.util.TestUtils.createManager;
36+
37+
class FutureCommandExecutionCoordinatorTest {
38+
39+
private CommandManager<TestCommandSender> commandManager;
40+
41+
@BeforeEach
42+
void setup() {
43+
this.commandManager = createManager();
44+
}
45+
46+
@Test
47+
void testExecution() {
48+
// Arrange
49+
this.commandManager.command(this.commandManager.commandBuilder("command").futureHandler(this::handler));
50+
51+
// Act
52+
final CommandResult<TestCommandSender> result =
53+
this.commandManager.commandExecutor().executeCommand(new TestCommandSender(), "command").join();
54+
55+
// Assert
56+
assertThat(result.commandContext().<String>get("string")).isEqualTo("hello");
57+
}
58+
59+
private @NonNull CompletableFuture<Void> handler(final @NonNull CommandContext<TestCommandSender> context) {
60+
return CompletableFuture.supplyAsync(() -> "hello").thenAccept(string -> context.store("string", string));
61+
}
62+
}

0 commit comments

Comments
 (0)