Skip to content

Commit

Permalink
chore(tests): Resolve Sonar assertj warnings (operaton#212)
Browse files Browse the repository at this point in the history
chore(tests): resolve Sonar issues for assertj (operaton#27)

replace isEqualTo(true) by isTrue()
replace isEqualTo(false) by isFalse()
replace isEqualTo(0) by isZero()
replace hasSize(0) by isEmpty()
replace toString()).isEqualTo by hasToString()
replace .size()).isEqualTo by .hasSize(()
replace `.size()).isZero()` by `).isEmpty()``
replace `.isEqualTo(0L)` by `.isZero()``
replace `.contains(String).isTrue()` by `.contains(String)`
replace `map.get(KEY).isEqualTo` by `containsEntry`
replace `size().isZero()` by `isEmpty()`
replace `keySet()).contains` by `containsKey()`
replace `.isGreaterThan(0)` by `.isPositive()`
chain assertion statements

related to operaton#27
  • Loading branch information
kthoms authored Nov 17, 2024
1 parent c8e5c55 commit 4d5b3c8
Show file tree
Hide file tree
Showing 290 changed files with 2,071 additions and 2,600 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ public long calculateBackoffTime() {
// then
EngineException exception = (EngineException) ex.get();
assertThat(exception).isInstanceOf(EngineException.class);
assertThat(exception.getCode()).isEqualTo(0);
assertThat(exception.getCode()).isZero();
assertThat(exception.getType()).isEqualTo("ProcessEngineException");
assertThat(exception.getMessage()).isEqualTo("TASK/CLIENT-03009 Exception while fetching and locking task: Object values cannot be used to query");
assertThat(exception.getHttpStatusCode()).isEqualTo(500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.operaton.bpm.client.util.ProcessModels.BPMN_ERROR_EXTERNAL_TASK_PROCESS;
import static org.operaton.bpm.client.util.ProcessModels.EXTERNAL_TASK_TOPIC_FOO;
import static org.operaton.bpm.client.util.ProcessModels.ONE_EXTERNAL_TASK_WITH_OUTPUT_PARAM_PROCESS;
import static org.operaton.bpm.client.util.ProcessModels.ONE_EXTERNAL_TASK_WITH_VERSION_TAG;
import static org.operaton.bpm.client.util.ProcessModels.PROCESS_DEFINITION_VERSION_TAG;
import static org.operaton.bpm.client.util.ProcessModels.PROCESS_KEY;
import static org.operaton.bpm.client.util.ProcessModels.PROCESS_KEY_2;
import static org.operaton.bpm.client.util.ProcessModels.*;

/**
* @author Tassilo Weidner
Expand Down Expand Up @@ -140,7 +134,7 @@ public void shouldFilterByProcessDefinitionId() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(1);
assertThat(handler.getHandledTasks()).hasSize(1);
ExternalTask task = handler.getHandledTasks().get(0);
assertThat(task.getProcessDefinitionId()).isEqualTo(processDefinitionId2);
assertThat(topicSubscription.getProcessDefinitionId()).isEqualTo(processDefinitionId2);
Expand Down Expand Up @@ -185,7 +179,7 @@ public void shouldFilterByProcessDefinitionIdIn() {
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

List<ExternalTask> handledTasks = handler.getHandledTasks();
assertThat(handledTasks.size()).isEqualTo(2);
assertThat(handledTasks).hasSize(2);
}

@Test
Expand All @@ -203,7 +197,7 @@ public void shouldFilterByProcessDefinitionKey() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(1);
assertThat(handler.getHandledTasks()).hasSize(1);
ExternalTask task = handler.getHandledTasks().get(0);
assertThat(task.getProcessDefinitionKey()).isEqualTo(PROCESS_KEY_2);
assertThat(topicSubscription.getProcessDefinitionKey()).isEqualTo(PROCESS_KEY_2);
Expand Down Expand Up @@ -245,7 +239,7 @@ public void shouldFilterByProcessDefinitionKeyIn() {
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

List<ExternalTask> handledTasks = handler.getHandledTasks();
assertThat(handledTasks.size()).isEqualTo(2);
assertThat(handledTasks).hasSize(2);
}

@Test
Expand All @@ -265,7 +259,7 @@ public void shouldFilterByProcessDefinitionVersionTag() {
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

List<ExternalTask> handledTasks = handler.getHandledTasks();
assertThat(handledTasks.size()).isEqualTo(1);
assertThat(handledTasks).hasSize(1);
assertThat(handledTasks.get(0).getProcessDefinitionKey()).isEqualTo(PROCESS_DEFINITION_VERSION_TAG);
assertThat(handledTasks.get(0).getProcessDefinitionVersionTag()).isEqualTo(PROCESS_DEFINITION_VERSION_TAG);
}
Expand All @@ -286,7 +280,7 @@ public void shouldSetProcessDefinitionVersionTag() {
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

List<ExternalTask> handledTasks = handler.getHandledTasks();
assertThat(handledTasks.size()).isEqualTo(2);
assertThat(handledTasks).hasSize(2);
assertThat(handledTasks.get(0).getProcessDefinitionVersionTag()).isEqualTo(null);
assertThat(handledTasks.get(1).getProcessDefinitionVersionTag()).isEqualTo(PROCESS_DEFINITION_VERSION_TAG);
}
Expand All @@ -305,7 +299,7 @@ public void shouldFilterByNoTenantId() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(1);
assertThat(handler.getHandledTasks()).hasSize(1);
}

@Test
Expand All @@ -324,7 +318,7 @@ public void shouldNotApplyAnyFilter() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(2);
assertThat(handler.getHandledTasks()).hasSize(2);
}

@Test
Expand All @@ -344,7 +338,7 @@ public void shouldFilterWithoutTenantId() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(1);
assertThat(handler.getHandledTasks()).hasSize(1);
ExternalTask task = handler.getHandledTasks().get(0);
assertThat(task.getTenantId()).isNull();
assertThat(task.getProcessInstanceId()).isEqualTo(processInstance.getId());
Expand All @@ -368,7 +362,7 @@ public void shouldFilterByTenantId() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(1);
assertThat(handler.getHandledTasks()).hasSize(1);
ExternalTask task = handler.getHandledTasks().get(0);
assertThat(task.getTenantId()).isEqualTo(tenantId);
assertThat(task.getProcessInstanceId()).isEqualTo(processInstance.getId());
Expand All @@ -391,20 +385,20 @@ public void shouldFilterByBusinessKeyAndVariable() {
// then
clientRule.waitForFetchAndLockUntil(() -> handler.getHandledTasks().size() == 2);

assertThat(topicSubscription.getVariableNames().size()).isEqualTo(1);
assertThat(topicSubscription.getVariableNames()).hasSize(1);
assertThat(topicSubscription.getVariableNames().get(0)).isEqualTo(VARIABLE_NAME);

List<ExternalTask> handledTasks = handler.getHandledTasks();
assertThat(handledTasks.size()).isEqualTo(2);
assertThat(handledTasks).hasSize(2);

ExternalTask task = handledTasks.get(0);
assertThat(task.getBusinessKey()).isEqualTo(BUSINESS_KEY);

if (task.getVariable(VARIABLE_NAME) != null) {
assertThat(task.getAllVariables().size()).isEqualTo(1);
assertThat(task.getAllVariables()).hasSize(1);
assertThat((String) task.getVariable(VARIABLE_NAME)).isEqualTo(VARIABLE_VALUE);
} else {
assertThat(task.getAllVariables().size()).isEqualTo(0);
assertThat(task.getAllVariables()).isEmpty();
}
}

Expand All @@ -424,10 +418,10 @@ public void shouldFilterByNotExistingVariable() {
clientRule.waitForFetchAndLockUntil(() -> handler.getHandledTasks().size() == 2);

ExternalTask taskOne = handler.getHandledTasks().get(0);
assertThat(taskOne.getAllVariables().size()).isEqualTo(0);
assertThat(taskOne.getAllVariables()).isEmpty();

ExternalTask taskTwo = handler.getHandledTasks().get(1);
assertThat(taskTwo.getAllVariables().size()).isEqualTo(0);
assertThat(taskTwo.getAllVariables()).isEmpty();
}

@Test
Expand All @@ -446,10 +440,10 @@ public void shouldFilterByNoVariable() {
clientRule.waitForFetchAndLockUntil(() -> handler.getHandledTasks().size() == 2);

ExternalTask taskOne = handler.getHandledTasks().get(0);
assertThat(taskOne.getAllVariables().size()).isEqualTo(0);
assertThat(taskOne.getAllVariables()).isEmpty();

ExternalTask taskTwo = handler.getHandledTasks().get(0);
assertThat(taskTwo.getAllVariables().size()).isEqualTo(0);
assertThat(taskTwo.getAllVariables()).isEmpty();
}

@Test
Expand Down Expand Up @@ -562,7 +556,7 @@ public void shouldFilterByOneToOneProcessVariableEquals() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(1);
assertThat(handler.getHandledTasks()).hasSize(1);
}

@Test
Expand All @@ -585,7 +579,7 @@ public void shouldFilterByOneToAnyProcessVariableEquals() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(2);
assertThat(handler.getHandledTasks()).hasSize(2);
}

@Test
Expand All @@ -609,7 +603,7 @@ public void shouldFilterByManyToAnyProcessVariableEquals() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(2);
assertThat(handler.getHandledTasks()).hasSize(2);

}

Expand Down Expand Up @@ -637,7 +631,7 @@ public void shouldNotFilterByManyToNoneProcessVariableEquals() {
// then
clientRule.waitForFetchAndLockUntil(() -> handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(0);
assertThat(handler.getHandledTasks()).isEmpty();
}

@Test
Expand All @@ -658,7 +652,7 @@ public void shouldFilterByOneToOneProcessVariablesEqualsIn() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(1);
assertThat(handler.getHandledTasks()).hasSize(1);
}

@Test
Expand All @@ -683,7 +677,7 @@ public void shouldFilterByOneToAnyProcessVariablesEqualsIn() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(2);
assertThat(handler.getHandledTasks()).hasSize(2);
}

@Test
Expand All @@ -710,7 +704,7 @@ public void shouldFilterByManyToAnyProcessVariablesEqualsIn() {
// then
clientRule.waitForFetchAndLockUntil(() -> !handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(2);
assertThat(handler.getHandledTasks()).hasSize(2);
}

@Test
Expand Down Expand Up @@ -739,7 +733,7 @@ public void shouldNotFilterByManyToNoneProcessVariablesEqualsIn() {
// then
clientRule.waitForFetchAndLockUntil(() -> handler.getHandledTasks().isEmpty());

assertThat(handler.getHandledTasks().size()).isEqualTo(0);
assertThat(handler.getHandledTasks()).isEmpty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void shouldGet() {
ExternalTask task = handler.getHandledTasks().get(0);

// then
assertThat(task.getAllVariables().size()).isEqualTo(1);
assertThat(task.getAllVariables()).hasSize(1);
assertThat(IoUtil.inputStreamAsString(task.getVariable(VARIABLE_NAME_FILE)))
.isEqualTo(new String(VARIABLE_VALUE_FILE_VALUE));
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public void shouldGetLocalAndGlobalVariables() {
ExternalTask task = handler.getHandledTasks().get(0);

// then
assertThat(task.getAllVariables().size()).isEqualTo(2);
assertThat(task.getAllVariables()).hasSize(2);
assertThat(IoUtil.inputStreamAsString(task.getVariable(VARIABLE_NAME_FILE)))
.isEqualTo(new String(VARIABLE_VALUE_FILE_VALUE));
assertThat(IoUtil.inputStreamAsString(task.getVariable(LOCAL_VARIABLE_NAME_FILE)))
Expand All @@ -171,7 +171,7 @@ public void shouldGetAll() {
ExternalTask task = handler.getHandledTasks().get(0);

// then
assertThat(task.getAllVariables().size()).isEqualTo(2);
assertThat(task.getAllVariables()).hasSize(2);
assertThat(IoUtil.inputStreamAsString((InputStream) task.getAllVariables().get(VARIABLE_NAME_FILE)))
.isEqualTo(new String(VARIABLE_VALUE_FILE_VALUE));
assertThat(IoUtil.inputStreamAsString((InputStream) task.getAllVariables().get(ANOTHER_VARIABLE_NAME_FILE)))
Expand Down Expand Up @@ -585,7 +585,7 @@ public void shouldFailWhenCompletingWihtDeferredFileValue() {

// then
List<VariableInstanceDto> variableInstances = engineRule.getVariablesByProcessInstanceIdAndVariableName(processInstance.getId(), null);
assertThat(variableInstances.size()).isEqualTo(2);
assertThat(variableInstances).hasSize(2);

List<String> variableNames = new ArrayList<>();
for (VariableInstanceDto variableInstance : variableInstances) {
Expand Down Expand Up @@ -626,7 +626,7 @@ public void shouldSet_LoadedFileValue() {

// then
List<VariableInstanceDto> variableInstances = engineRule.getVariablesByProcessInstanceIdAndVariableName(processInstance.getId(), null);
assertThat(variableInstances.size()).isEqualTo(3);
assertThat(variableInstances).hasSize(3);

List<String> variableNames = new ArrayList<>();
for (VariableInstanceDto variableInstance : variableInstances) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@
import java.util.Arrays;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.operaton.bpm.client.util.ProcessModels.EXTERNAL_TASK_TOPIC_BAR;
import static org.operaton.bpm.client.util.ProcessModels.EXTERNAL_TASK_TOPIC_FOO;
import static org.operaton.bpm.client.util.ProcessModels.TWO_EXTERNAL_TASK_PROCESS;
import static org.assertj.core.api.Assertions.*;
import static org.operaton.bpm.client.util.ProcessModels.*;
import static org.operaton.bpm.engine.variable.Variables.SerializationDataFormats.XML;
import static org.operaton.bpm.engine.variable.type.ValueType.OBJECT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void shouldThrowNotFoundException() {

// then
NotFoundException px = (NotFoundException) catchThrowable(() -> service.complete(externalTask));
assertThat(px.getCode()).isEqualTo(0);
assertThat(px.getCode()).isZero();
assertThat(px.getType()).isEqualTo("RestException");
assertThat(px.getMessage()).isEqualTo("TASK/CLIENT-01008 Exception while completing the external task: External task with id not-existing-id does not exist");
assertThat(px.getHttpStatusCode()).isEqualTo(404);
Expand Down Expand Up @@ -208,7 +208,7 @@ public void shouldThrowBadRequestException() {
// then
BadRequestException px = (BadRequestException) catchThrowable(() -> service.complete(externalTask));
assertThat(px).isInstanceOf(BadRequestException.class);
assertThat(px.getCode()).isEqualTo(0);
assertThat(px.getCode()).isZero();
assertThat(px.getType()).isEqualTo("RestException");
assertThat(px.getMessage()).matches("TASK/CLIENT-01007 Exception while completing the external task: "
+ "External Task ([a-z0-9-]*) cannot be completed by worker 'aWorkerId'. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void setup() {
void shouldAdvanceBackoffStrategy() {
// given
long initialWaitingTime = backoffStrategy.calculateBackoffTime();
assertThat(initialWaitingTime).isEqualTo(0L);
assertThat(initialWaitingTime).isZero();

// when
// in consecutive iterations, no external tasks are available
Expand All @@ -66,14 +66,14 @@ void shouldResetBackoffStrategy() {

// then
long waitingTime2 = backoffStrategy.calculateBackoffTime();
assertThat(waitingTime2).isEqualTo(0L);
assertThat(waitingTime2).isZero();
}

@Test
void shouldCapWaitingTime() {
// given
long waitingTime = backoffStrategy.calculateBackoffTime();
assertThat(waitingTime).isEqualTo(0L);
assertThat(waitingTime).isZero();

// when
// reach maximum waiting time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void setup() {
void shouldAdvanceBackoffStrategy() {
// given
long initialWaitingTime = backoffStrategy.calculateBackoffTime();
assertThat(initialWaitingTime).isEqualTo(0L);
assertThat(initialWaitingTime).isZero();

// when
// in consecutive iterations, an error occurs
Expand Down Expand Up @@ -71,14 +71,14 @@ void shouldResetBackoffStrategy() {

// then
long waitingTime2 = backoffStrategy.calculateBackoffTime();
assertThat(waitingTime2).isEqualTo(0L);
assertThat(waitingTime2).isZero();
}

@Test
void shouldCapWaitingTime() {
// given
long waitingTime = backoffStrategy.calculateBackoffTime();
assertThat(waitingTime).isEqualTo(0L);
assertThat(waitingTime).isZero();

// when
// reach maximum waiting time
Expand All @@ -97,7 +97,7 @@ void shouldCapWaitingTime() {
void shouldCapWaitingTime2() {
// given
long waitingTime = backoffStrategy.calculateBackoffTime();
assertThat(waitingTime).isEqualTo(0L);
assertThat(waitingTime).isZero();

// when
// reach maximum waiting time
Expand Down
Loading

0 comments on commit 4d5b3c8

Please sign in to comment.