diff --git a/pom.xml b/pom.xml index 8980116..d142d41 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 pl.damianszczepanik silencio @@ -8,13 +9,7 @@ https://github.com/damianszczepanik/silencio - UTF-8 - UTF-8 - UTF-8 - UTF-8 - 1.7.4 - 2.14.0 **/*IntegrationTest*.java @@ -44,6 +39,7 @@ https://github.com/${gitHubRepo} ${scmTag} + GitHub Actions https://github.com/damianszczepanik/silencio/actions @@ -244,7 +240,7 @@ org.assertj assertj-core - 3.24.2 + 3.25.0 test @@ -280,7 +276,7 @@ commons-io commons-io - ${commons-io.version} + 2.15.1 com.googlecode.combinatoricslib diff --git a/src/test/java/pl/szczepanik/silencio/GenericTest.java b/src/test/java/pl/szczepanik/silencio/GenericTest.java index 479ea35..292c50c 100644 --- a/src/test/java/pl/szczepanik/silencio/GenericTest.java +++ b/src/test/java/pl/szczepanik/silencio/GenericTest.java @@ -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; diff --git a/src/test/java/pl/szczepanik/silencio/api/FormatTest.java b/src/test/java/pl/szczepanik/silencio/api/FormatTest.java index f59bfb0..4083a09 100644 --- a/src/test/java/pl/szczepanik/silencio/api/FormatTest.java +++ b/src/test/java/pl/szczepanik/silencio/api/FormatTest.java @@ -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; @@ -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 diff --git a/src/test/java/pl/szczepanik/silencio/converters/WikipediaConverterTest.java b/src/test/java/pl/szczepanik/silencio/converters/WikipediaConverterTest.java index ceaeeae..596fd7e 100644 --- a/src/test/java/pl/szczepanik/silencio/converters/WikipediaConverterTest.java +++ b/src/test/java/pl/szczepanik/silencio/converters/WikipediaConverterTest.java @@ -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; @@ -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 diff --git a/src/test/java/pl/szczepanik/silencio/core/AbstractProcessorTest.java b/src/test/java/pl/szczepanik/silencio/core/AbstractProcessorTest.java index 1cffe19..73dfc2f 100644 --- a/src/test/java/pl/szczepanik/silencio/core/AbstractProcessorTest.java +++ b/src/test/java/pl/szczepanik/silencio/core/AbstractProcessorTest.java @@ -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; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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"); } } diff --git a/src/test/java/pl/szczepanik/silencio/core/BuilderTest.java b/src/test/java/pl/szczepanik/silencio/core/BuilderTest.java index 0f90e0a..b11909b 100644 --- a/src/test/java/pl/szczepanik/silencio/core/BuilderTest.java +++ b/src/test/java/pl/szczepanik/silencio/core/BuilderTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.List; @@ -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 diff --git a/src/test/java/pl/szczepanik/silencio/core/ConfigurationTest.java b/src/test/java/pl/szczepanik/silencio/core/ConfigurationTest.java index 7c46797..cf9cead 100644 --- a/src/test/java/pl/szczepanik/silencio/core/ConfigurationTest.java +++ b/src/test/java/pl/szczepanik/silencio/core/ConfigurationTest.java @@ -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; @@ -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); @@ -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!"); } } diff --git a/src/test/java/pl/szczepanik/silencio/core/ExecutionTest.java b/src/test/java/pl/szczepanik/silencio/core/ExecutionTest.java index ae20bea..a714a36 100644 --- a/src/test/java/pl/szczepanik/silencio/core/ExecutionTest.java +++ b/src/test/java/pl/szczepanik/silencio/core/ExecutionTest.java @@ -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; @@ -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 @@ -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 @@ -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 @@ -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!"); } } diff --git a/src/test/java/pl/szczepanik/silencio/core/ProcessorStateMachineTest.java b/src/test/java/pl/szczepanik/silencio/core/ProcessorStateMachineTest.java index 14a351e..168771c 100644 --- a/src/test/java/pl/szczepanik/silencio/core/ProcessorStateMachineTest.java +++ b/src/test/java/pl/szczepanik/silencio/core/ProcessorStateMachineTest.java @@ -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; /** @@ -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 @@ -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 diff --git a/src/test/java/pl/szczepanik/silencio/diagnostics/ProcessorSmokeCheckerTest.java b/src/test/java/pl/szczepanik/silencio/diagnostics/ProcessorSmokeCheckerTest.java index e307126..6eec7e2 100644 --- a/src/test/java/pl/szczepanik/silencio/diagnostics/ProcessorSmokeCheckerTest.java +++ b/src/test/java/pl/szczepanik/silencio/diagnostics/ProcessorSmokeCheckerTest.java @@ -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; @@ -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 @@ -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); } } diff --git a/src/test/java/pl/szczepanik/silencio/processors/JSONProcessorTest.java b/src/test/java/pl/szczepanik/silencio/processors/JSONProcessorTest.java index f808102..fdae8dd 100644 --- a/src/test/java/pl/szczepanik/silencio/processors/JSONProcessorTest.java +++ b/src/test/java/pl/szczepanik/silencio/processors/JSONProcessorTest.java @@ -1,7 +1,7 @@ package pl.szczepanik.silencio.processors; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.core.StringContains.containsString; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.StringWriter; @@ -64,9 +64,9 @@ public void shouldFailWhenLoadingInvalidJSONFile() { processor.setConfiguration(new Configuration(execution)); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage(containsString("Unexpected character")); - processor.load(input); + assertThatThrownBy(() -> processor.load(input)) + .isInstanceOf(ProcessorException.class) + .hasMessageContaining("Unexpected character"); } @Test @@ -86,8 +86,8 @@ public void shouldFailWhenWritingToInvalidWriter() { processor.realProcess(); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage(errorMessage); - processor.realWrite(output); + assertThatThrownBy(() -> processor.realWrite(output)) + .isInstanceOf(ProcessorException.class) + .hasMessageContaining(errorMessage); } } \ No newline at end of file diff --git a/src/test/java/pl/szczepanik/silencio/processors/PropertiesProcessorTest.java b/src/test/java/pl/szczepanik/silencio/processors/PropertiesProcessorTest.java index 0c9550d..5170fd6 100644 --- a/src/test/java/pl/szczepanik/silencio/processors/PropertiesProcessorTest.java +++ b/src/test/java/pl/szczepanik/silencio/processors/PropertiesProcessorTest.java @@ -1,7 +1,7 @@ package pl.szczepanik.silencio.processors; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.core.StringContains.containsString; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; import java.io.Reader; @@ -67,9 +67,9 @@ public void shouldFailWhenLoadingInvalidPropertiesFile() { PropertiesProcessor processor = new PropertiesProcessor(); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage(containsString("Malformed \\uxxxx encoding.")); - processor.realLoad(input); + assertThatThrownBy(() -> processor.realLoad(input)) + .isInstanceOf(ProcessorException.class) + .hasMessageContaining("Malformed \\uxxxx encoding."); } @Test @@ -99,9 +99,9 @@ public void shouldFailOnRealWrite() { Writer writer = new WriterCrashOnWrite(errorMessage); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage(errorMessage); - processor.realWrite(writer); + assertThatThrownBy(() -> processor.realWrite(writer)) + .isInstanceOf(ProcessorException.class) + .hasMessageContaining(errorMessage); } @Test diff --git a/src/test/java/pl/szczepanik/silencio/processors/XMLProcessorTest.java b/src/test/java/pl/szczepanik/silencio/processors/XMLProcessorTest.java index 62daf71..acc5407 100644 --- a/src/test/java/pl/szczepanik/silencio/processors/XMLProcessorTest.java +++ b/src/test/java/pl/szczepanik/silencio/processors/XMLProcessorTest.java @@ -1,7 +1,7 @@ package pl.szczepanik.silencio.processors; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.core.StringContains.containsString; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.StringWriter; @@ -64,13 +64,13 @@ public void shouldFailWhenLoadingInvalidJSONFile() { processor.setConfiguration(new Configuration(execution)); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage(containsString("XML document structures must start and end within the same entity")); - processor.load(input); + assertThatThrownBy(() -> processor.load(input)) + .isInstanceOf(ProcessorException.class) + .hasMessageContaining("XML document structures must start and end within the same entity"); } @Test - public void shouldFailWhenWrittingToInvalidWriter() { + public void shouldFailWhenWritingToInvalidWriter() { final String errorMessage = "Don't write into this writer!"; @@ -86,8 +86,8 @@ public void shouldFailWhenWrittingToInvalidWriter() { processor.realProcess(); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage(errorMessage); - processor.realWrite(output); + assertThatThrownBy(() -> processor.realWrite(output)) + .isInstanceOf(ProcessorException.class) + .hasMessageContaining(errorMessage); } } \ No newline at end of file diff --git a/src/test/java/pl/szczepanik/silencio/processors/YAMLProcessorTest.java b/src/test/java/pl/szczepanik/silencio/processors/YAMLProcessorTest.java index 38bc177..3484c58 100644 --- a/src/test/java/pl/szczepanik/silencio/processors/YAMLProcessorTest.java +++ b/src/test/java/pl/szczepanik/silencio/processors/YAMLProcessorTest.java @@ -1,7 +1,7 @@ package pl.szczepanik.silencio.processors; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.core.StringContains.containsString; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.StringWriter; @@ -63,9 +63,9 @@ public void shouldFailWhenLoadingInvalidYAMLFile() { processor.setConfiguration(new Configuration(execution)); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage(containsString("Cannot construct instance of")); - processor.load(input); + assertThatThrownBy(() -> processor.load(input)) + .isInstanceOf(ProcessorException.class) + .hasMessageContaining("Cannot construct instance of"); } @Test @@ -85,8 +85,8 @@ public void shouldFailWhenWritingToInvalidWriter() { processor.realProcess(); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage(errorMessage); - processor.realWrite(output); + assertThatThrownBy(() -> processor.realWrite(output)) + .isInstanceOf(ProcessorException.class) + .hasMessageContaining(errorMessage); } } \ No newline at end of file diff --git a/src/test/java/pl/szczepanik/silencio/processors/visitors/AbstractVisitorTest.java b/src/test/java/pl/szczepanik/silencio/processors/visitors/AbstractVisitorTest.java index 9d59cf5..a86cf08 100644 --- a/src/test/java/pl/szczepanik/silencio/processors/visitors/AbstractVisitorTest.java +++ b/src/test/java/pl/szczepanik/silencio/processors/visitors/AbstractVisitorTest.java @@ -1,7 +1,8 @@ package pl.szczepanik.silencio.processors.visitors; -import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.junit.Test; import pl.szczepanik.silencio.GenericTest; import pl.szczepanik.silencio.core.Key; import pl.szczepanik.silencio.core.Value; @@ -21,8 +22,8 @@ public void shouldFailWhenPassingValueToProcessValue() { AbstractVisitor visitor = new StubAbstractVisitor(); // then - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage(AbstractVisitor.EXCEPTION_MESSAGE_INVALID_VALUE_TYPE); - visitor.processValue(key, value); + assertThatThrownBy(() -> visitor.processValue(key, value)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(AbstractVisitor.EXCEPTION_MESSAGE_INVALID_VALUE_TYPE); } } diff --git a/src/test/java/pl/szczepanik/silencio/processors/visitors/JSONVisitorTest.java b/src/test/java/pl/szczepanik/silencio/processors/visitors/JSONVisitorTest.java index e8ebf4b..12ef2d3 100644 --- a/src/test/java/pl/szczepanik/silencio/processors/visitors/JSONVisitorTest.java +++ b/src/test/java/pl/szczepanik/silencio/processors/visitors/JSONVisitorTest.java @@ -1,6 +1,7 @@ package pl.szczepanik.silencio.processors.visitors; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; import java.util.Map; @@ -31,9 +32,9 @@ public void shouldReportExceptionOnUnsupportedModel() throws Exception { JSONVisitor parser = new JSONVisitor(); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage("Unknown type of the key: " + value.getClass().getName()); - Whitebox.invokeMethod(parser, "processComplex", key, value); + assertThatThrownBy(() -> Whitebox.invokeMethod(parser, "processComplex", key, value)) + .isInstanceOf(ProcessorException.class) + .hasMessage("Unknown type of the key: " + value.getClass().getName()); } @Test diff --git a/src/test/java/pl/szczepanik/silencio/processors/visitors/XMLVisitorTest.java b/src/test/java/pl/szczepanik/silencio/processors/visitors/XMLVisitorTest.java index d76555d..875d5d2 100644 --- a/src/test/java/pl/szczepanik/silencio/processors/visitors/XMLVisitorTest.java +++ b/src/test/java/pl/szczepanik/silencio/processors/visitors/XMLVisitorTest.java @@ -1,6 +1,7 @@ package pl.szczepanik.silencio.processors.visitors; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.powermock.api.mockito.PowerMockito.mock; import static org.powermock.api.mockito.PowerMockito.when; @@ -31,7 +32,7 @@ * @author Damian Szczepanik (damianszczepanik@github) */ @RunWith(PowerMockRunner.class) -@PrepareForTest(value = {Node.class}) +@PrepareForTest(value = { Node.class }) @PowerMockIgnore("jdk.internal.reflect.*") public class XMLVisitorTest extends GenericTest { @@ -44,9 +45,9 @@ public void shouldReportExceptionOnUnsupportedModel() throws Exception { JSONVisitor parserr = new JSONVisitor(); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage("Unknown type of the key: " + value.getClass().getName()); - Whitebox.invokeMethod(parserr, "processComplex", key, value); + assertThatThrownBy(() -> Whitebox.invokeMethod(parserr, "processComplex", key, value)) + .isInstanceOf(ProcessorException.class) + .hasMessage("Unknown type of the key: " + value.getClass().getName()); } @Test @@ -88,9 +89,9 @@ public void shouldFailOnInvalidNodeType() throws Exception { when(node.getNodeValue()).thenReturn(nodeValue); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage(String.format(XMLVisitor.EXCEPTION_MESSAGE_NODE_TYPE_UNSUPPORTED, invalidNodeType, - nodeName, nodeValue)); - Whitebox.invokeMethod(visitor, "processNode", node); + assertThatThrownBy(() -> Whitebox.invokeMethod(visitor, "processNode", node)) + .isInstanceOf(ProcessorException.class) + .hasMessage((String.format(XMLVisitor.EXCEPTION_MESSAGE_NODE_TYPE_UNSUPPORTED, invalidNodeType, + nodeName, nodeValue))); } } diff --git a/src/test/java/pl/szczepanik/silencio/processors/visitors/YAMLVisitorTest.java b/src/test/java/pl/szczepanik/silencio/processors/visitors/YAMLVisitorTest.java index a2b3a6a..d6588b6 100644 --- a/src/test/java/pl/szczepanik/silencio/processors/visitors/YAMLVisitorTest.java +++ b/src/test/java/pl/szczepanik/silencio/processors/visitors/YAMLVisitorTest.java @@ -1,6 +1,7 @@ package pl.szczepanik.silencio.processors.visitors; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; import java.util.Map; @@ -32,9 +33,9 @@ public void shouldReportExceptionOnUnsupportedModel() throws Exception { YAMLVisitor parser = new YAMLVisitor(); // then - thrown.expect(ProcessorException.class); - thrown.expectMessage("Unknown type of the key: " + value.getClass().getName()); - Whitebox.invokeMethod(parser, "processComplex", key, value); + assertThatThrownBy(() -> Whitebox.invokeMethod(parser, "processComplex", key, value)) + .isInstanceOf(ProcessorException.class) + .hasMessage("Unknown type of the key: " + value.getClass().getName()); } @Test diff --git a/src/test/java/pl/szczepanik/silencio/utils/IOUtilityTest.java b/src/test/java/pl/szczepanik/silencio/utils/IOUtilityTest.java index b9576df..e170c56 100644 --- a/src/test/java/pl/szczepanik/silencio/utils/IOUtilityTest.java +++ b/src/test/java/pl/szczepanik/silencio/utils/IOUtilityTest.java @@ -1,6 +1,7 @@ package pl.szczepanik.silencio.utils; 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; @@ -34,7 +35,7 @@ public void shouldReturnWholeHtmlPage() throws Exception { // given mockStatic(IOUtils.class); when(IOUtils.toString(new URL(URL_ADDRESS), StandardCharsets.UTF_8)) - .thenReturn(INVALID_HTML_PAGE); + .thenReturn(INVALID_HTML_PAGE); // then String page = IOUtility.urlToString(new URL(URL_ADDRESS)); @@ -50,12 +51,12 @@ public void shouldFailOnIOException() throws Exception { // when mockStatic(IOUtils.class); when(IOUtils.toString(new URL(URL_ADDRESS), StandardCharsets.UTF_8)) - .thenThrow(new IOException(errorMessage)); + .thenThrow(new IOException(errorMessage)); // then - thrown.expect(IntegrityException.class); - thrown.expectMessage(errorMessage); - IOUtility.urlToString(new URL(URL_ADDRESS)); + assertThatThrownBy(() -> IOUtility.urlToString(new URL(URL_ADDRESS))) + .isInstanceOf(IntegrityException.class) + .hasMessage(errorMessage); } @Test @@ -65,8 +66,8 @@ public void shouldFailWhenUrlIsNotValid() { String invalidURL = "wwww.my@funpage"; // then - thrown.expect(IntegrityException.class); - thrown.expectMessage("no protocol: " + invalidURL); - IOUtility.createURL(invalidURL); + assertThatThrownBy(() -> IOUtility.createURL(invalidURL)) + .isInstanceOf(IntegrityException.class) + .hasMessageContaining("no protocol: " + invalidURL); } }