Skip to content

Commit

Permalink
Use AssertJ assertThatThrownBy instead of JUnit 4 ExpectedException rule
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr committed Feb 12, 2024
1 parent eab41c2 commit e5d93bd
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,13 @@
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.variable.api.history.HistoricVariableInstance;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
* @author Joram Barrez
*/
public class CmmnPrefixTest {

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
public void testPrefixCase() {
CmmnEngine cmmnEngine = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.flowable.cmmn.test.runtime;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.Collections;
import java.util.HashSet;
Expand All @@ -28,18 +29,13 @@
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.common.engine.impl.AbstractEngineConfiguration;
import org.flowable.identitylink.api.IdentityLinkType;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
* @author martin.grofcik
*/
public class CaseInstanceInvolvementTest extends FlowableCmmnTestCase {

@Rule
public ExpectedException expectException = ExpectedException.none();

@Test
@CmmnDeployment(resources = "org/flowable/cmmn/test/runtime/oneTaskCase.cmmn")
public void getCaseInstanceWithInvolvedUser() {
Expand Down Expand Up @@ -94,26 +90,23 @@ public void getCaseInstanceWithNonExistingInvolvedUser() {

@Test
public void getCaseInstanceWithNullInvolvedUser() {
this.expectException.expect(FlowableIllegalArgumentException.class);
this.expectException.expectMessage("involvedUser is null");

cmmnRuntimeService.createCaseInstanceQuery().involvedUser(null);
assertThatThrownBy(() -> cmmnRuntimeService.createCaseInstanceQuery().involvedUser(null))
.isInstanceOf(FlowableIllegalArgumentException.class)
.hasMessage("involvedUser is null");
}

@Test
public void getCaseInstanceWithNullInvolvedGroups() {
this.expectException.expect(FlowableIllegalArgumentException.class);
this.expectException.expectMessage("involvedGroups are null");

cmmnRuntimeService.createCaseInstanceQuery().involvedGroups(null);
assertThatThrownBy(() -> cmmnRuntimeService.createCaseInstanceQuery().involvedGroups(null))
.isInstanceOf(FlowableIllegalArgumentException.class)
.hasMessage("involvedGroups are null");
}

@Test
public void getCaseInstanceWithEmptyInvolvedGroups() {
this.expectException.expect(FlowableIllegalArgumentException.class);
this.expectException.expectMessage("involvedGroups are empty");

cmmnRuntimeService.createCaseInstanceQuery().involvedGroups(Collections.emptySet());
assertThatThrownBy(() -> cmmnRuntimeService.createCaseInstanceQuery().involvedGroups(Collections.emptySet()))
.isInstanceOf(FlowableIllegalArgumentException.class)
.hasMessage("involvedGroups are empty");
}

@Test
Expand All @@ -124,10 +117,9 @@ public void getCaseInstanceWithNonNullInvolvedUser() {
start();
cmmnRuntimeService.addUserIdentityLink(caseInstance.getId(), "kermit", IdentityLinkType.PARTICIPANT);

this.expectException.expect(FlowableIllegalArgumentException.class);
this.expectException.expectMessage("involvedUser is null");

cmmnRuntimeService.createCaseInstanceQuery().involvedUser(null).count();
assertThatThrownBy(() -> cmmnRuntimeService.createCaseInstanceQuery().involvedUser(null))
.isInstanceOf(FlowableIllegalArgumentException.class)
.hasMessage("involvedUser is null");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static java.util.stream.Collectors.toMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;

import java.io.Serializable;
Expand Down Expand Up @@ -54,18 +55,13 @@
import org.flowable.variable.api.types.VariableType;
import org.flowable.variable.service.VariableServiceConfiguration;
import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
* @author Joram Barrez
*/
public class VariablesTest extends FlowableCmmnTestCase {

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
@CmmnDeployment
public void testGetVariables() {
Expand Down Expand Up @@ -437,19 +433,17 @@ public void testSetVariableOnRootCase() {
@Test
@CmmnDeployment(resources = "org/flowable/cmmn/test/task/CmmnTaskServiceTest.testOneHumanTaskCase.cmmn")
public void testSetVariableOnNonExistingCase() {
this.expectedException.expect(FlowableObjectNotFoundException.class);
this.expectedException.expectMessage("No case instance found for id NON-EXISTING-CASE");

cmmnRuntimeService.setVariable("NON-EXISTING-CASE", "varToUpdate", "newValue");
assertThatThrownBy(() -> cmmnRuntimeService.setVariable("NON-EXISTING-CASE", "varToUpdate", "newValue"))
.isInstanceOf(FlowableObjectNotFoundException.class)
.hasMessage("No case instance found for id NON-EXISTING-CASE");
}

@Test
@CmmnDeployment(resources = "org/flowable/cmmn/test/task/CmmnTaskServiceTest.testOneHumanTaskCase.cmmn")
public void testSetVariableWithoutName() {
this.expectedException.expect(FlowableIllegalArgumentException.class);
this.expectedException.expectMessage("variable name is null");

cmmnRuntimeService.setVariable("NON-EXISTING-CASE", null, "newValue");
assertThatThrownBy(() -> cmmnRuntimeService.setVariable("NON-EXISTING-CASE", null, "newValue"))
.isInstanceOf(FlowableIllegalArgumentException.class)
.hasMessage("variable name is null");
}

@Test
Expand Down Expand Up @@ -513,13 +507,13 @@ public void testSetVariablesOnRootCase() {
@Test
@CmmnDeployment(resources = "org/flowable/cmmn/test/task/CmmnTaskServiceTest.testOneHumanTaskCase.cmmn")
public void testSetVariablesOnNonExistingCase() {
this.expectedException.expect(FlowableObjectNotFoundException.class);
this.expectedException.expectMessage("No case instance found for id NON-EXISTING-CASE");
Map<String, Object> variables = Stream.of(new ImmutablePair<String, Object>("varToUpdate", "newValue")).collect(
toMap(Pair::getKey, Pair::getValue)
);

cmmnRuntimeService.setVariables("NON-EXISTING-CASE", variables);
assertThatThrownBy(() -> cmmnRuntimeService.setVariables("NON-EXISTING-CASE", variables))
.isInstanceOf(FlowableObjectNotFoundException.class)
.hasMessage("No case instance found for id NON-EXISTING-CASE");
}

@SuppressWarnings("unchecked")
Expand All @@ -531,10 +525,9 @@ public void testSetVariablesWithEmptyMap() {
.caseDefinitionKey("oneHumanTaskCase")
.start();

this.expectedException.expect(FlowableIllegalArgumentException.class);
this.expectedException.expectMessage("variables is empty");

cmmnRuntimeService.setVariables(caseInstance.getId(), Collections.EMPTY_MAP);
assertThatThrownBy(() -> cmmnRuntimeService.setVariables(caseInstance.getId(), Collections.EMPTY_MAP))
.isInstanceOf(FlowableIllegalArgumentException.class)
.hasMessage("variables is empty");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,14 @@
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
* @author Joram Barrez
* @author Christopher Welsch
*/
public class CmmnTaskServiceTest extends FlowableCmmnTestCase {

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
@CmmnDeployment
public void testOneHumanTaskCase() {
Expand Down Expand Up @@ -167,12 +162,12 @@ public void testOneHumanTaskVariableScopeExpressionCase() {
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
Task task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();

this.expectedException.expect(FlowableException.class);
this.expectedException.expectMessage("Error while evaluating expression: ${caseInstance.name}");
cmmnTaskService.complete(task.getId(), Collections.singletonMap(
assertThatThrownBy(() -> cmmnTaskService.complete(task.getId(), Collections.singletonMap(
"${caseInstance.name}", "newCaseName"
)
);
))
.isInstanceOf(FlowableException.class)
.hasMessageContaining("Error while evaluating expression: ${caseInstance.name}");
}

@Test
Expand All @@ -181,12 +176,12 @@ public void testOneHumanTaskCompleteSetCaseName() {
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder().caseDefinitionKey("oneHumanTaskCase").start();
Task task = cmmnTaskService.createTaskQuery().caseInstanceId(caseInstance.getId()).singleResult();

this.expectedException.expect(FlowableException.class);
this.expectedException.expectMessage("Error while evaluating expression: ${name}");
cmmnTaskService.complete(task.getId(), Collections.singletonMap(
assertThatThrownBy(() -> cmmnTaskService.complete(task.getId(), Collections.singletonMap(
"${name}", "newCaseName"
)
);
))
.isInstanceOf(FlowableException.class)
.hasMessageContaining("Error while evaluating expression: ${name}");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,14 @@
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.test.Deployment;
import org.flowable.variable.api.history.HistoricVariableInstance;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
* @author Yvo Swillens
* @author Filip Hrisafov
*/
public class MixedDeploymentTest extends AbstractFlowableDmnEngineConfiguratorTest {

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
@Deployment(resources = { "org/flowable/dmn/engine/test/deployment/oneDecisionTaskProcess.bpmn20.xml",
"org/flowable/dmn/engine/test/deployment/simple.dmn" })
Expand Down Expand Up @@ -155,40 +150,35 @@ public void testDecisionTaskExecutionWithGlobalTenantFallback() {
@Deployment(resources = { "org/flowable/dmn/engine/test/deployment/oneDecisionTaskProcess.bpmn20.xml" }
)
public void testDecisionTaskExecutionInAnotherDeploymentAndTenantDefaultBehavior() {
this.expectedException.expect(FlowableObjectNotFoundException.class);
this.expectedException.expectMessage("Process definition with key 'oneDecisionTaskProcess' and tenantId 'flowable' was not found");

deployDecisionAndAssertProcessExecuted();
assertThatThrownBy(this::deployDecisionAndAssertProcessExecuted)
.isInstanceOf(FlowableObjectNotFoundException.class)
.hasMessageContaining("Process definition with key 'oneDecisionTaskProcess' and tenantId 'flowable' was not found");
}

@Test
@Deployment(resources = { "org/flowable/dmn/engine/test/deployment/oneDecisionTaskProcessFallBackToDefaultTenantFalse.bpmn20.xml" },
tenantId = "flowable"
)
public void testDecisionTaskExecutionInAnotherDeploymentAndTenantFalse() {
this.expectedException.expect(FlowableException.class);
this.expectedException.expectMessage("No decision found for key: decision1");
this.expectedException.expectMessage("and tenant id: flowable");

deployDecisionAndAssertProcessExecuted();
assertThatThrownBy(this::deployDecisionAndAssertProcessExecuted)
.isInstanceOf(FlowableObjectNotFoundException.class)
.hasMessageContainingAll("No decision found for key: decision1", "and tenant id: flowable");
}

@Test
@Deployment(resources = { "org/flowable/dmn/engine/test/deployment/oneDecisionTaskProcessFallBackToDefaultTenantFalse.bpmn20.xml" },
tenantId = "flowable"
)
public void testDecisionTaskExecutionInAnotherDeploymentAndTenantFallbackFalseWithoutDeployment() {
this.expectedException.expect(FlowableException.class);
this.expectedException.expectMessage("No decision found for key: decision1");
this.expectedException.expectMessage("and tenant id: flowable");

deleteAllDmnDeployments();
org.flowable.engine.repository.Deployment deployment = repositoryService.createDeployment().
addClasspathResource("org/flowable/dmn/engine/test/deployment/simple.dmn").
tenantId("anotherTenant").
deploy();
try {
assertDmnProcessExecuted();
assertThatThrownBy(this::assertDmnProcessExecuted)
.isInstanceOf(FlowableObjectNotFoundException.class)
.hasMessageContainingAll("No decision found for key: decision1", "and tenant id: flowable");
} finally {
this.repositoryService.deleteDeployment(deployment.getId(), true);
deleteAllDmnDeployments();
Expand All @@ -200,15 +190,14 @@ public void testDecisionTaskExecutionInAnotherDeploymentAndTenantFallbackFalseWi
tenantId = "flowable"
)
public void testDecisionTaskExecutionInAnotherDeploymentAndTenantFallbackTrueWithoutDeployment() {
this.expectedException.expect(FlowableException.class);
this.expectedException.expectMessage("No decision found for key: decision1. There was also no fall back decision table found without tenant.");

org.flowable.engine.repository.Deployment deployment = repositoryService.createDeployment().
addClasspathResource("org/flowable/dmn/engine/test/deployment/simple.dmn").
tenantId("anotherTenant").
deploy();
try {
assertDmnProcessExecuted();
assertThatThrownBy(this::assertDmnProcessExecuted)
.isInstanceOf(FlowableObjectNotFoundException.class)
.hasMessageContaining("No decision found for key: decision1. There was also no fall back decision table found without tenant.");
} finally {
this.repositoryService.deleteDeployment(deployment.getId(), true);
deleteAllDmnDeployments();
Expand Down
Loading

0 comments on commit e5d93bd

Please sign in to comment.