Migrate from ExpectedException rule to AssertJ
Replace ExpectedException JUnit rules with AssertJ exception assertions. Closes gh-14336
This commit is contained in:
@@ -19,9 +19,6 @@ package org.springframework.boot.configurationmetadata;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
@@ -34,9 +31,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public abstract class AbstractConfigurationMetadataTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
protected void assertSource(ConfigurationMetadataSource actual, String groupId,
|
||||
String type, String sourceType) {
|
||||
assertThat(actual).isNotNull();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConfigurationMetadataRepository}.
|
||||
@@ -34,8 +35,9 @@ public class ConfigurationMetadataRepositoryJsonBuilderTests
|
||||
|
||||
@Test
|
||||
public void nullResource() throws IOException {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
ConfigurationMetadataRepositoryJsonBuilder.create().withJsonResource(null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ConfigurationMetadataRepositoryJsonBuilder.create()
|
||||
.withJsonResource(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,11 +21,11 @@ import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.json.JSONException;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Tests for {@link JsonReader}.
|
||||
@@ -47,8 +47,8 @@ public class JsonReaderTests extends AbstractConfigurationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void invalidMetadata() throws IOException {
|
||||
this.thrown.expectCause(CoreMatchers.instanceOf(JSONException.class));
|
||||
readFor("invalid");
|
||||
assertThatIllegalStateException().isThrownBy(() -> readFor("invalid"))
|
||||
.withCauseInstanceOf(JSONException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user