Skip to content

Commit

Permalink
Replaces deprecated ExpectedException.none();
Browse files Browse the repository at this point in the history
  • Loading branch information
damianszczepanik committed Dec 31, 2023
1 parent 00c36c5 commit 3073536
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 125 deletions.
14 changes: 5 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pl.damianszczepanik</groupId>
<artifactId>silencio</artifactId>
Expand All @@ -8,13 +9,7 @@
<url>https://github.com/damianszczepanik/silencio</url>

<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>
<maven.compile.encoding>UTF-8</maven.compile.encoding>

<powermock.version>1.7.4</powermock.version>
<commons-io.version>2.14.0</commons-io.version>

<test.integration.pattern>**/*IntegrationTest*.java</test.integration.pattern>

Expand Down Expand Up @@ -44,6 +39,7 @@
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
</scm>

<ciManagement>
<system>GitHub Actions</system>
<url>https://github.com/damianszczepanik/silencio/actions</url>
Expand Down Expand Up @@ -244,7 +240,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<version>3.25.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -280,7 +276,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.combinatoricslib</groupId>
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/pl/szczepanik/silencio/GenericTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
import java.io.Writer;

import org.junit.After;
import org.junit.Rule;
import org.junit.rules.ExpectedException;

/**
* @author Damian Szczepanik (damianszczepanik@github)
*/
public abstract class GenericTest {

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

protected Writer output;
protected Reader input;

Expand Down
7 changes: 4 additions & 3 deletions src/test/java/pl/szczepanik/silencio/api/FormatTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.szczepanik.silencio.api;

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

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
Expand Down Expand Up @@ -33,9 +34,9 @@ public void shouldNotAllowForEmptyName() {
String emptyName = StringUtils.EMPTY;

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("Name of the format must not be empty!");
new StubFormat(emptyName);
assertThatThrownBy(() -> new StubFormat(emptyName))
.isInstanceOf(IntegrityException.class)
.hasMessage("Name of the format must not be empty!");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.szczepanik.silencio.converters;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;

Expand Down Expand Up @@ -57,9 +58,9 @@ public void shouldFailWhenServerReturnsInvalidPage() throws IOException {
.thenReturn(INVALID_HTML_PAGE);

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("Could not find header pattern for page: " + INVALID_HTML_PAGE);
processor.process();
assertThatThrownBy(() -> processor.process())
.isInstanceOf(IntegrityException.class)
.hasMessage("Could not find header pattern for page: " + INVALID_HTML_PAGE);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.szczepanik.silencio.core;

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

import org.junit.Test;

import pl.szczepanik.silencio.GenericTest;
import pl.szczepanik.silencio.api.Converter;
import pl.szczepanik.silencio.api.Format;
Expand All @@ -20,7 +20,7 @@ public class AbstractProcessorTest extends GenericTest {
public void shouldReturnPassedFormat() {

// given
Converter[] converters = { new StubConverter() };
Converter[] converters = {new StubConverter()};
Format format = Format.PROPERTIES;

// when
Expand All @@ -34,15 +34,15 @@ public void shouldReturnPassedFormat() {
public void shouldFailWhenBuildFromEmptyFormat() {

// given
Converter[] converters = { new StubConverter() };
Converter[] converters = {new StubConverter()};

// when
Format format = null;

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("Format must not be null!");
new StubProcessor(format, converters);
assertThatThrownBy(() -> new StubProcessor(format, converters))
.isInstanceOf(IntegrityException.class)
.hasMessage("Format must not be null!");
}

@Test
Expand All @@ -53,9 +53,9 @@ public void shouldFailWhenBuildFromNullConfiguration() {
AbstractProcessor processor = new StubProcessor(format);

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("Configuration must not be null!");
processor.setConfiguration(null);
assertThatThrownBy(() -> processor.setConfiguration(null))
.isInstanceOf(IntegrityException.class)
.hasMessage("Configuration must not be null!");
}

@Test
Expand All @@ -66,9 +66,9 @@ public void shouldFailWhenBuildFromEmptyConverter() {
Converter[] converter = {};

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("Array with Converters must not be empty!");
new StubProcessor(format, converter);
assertThatThrownBy(() -> new StubProcessor(format, converter))
.isInstanceOf(IntegrityException.class)
.hasMessage("Array with Converters must not be empty!");
}

@Test
Expand All @@ -81,8 +81,8 @@ public void shouldFailOnProcessWhenConvertersAreNotSet() {
AbstractProcessor processor = new StubProcessor(format);

// then
thrown.expect(ProcessorException.class);
thrown.expectMessage("This operation is not allowed for this state: CREATED");
processor.process();
assertThatThrownBy(() -> processor.process())
.isInstanceOf(ProcessorException.class)
.hasMessage("This operation is not allowed for this state: CREATED");
}
}
7 changes: 4 additions & 3 deletions src/test/java/pl/szczepanik/silencio/core/BuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


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

import java.util.List;

Expand Down Expand Up @@ -145,9 +146,9 @@ public void shouldFailWhenPassingInvalidFormat() {
Builder builder = new Builder(format);

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("Unsupported format: " + format.getName());
builder.build();
assertThatThrownBy(() -> builder.build())
.isInstanceOf(IntegrityException.class)
.hasMessage("Unsupported format: " + format.getName());
}

@Test
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/pl/szczepanik/silencio/core/ConfigurationTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.szczepanik.silencio.core;

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

import org.junit.Test;

import pl.szczepanik.silencio.GenericTest;
import pl.szczepanik.silencio.decisions.PositiveDecision;
import pl.szczepanik.silencio.stubs.StubConverter;
Expand All @@ -17,7 +17,7 @@ public class ConfigurationTest extends GenericTest {
public void shouldReturnPassedExecutions() {

// given
Execution[] executions = { new Execution(new PositiveDecision(), new StubConverter()) };
Execution[] executions = {new Execution(new PositiveDecision(), new StubConverter())};

// when
Configuration configuration = new Configuration(executions);
Expand All @@ -33,8 +33,8 @@ public void shouldFailWhenPassingEmtptyExecution() {
Execution[] executors = {};

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("Executions must not be empty!");
new Configuration(executors);
assertThatThrownBy(() -> new Configuration(executors))
.isInstanceOf(IntegrityException.class)
.hasMessage("Executions must not be empty!");
}
}
26 changes: 13 additions & 13 deletions src/test/java/pl/szczepanik/silencio/core/ExecutionTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.szczepanik.silencio.core;

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

import org.junit.Test;

import pl.szczepanik.silencio.GenericTest;
import pl.szczepanik.silencio.api.Converter;
import pl.szczepanik.silencio.api.Decision;
Expand Down Expand Up @@ -39,9 +39,9 @@ public void shouldFailWhenPassingEmtptyDecisions() {
Converter[] converters = { new BlankConverter() };

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("Array with Decisions must not be empty!");
new Execution(decisions, converters);
assertThatThrownBy(() -> new Execution(decisions, converters))
.isInstanceOf(IntegrityException.class)
.hasMessage("Array with Decisions must not be empty!");
}

@Test
Expand All @@ -52,9 +52,9 @@ public void shouldFailWhenPassingNullDecisions() {
Converter[] converters = { new BlankConverter() };

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("None of passed Decision can be null!");
new Execution(decisions, converters);
assertThatThrownBy(() -> new Execution(decisions, converters))
.isInstanceOf(IntegrityException.class)
.hasMessage("None of passed Decision can be null!");
}

@Test
Expand All @@ -65,9 +65,9 @@ public void shouldFailWhenPassingEmtptyConverter() {
Converter[] converters = {};

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("Array with Converters must not be empty!");
new Execution(decisions, converters);
assertThatThrownBy(() -> new Execution(decisions, converters))
.isInstanceOf(IntegrityException.class)
.hasMessage("Array with Converters must not be empty!");
}

@Test
Expand All @@ -78,8 +78,8 @@ public void shouldFailWhenPassingNullConverter() {
Converter[] converters = { null };

// then
thrown.expect(IntegrityException.class);
thrown.expectMessage("None of passed Converter can be null!");
new Execution(decisions, converters);
assertThatThrownBy(() -> new Execution(decisions, converters))
.isInstanceOf(IntegrityException.class)
.hasMessage("None of passed Converter can be null!");
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.szczepanik.silencio.core;

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

import org.junit.Test;

import pl.szczepanik.silencio.GenericTest;

/**
Expand All @@ -18,9 +18,9 @@ public void shouldNotAllowToValidateProcessInCreatedState() {
ProcessorStateMachine machine = new ProcessorStateMachine();

// then
thrown.expect(ProcessorException.class);
thrown.expectMessage("This operation is not allowed for this state: CREATED");
machine.validateProcess();
assertThatThrownBy(() -> machine.validateProcess())
.isInstanceOf(ProcessorException.class)
.hasMessage("This operation is not allowed for this state: CREATED");
}

@Test
Expand All @@ -43,9 +43,9 @@ public void shouldNotAllowToValidateWriteInCreatedState() {
ProcessorStateMachine machine = new ProcessorStateMachine();

// then
thrown.expect(ProcessorException.class);
thrown.expectMessage("This operation is not allowed for this state: CREATED");
machine.validateWrite();
assertThatThrownBy(() -> machine.validateWrite())
.isInstanceOf(ProcessorException.class)
.hasMessage("This operation is not allowed for this state: CREATED");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.szczepanik.silencio.diagnostics;

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

import org.junit.Test;

import pl.szczepanik.silencio.GenericTest;
import pl.szczepanik.silencio.api.Converter;
import pl.szczepanik.silencio.api.Format;
Expand All @@ -21,11 +21,12 @@ public class ProcessorSmokeCheckerTest extends GenericTest {
public void shouldPassWithStubProcessor() {

// given
StubProcessor processor = new StubProcessor(Format.JSON, new Converter[]{new StubConverter()});
StubProcessor processor = new StubProcessor(Format.JSON, new Converter[] { new StubConverter() });
ProcessorSmokeChecker processorChecker = new ProcessorSmokeChecker(processor);

// when & then
assertThatNoException().isThrownBy(() -> processorChecker.validateWithAllCombinations(""));
assertThatNoException()
.isThrownBy(() -> processorChecker.validateWithAllCombinations(""));
}

@Test
Expand All @@ -35,12 +36,12 @@ public void shouldThrowProcessorExceptionWhenValidationFails() {

// given
AbstractProcessorCrashOnRealProcess processor = new AbstractProcessorCrashOnRealProcess(Format.XML,
new Converter[]{new StubConverter()}, errorMessage);
new Converter[] { new StubConverter() }, errorMessage);
ProcessorSmokeChecker processorChecker = new ProcessorSmokeChecker(processor);

// then
thrown.expect(ProcessorException.class);
thrown.expectMessage(errorMessage);
processorChecker.validateWithAllCombinations("");
assertThatThrownBy(() -> processorChecker.validateWithAllCombinations(""))
.isInstanceOf(ProcessorException.class)
.hasMessage(errorMessage);
}
}
Loading

0 comments on commit 3073536

Please sign in to comment.