aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-testing-harness
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2021-11-17 22:54:06 +0100
committersonartech <sonartech@sonarsource.com>2021-11-19 20:03:27 +0000
commita3d88ea27c35921647d7602755828ca73e15e865 (patch)
tree5626c38afab1ea00ab9897da431476c17b478bbe /sonar-testing-harness
parent92f482f2aa43e4aa36e0fda377d13b9dc3282ff9 (diff)
downloadsonarqube-a3d88ea27c35921647d7602755828ca73e15e865.tar.gz
sonarqube-a3d88ea27c35921647d7602755828ca73e15e865.zip
SONAR-15631 - Refactor UTs to stop using ExpectedException
Diffstat (limited to 'sonar-testing-harness')
-rw-r--r--sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java31
-rw-r--r--sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedMatcherTest.java21
2 files changed, 21 insertions, 31 deletions
diff --git a/sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java b/sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java
index 6f6fef8d359..6d984dacb81 100644
--- a/sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java
+++ b/sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java
@@ -22,19 +22,15 @@ package org.sonar.test;
import java.io.File;
import java.net.URL;
import org.junit.ComparisonFailure;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.fail;
import static org.sonar.test.JsonAssert.assertJson;
public class JsonAssertTest {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Test
public void isSimilarAs_strings() {
assertJson("{}").isSimilarTo("{}");
@@ -54,38 +50,35 @@ public class JsonAssertTest {
URL url1 = getClass().getResource("JsonAssertTest/sample1.json");
URL url2 = getClass().getResource("JsonAssertTest/sample2.json");
assertJson(url1).isSimilarTo(url1);
- expectedException.expect(AssertionError.class);
- assertJson(url1).isSimilarTo(url2);
+ assertThatThrownBy(() -> assertJson(url1).isSimilarTo(url2))
+ .isInstanceOf(AssertionError.class);
}
@Test
public void actual_can_be_superset_of_expected() {
assertJson("{\"foo\": \"bar\"}").isSimilarTo("{}");
- expectedException.expect(AssertionError.class);
- assertJson("{}").isSimilarTo("{\"foo\": \"bar\"}");
+ assertThatThrownBy(() -> assertJson("{}").isSimilarTo("{\"foo\": \"bar\"}"))
+ .isInstanceOf(AssertionError.class);
}
@Test
- public void fail_to_load_url() throws Exception {
- expectedException.expect(IllegalStateException.class);
-
- assertJson(new File("target/missing").toURI().toURL());
+ public void fail_to_load_url() {
+ assertThatThrownBy(() -> assertJson(new File("target/missing").toURI().toURL()))
+ .isInstanceOf(IllegalStateException.class);
}
@Test
public void enable_strict_order_of_arrays() {
- expectedException.expect(AssertionError.class);
-
- assertJson("[1,2]").withStrictArrayOrder().isSimilarTo("[2, 1]");
+ assertThatThrownBy(() -> assertJson("[1,2]").withStrictArrayOrder().isSimilarTo("[2, 1]"))
+ .isInstanceOf(AssertionError.class);
}
@Test
public void enable_strict_timezone() {
- expectedException.expect(AssertionError.class);
-
- assertJson("[\"2010-05-18T15:50:45+0100\"]").withStrictTimezone().isSimilarTo("[\"2010-05-18T16:50:45+0200\"]");
+ assertThatThrownBy(() -> assertJson("[\"2010-05-18T15:50:45+0100\"]").withStrictTimezone().isSimilarTo("[\"2010-05-18T16:50:45+0200\"]"))
+ .isInstanceOf(AssertionError.class);
}
@Test
diff --git a/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedMatcherTest.java b/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedMatcherTest.java
index 2979842f6d3..af7495200f8 100644
--- a/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedMatcherTest.java
+++ b/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedMatcherTest.java
@@ -19,31 +19,28 @@
*/
package org.sonar.test.i18n;
-import org.apache.commons.io.IOUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.SortedMap;
+import org.apache.commons.io.IOUtils;
+import org.junit.Before;
+import org.junit.Test;
import static junit.framework.TestCase.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
public class BundleSynchronizedMatcherTest {
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
BundleSynchronizedMatcher matcher;
@Before
@@ -141,8 +138,8 @@ public class BundleSynchronizedMatcherTest {
@Test
public void shouldFailToLoadUnexistingPropertiesFile() throws Exception {
- thrown.expect(IOException.class);
- BundleSynchronizedMatcher.loadProperties(new FileInputStream("foo.blabla"));
+ assertThatThrownBy(() -> BundleSynchronizedMatcher.loadProperties(new FileInputStream("foo.blabla")))
+ .isInstanceOf(IOException.class);
}
}