-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBuildTaskAssert.java
More file actions
66 lines (60 loc) · 2.24 KB
/
BuildTaskAssert.java
File metadata and controls
66 lines (60 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package nebula.test.dsl;
import org.assertj.core.api.AbstractAssert;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.TaskOutcome;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Assertions for individual tasks
*/
@NullMarked
public class BuildTaskAssert extends AbstractAssert<BuildTaskAssert, @Nullable BuildTask> {
BuildTaskAssert(@Nullable BuildTask buildTask) {
super(buildTask, BuildTaskAssert.class);
}
/**
* fluent entry point
*
* @param actual the actual task to assert on
* @return a new instance of the task assertion
*/
@Contract("_ -> new")
public static BuildTaskAssert assertThat(BuildTask actual) {
return new BuildTaskAssert(actual);
}
/**
* Assert that the task was run and resulted in the expected outcome
* @param outcome the expected outcome
* @return the same instance of the task assertion for chaining
*/
@Contract("_ -> this")
public BuildTaskAssert hasOutcome(TaskOutcome outcome) {
this.objects.assertNotNull(this.info, actual);
if (actual.getOutcome() != outcome) {
failWithMessage("Expected outcome of task <%s> is <%s> but was <%s>",
actual.getPath(), outcome, actual.getOutcome());
}
return this;
}
/**
* Assert that the task was run and resulted in any of the expected outcomes
* @param outcomes the expected possible outcomes
* @return the same instance of the task assertion for chaining
*/
@Contract("_ -> this")
public BuildTaskAssert hasOutcome(TaskOutcome... outcomes) {
this.objects.assertNotNull(this.info, actual);
final List<TaskOutcome> expected = Arrays.asList(outcomes);
if (!expected.contains(actual.getOutcome())) {
failWithMessage("Expected outcome of task <%s> to be one of <%s> but was <%s>",
actual.getPath(),
expected.stream().map(Enum::name).collect(Collectors.joining(",")),
actual.getOutcome());
}
return this;
}
}