flowable / flowable/flowable-engine
Fluent assertions
- Vorherrschende Sprache
- Java
- Sterne
- 9.5k
- Forks
- 2.9k
- Ø Merge
- 7 Std. 8 Min.
- Gemergte PRs (30 T.)
- 2
Beschreibung
**Is your feature request related to a problem? Please describe.**
Assertions are not readable. Instead of:
```
@Test
void followHappyPath(RuntimeService runtimeService, TaskService taskService, HistoryService historyService) {
ProcessInstance helloWorldProcess = runtimeService.createProcessInstanceBuilder().processDefinitionKey("P001-helloWorld").start();
assertThat(helloWorldProcess).isNotNull();
List path = new ArrayList<>(List.of("theStart", "theStart-theSayHelloUserTask", "theSayHelloUserTask"));
assertThat(runtimeService.createActivityInstanceQuery()
.processInstanceId(helloWorldProcess.getId()).orderByActivityInstanceStartTime().asc().list())
.as("The hello world process has to go directly through theStart -> theSayHelloUserTask")
.extracting(ActivityInstance::getActivityId)
.containsExactlyInAnyOrderElementsOf(path);
assertThat(runtimeService.createVariableInstanceQuery().processInstanceId(helloWorldProcess.getId()).list())
.extracting("name", "value")
.containsExactly(Tuple.tuple("initiator", null));
Task userTask = taskService.createTaskQuery().processInstanceId(helloWorldProcess.getId()).singleResult();
assertThat(userTask).extracting(Task::getName).isEqualTo("Say hello world");
assertThat(userTask).extracting(Task::getTaskDefinitionKey).isEqualTo("theSayHelloUserTask");
taskService.complete(userTask.getId(), Map.of("greeting", "Hello World!"));
assertThat(runtimeService.createActivityInstanceQuery().processInstanceId(helloWorldProcess.getId()).singleResult())
.as("The hello world process is finished, no instance is present in the runtime.")
.isNull();
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(helloWorldProcess.getId()).singleResult();
assertThat(historicProcessInstance)
.as("The hello world process must be present in the history")
.isNotNull();
assertThat(historicProcessInstance.getEndTime())
.as("The hello world process must be finished")
.isNotNull();
assertThat(historyService.createHistoricVariableInstanceQuery().processInstanceId(helloWorldProcess.getId()).list())
.as("All variables must be present in the history")
.extracting("name", "value")
.containsExactlyInAnyOrder(Tuple.tuple("initiator", null), Tuple.tuple("greeting", "Hello World!"));
path.addAll(List.of("theSayHelloUserTask-theEnd", "theEnd"));
assertThat(historyService.createHistoricActivityInstanceQuery().processInstanceId(helloWorldProcess.getId()).orderByHistoricActivityInstanceStartTime().asc().list())
.as("The hello world process must pass through all activities")
.extracting(HistoricActivityInstance::getActivityId)
.containsExactlyInAnyOrderElementsOf(path);
}
```
Use:
```
@Test
void followHappyPathWithFluentAssertions(RuntimeService runtimeService, TaskService taskService) {
ProcessInstance helloWorldProcess = runtimeService.createProcessInstanceBuilder().processDefinitionKey("P001-helloWorld").start();
List path = new ArrayList<>(List.of("theStart", "theStart-theSayHelloUserTask", "theSayHelloUserTask"));
assertThat(helloWorldProcess)
.isRunning()
.hasVariableWithValue("initiator", null)
.activities()
.extracting(ActivityInstance::getActivityId)
.containsExactlyInAnyOrderElementsOf(path);
assertThat(helloWorldProcess)
.userTasks()
.extracting("name", "taskDefinitionKey")
.containsExactly(Tuple.tuple("Say hello world", "theSayHelloUserTask"));
Task userTask = taskService.createTaskQuery().processInstanceId(helloWorldProcess.getId()).singleResult();
taskService.complete(userTask.getId(), Map.of("greeting", "Hello World!"));
assertThat(helloWorldProcess)
.as("The hello world process is finished, no instance is present in the runtime.")
.doesNotExist()
.inHistory()
.as("The hello world process must be present in the history and finished")
.isFinished()
.variables()
.as("All variables must be present in the history")
.extracting("name", "value")
.containsExactlyInAnyOrder(Tuple.tuple("initiator", null), Tuple.tuple("greeting", "Hello World!"));
path.addAll(List.of("theSayHelloUserTask-theEnd", "theEnd"));
assertThat(helloWorldProcess).inHistory()
.as("The hello world process must pass through all activities")
.activities()
.extracting(HistoricActivityInstance::getActivityId)
.containsExactlyInAnyOrderElementsOf(path);
}
```
The code can be even more readable in groovy.
https://github.com/crystal-processes/crp-flowable-springboot-sample/blob/main/docs/01_sample/02-helloWorld.md#partly_sunny-what-to-do-next---tests
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Start with the issue's before-and-after followHappyPath examples and the linked helloWorld.md sample. Identify the existing test assertion entry points for process state, activities, user tasks, history, and variables. Done means the fluent chains shown in the requested example are supported and the corresponding sample test can use them successfully.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- testing
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100