Skip to content

Commit

Permalink
Use AssertJ recursive assertion and replace getCause with cause asser…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
filiphr committed Feb 13, 2024
1 parent 5f65ec9 commit f43c3c6
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,9 @@ protected void assertThatTaskLogIsFetched(HistoricTaskLogEntryBuilder historicTa

List<HistoricTaskLogEntry> pagedLogEntries = historicTaskLogEntryQuery.listPage(1, 1);
assertThat(pagedLogEntries).hasSize(1);
assertThat(pagedLogEntries.get(0)).isEqualToComparingFieldByField(logEntries.get(1));
assertThat(pagedLogEntries.get(0))
.usingRecursiveComparison()
.isEqualTo(logEntries.get(1));

} finally {
deleteTaskWithLogEntries(anotherTask.getId());
Expand All @@ -753,7 +755,9 @@ protected void assertThatAllTaskLogIsFetched(HistoricTaskLogEntryBuilder histori

List<HistoricTaskLogEntry> pagedLogEntries = historicTaskLogEntryQuery.listPage(1, 1);
assertThat(pagedLogEntries).hasSize(1);
assertThat(pagedLogEntries.get(0)).isEqualToComparingFieldByField(logEntries.get(1));
assertThat(pagedLogEntries.get(0))
.usingRecursiveComparison()
.isEqualTo(logEntries.get(1));

} finally {
deleteTaskWithLogEntries(anotherTask.getId());
Expand Down Expand Up @@ -855,7 +859,9 @@ public void queryForTaskLogEntriesByToIncludedTimeStamp() {

List<HistoricTaskLogEntry> pagedLogEntries = historicTaskLogEntryQuery.listPage(1, 1);
assertThat(pagedLogEntries).hasSize(1);
assertThat(pagedLogEntries.get(0)).isEqualToComparingFieldByField(logEntries.get(1));
assertThat(pagedLogEntries.get(0))
.usingRecursiveComparison()
.isEqualTo(logEntries.get(1));

} finally {
deleteTaskWithLogEntries(anotherTask.getId());
Expand Down Expand Up @@ -934,7 +940,9 @@ public void queryForTaskLogEntriesByLogNumber() {

List<HistoricTaskLogEntry> pagedLogEntries = historicTaskLogEntryQuery.listPage(1, 1);
assertThat(pagedLogEntries).hasSize(1);
assertThat(pagedLogEntries.get(0)).isEqualToComparingFieldByField(logEntries.get(1));
assertThat(pagedLogEntries.get(0))
.usingRecursiveComparison()
.isEqualTo(logEntries.get(1));

} finally {
deleteTaskWithLogEntries(anotherTask.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,9 @@ protected void assertThatTaskLogIsFetched(HistoricTaskLogEntryBuilder historicTa

List<HistoricTaskLogEntry> pagedLogEntries = historicTaskLogEntryQuery.listPage(1, 1);
assertThat(pagedLogEntries).hasSize(1);
assertThat(pagedLogEntries.get(0)).isEqualToComparingFieldByField(logEntries.get(1));
assertThat(pagedLogEntries.get(0))
.usingRecursiveComparison()
.isEqualTo(logEntries.get(1));
}

} finally {
Expand Down Expand Up @@ -865,7 +867,9 @@ protected void assertThatAllTaskLogIsFetched(HistoricTaskLogEntryBuilder histori

List<HistoricTaskLogEntry> pagedLogEntries = historicTaskLogEntryQuery.listPage(1, 1);
assertThat(pagedLogEntries).hasSize(1);
assertThat(pagedLogEntries.get(0)).isEqualToComparingFieldByField(logEntries.get(1));
assertThat(pagedLogEntries.get(0))
.usingRecursiveComparison()
.isEqualTo(logEntries.get(1));
}

} finally {
Expand Down Expand Up @@ -940,7 +944,9 @@ public void queryForTaskLogEntriesByToTimeStamp() {

List<HistoricTaskLogEntry> pagedLogEntries = historicTaskLogEntryQuery.listPage(1, 1);
assertThat(pagedLogEntries).hasSize(1);
assertThat(pagedLogEntries.get(0)).isEqualToComparingFieldByField(logEntries.get(1));
assertThat(pagedLogEntries.get(0))
.usingRecursiveComparison()
.isEqualTo(logEntries.get(1));
}

} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ protected void checkActivityInstances(ProcessDefinition processDefinition, Proce
activityInstance -> {
HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery()
.activityInstanceId(activityInstance.getId()).singleResult();
assertThat(activityInstance).isEqualToComparingFieldByField(historicActivityInstance);
assertThat(activityInstance)
.usingRecursiveComparison()
.isEqualTo(historicActivityInstance);
}
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,9 @@ public void testMigrateProcessWithCallActivityWithoutAlteringTheSubProcessDefini
.containsOnly(procDefWithCallActivityV2.getId());
ProcessInstance subProcessInstanceAfterMigration = runtimeService.createProcessInstanceQuery().superProcessInstanceId(processInstance.getId())
.singleResult();
assertThat(subProcessInstanceAfterMigration).isEqualToComparingFieldByField(subProcessInstance);
assertThat(subProcessInstanceAfterMigration)
.usingRecursiveComparison()
.isEqualTo(subProcessInstance);
List<Execution> subProcessExecutionsAfterMigration = runtimeService.createExecutionQuery().processInstanceId(subProcessInstanceAfterMigration.getId())
.onlyChildExecutions().list();
assertThat(subProcessExecutionsAfterMigration)
Expand All @@ -1807,7 +1809,9 @@ public void testMigrateProcessWithCallActivityWithoutAlteringTheSubProcessDefini
.containsOnly(procDefSubProcess.getId());
subProcessExecutions.sort(Comparator.comparing(Execution::getId));
subProcessExecutionsAfterMigration.sort(Comparator.comparing(Execution::getId));
assertThat(subProcessExecutionsAfterMigration).usingFieldByFieldElementComparator().isEqualTo(subProcessExecutions);
assertThat(subProcessExecutionsAfterMigration)
.usingRecursiveFieldByFieldElementComparator()
.isEqualTo(subProcessExecutions);

List<Task> subProcessTasksAfterMigration = taskService.createTaskQuery().processInstanceId(subProcessInstance.getId()).list();
assertThat(subProcessTasksAfterMigration)
Expand All @@ -1816,7 +1820,9 @@ public void testMigrateProcessWithCallActivityWithoutAlteringTheSubProcessDefini

subProcessTasks.sort(Comparator.comparing(Task::getId));
subProcessTasksAfterMigration.sort(Comparator.comparing(Task::getId));
assertThat(subProcessTasksAfterMigration).usingFieldByFieldElementComparator().isEqualTo(subProcessTasks);
assertThat(subProcessTasksAfterMigration)
.usingRecursiveFieldByFieldElementComparator()
.isEqualTo(subProcessTasks);

subProcessTasksAfterMigration.forEach(this::completeTask);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ public void testDeSerializeCompleteProcessInstanceMigrationDocument() {
.containsExactly(oneToOneMapping, oneToManyMapping, manyToOneMapping);
assertThat(migrationDocument.getActivitiesLocalVariables()).isEqualTo(activityLocalVariables);
assertThat(migrationDocument.getProcessInstanceVariables()).isEqualTo(processInstanceVariables);
assertThat(migrationDocument.getPreUpgradeScript()).isEqualToComparingFieldByField(new Script("groovy", "1+1"));
assertThat(migrationDocument.getPostUpgradeScript()).isEqualToComparingFieldByField(new Script("groovy", "2+2"));
assertThat(migrationDocument.getPreUpgradeScript())
.usingRecursiveComparison()
.isEqualTo(new Script("groovy", "1+1"));
assertThat(migrationDocument.getPostUpgradeScript())
.usingRecursiveComparison()
.isEqualTo(new Script("groovy", "2+2"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,9 @@ public void testMigrateActivityToActivityWithTimerInNewDefinition() {
Execution execution = runtimeService.createExecutionQuery().parentId(task.getExecutionId()).singleResult();
Job job = managementService.createTimerJobQuery().executionId(execution.getId()).singleResult();
assertThat(job)
.isEqualToIgnoringGivenFields(timerJob, "originalPersistentState", "customValuesByteArrayRef", "exceptionByteArrayRef");
.usingRecursiveComparison()
.ignoringFields("originalPersistentState", "customValuesByteArrayRef", "exceptionByteArrayRef")
.isEqualTo(timerJob);

// Verify events
assertThat(changeStateEventListener.hasEvents()).isTrue();
Expand Down Expand Up @@ -1992,7 +1994,9 @@ public void testMigrateActivityWithTimerToActivityWithoutTimerInNewDefinition()
Execution execution = runtimeService.createExecutionQuery().parentId(task.getExecutionId()).singleResult();
Job job = managementService.createTimerJobQuery().executionId(execution.getId()).singleResult();
assertThat(job)
.isEqualToIgnoringGivenFields(timerJob, "originalPersistentState", "customValuesByteArrayRef", "exceptionByteArrayRef");
.usingRecursiveComparison()
.ignoringFields("originalPersistentState", "customValuesByteArrayRef", "exceptionByteArrayRef")
.isEqualTo(timerJob);

changeStateEventListener.clear();

Expand Down Expand Up @@ -2096,7 +2100,9 @@ public void testMigrateActivityWithTimerToActivityWithTimerInNewDefinition() {
Execution execution = runtimeService.createExecutionQuery().parentId(task.getExecutionId()).singleResult();
Job job = managementService.createTimerJobQuery().executionId(execution.getId()).singleResult();
assertThat(job)
.isEqualToIgnoringGivenFields(timerJob2, "originalPersistentState", "customValuesByteArrayRef", "exceptionByteArrayRef");
.usingRecursiveComparison()
.ignoringFields("originalPersistentState", "customValuesByteArrayRef", "exceptionByteArrayRef")
.isEqualTo(timerJob2);
assertThat(timerJob1)
.extracting(Job::getExecutionId)
.isNotEqualTo(timerJob2);
Expand Down Expand Up @@ -2530,7 +2536,9 @@ public void testMigrateActivityToActivityWithTimerInsideEmbeddedSubProcessInNewD
Execution timerExecution = runtimeService.createExecutionQuery().parentId(task.getExecutionId()).singleResult();
Job timerFromTask = managementService.createTimerJobQuery().executionId(timerExecution.getId()).singleResult();
assertThat(timerJob)
.isEqualToIgnoringGivenFields(timerFromTask, "originalPersistentState", "customValuesByteArrayRef", "exceptionByteArrayRef");
.usingRecursiveComparison()
.ignoringFields("originalPersistentState", "customValuesByteArrayRef", "exceptionByteArrayRef")
.isEqualTo(timerFromTask);

// Verify events
assertThat(changeStateEventListener.hasEvents()).isTrue();
Expand Down Expand Up @@ -2619,7 +2627,9 @@ public void testMigrateActivityToActivityWithTimerInsideEmbeddedSubProcessInNewD
Execution timerExecution = runtimeService.createExecutionQuery().parentId(task.getExecutionId()).singleResult();
Job timerFromTask = managementService.createTimerJobQuery().executionId(timerExecution.getId()).singleResult();
assertThat(timerJob)
.isEqualToIgnoringGivenFields(timerFromTask, "originalPersistentState", "customValuesByteArrayRef", "exceptionByteArrayRef");
.usingRecursiveComparison()
.ignoringFields("originalPersistentState", "customValuesByteArrayRef", "exceptionByteArrayRef")
.isEqualTo(timerFromTask);

// Verify events
assertThat(changeStateEventListener.hasEvents()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void testConnectTimeout() {
public void testRequestTimeout() {
assertThatThrownBy(() -> runtimeService.startProcessInstanceByKey("requestTimeout"))
.isExactlyInstanceOf(FlowableException.class)
.getCause().isInstanceOfAny(SocketTimeoutException.class, SocketException.class);
.cause().isInstanceOfAny(SocketTimeoutException.class, SocketException.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void shouldCorrectlyCustomizeLdapConfiguration() {

assertThat(ldapConfiguration)
.as("Base Ldap Configuration")
.isEqualToIgnoringGivenFields(properties,
.usingRecursiveComparison()
.ignoringFields(
"queryUserByUserId",
"queryUserByFullNameLike",
"queryAllUsers",
Expand All @@ -87,7 +88,8 @@ public void shouldCorrectlyCustomizeLdapConfiguration() {
"groupCacheExpirationTime",
"ldapQueryBuilder",
"groupCacheListener"
);
)
.isEqualTo(properties);

assertThat(ldapConfiguration)
.as("Query properties")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ public void processEngineWithCustomIdGenerator() {
assertThat(dbIdGenerator.getIdBlockSize()).isEqualTo(engineConfiguration.getIdBlockSize());
assertThat(dbIdGenerator.getCommandExecutor()).isEqualTo(engineConfiguration.getCommandExecutor());
assertThat(dbIdGenerator.getCommandConfig())
.isEqualToComparingFieldByField(engineConfiguration.getDefaultCommandConfig().transactionRequiresNew());
.usingRecursiveComparison()
.isEqualTo(engineConfiguration.getDefaultCommandConfig().transactionRequiresNew());
});
});
}
Expand All @@ -467,7 +468,8 @@ public void processEngineWithCustomIdGeneratorAsBean() {
assertThat(dbIdGenerator.getIdBlockSize()).isEqualTo(engineConfiguration.getIdBlockSize());
assertThat(dbIdGenerator.getCommandExecutor()).isEqualTo(engineConfiguration.getCommandExecutor());
assertThat(dbIdGenerator.getCommandConfig())
.isEqualToComparingFieldByField(engineConfiguration.getDefaultCommandConfig().transactionRequiresNew());
.usingRecursiveComparison()
.isEqualTo(engineConfiguration.getDefaultCommandConfig().transactionRequiresNew());
})
.isEqualTo(context.getBean(IdGenerator.class));
});
Expand Down

0 comments on commit f43c3c6

Please sign in to comment.