Migrate from ExpectedException rule to AssertJ
Replace ExpectedException JUnit rules with AssertJ exception assertions. Closes gh-14336
This commit is contained in:
@@ -16,15 +16,14 @@
|
||||
|
||||
package org.springframework.boot.test.context;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.test.context.example.ExampleConfig;
|
||||
import org.springframework.boot.test.context.example.scan.Example;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link AnnotatedClassFinder}.
|
||||
@@ -33,24 +32,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class AnnotatedClassFinderTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private AnnotatedClassFinder finder = new AnnotatedClassFinder(
|
||||
SpringBootConfiguration.class);
|
||||
|
||||
@Test
|
||||
public void findFromClassWhenSourceIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Source must not be null");
|
||||
this.finder.findFromClass((Class<?>) null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.finder.findFromClass((Class<?>) null))
|
||||
.withMessageContaining("Source must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findFromPackageWhenSourceIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Source must not be null");
|
||||
this.finder.findFromPackage((String) null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.finder.findFromPackage((String) null))
|
||||
.withMessageContaining("Source must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,11 +16,10 @@
|
||||
|
||||
package org.springframework.boot.test.context;
|
||||
|
||||
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.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link FilteredClassLoader}.
|
||||
@@ -29,25 +28,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class FilteredClassLoaderTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void loadClassWhenFilteredOnPackageShouldThrowClassNotFound()
|
||||
throws Exception {
|
||||
FilteredClassLoader classLoader = new FilteredClassLoader(
|
||||
FilteredClassLoaderTests.class.getPackage().getName());
|
||||
this.thrown.expect(ClassNotFoundException.class);
|
||||
classLoader.loadClass(getClass().getName());
|
||||
classLoader.close();
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(
|
||||
FilteredClassLoaderTests.class.getPackage().getName())) {
|
||||
assertThatExceptionOfType(ClassNotFoundException.class)
|
||||
.isThrownBy(() -> classLoader.loadClass(getClass().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadClassWhenFilteredOnClassShouldThrowClassNotFound() throws Exception {
|
||||
try (FilteredClassLoader classLoader = new FilteredClassLoader(
|
||||
FilteredClassLoaderTests.class)) {
|
||||
this.thrown.expect(ClassNotFoundException.class);
|
||||
classLoader.loadClass(getClass().getName());
|
||||
assertThatExceptionOfType(ClassNotFoundException.class)
|
||||
.isThrownBy(() -> classLoader.loadClass(getClass().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -19,9 +19,7 @@ package org.springframework.boot.test.context;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -31,6 +29,7 @@ import org.springframework.test.context.ContextCustomizer;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -41,9 +40,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class ImportsContextCustomizerFactoryTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private ImportsContextCustomizerFactory factory = new ImportsContextCustomizerFactory();
|
||||
|
||||
@Test
|
||||
@@ -86,9 +82,10 @@ public class ImportsContextCustomizerFactoryTests {
|
||||
|
||||
@Test
|
||||
public void getContextCustomizerWhenClassHasBeanMethodsShouldThrowException() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Test classes cannot include @Bean methods");
|
||||
this.factory.createContextCustomizer(TestWithImportAndBeanMethod.class, null);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.factory
|
||||
.createContextCustomizer(TestWithImportAndBeanMethod.class, null))
|
||||
.withMessageContaining("Test classes cannot include @Bean methods");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.context;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
@@ -29,6 +27,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringBootTest} configured with specific classes.
|
||||
@@ -40,17 +39,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@SpringBootTest(classes = SpringBootTestWithClassesIntegrationTests.Config.class)
|
||||
public class SpringBootTestWithClassesIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void injectsOnlyConfig() {
|
||||
assertThat(this.context.getBean(Config.class)).isNotNull();
|
||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
||||
this.context.getBean(AdditionalConfig.class);
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.context.getBean(AdditionalConfig.class));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.context;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
@@ -30,6 +28,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringBootTest} configured with {@link ContextConfiguration}.
|
||||
@@ -42,17 +41,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ContextConfiguration(classes = SpringBootTestWithContextConfigurationIntegrationTests.Config.class)
|
||||
public class SpringBootTestWithContextConfigurationIntegrationTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void injectsOnlyConfig() {
|
||||
assertThat(this.context.getBean(Config.class)).isNotNull();
|
||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
||||
this.context.getBean(AdditionalConfig.class);
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> this.context.getBean(AdditionalConfig.class));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -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.
|
||||
@@ -19,9 +19,7 @@ package org.springframework.boot.test.context.assertj;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@@ -30,7 +28,8 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
@@ -41,9 +40,6 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class ApplicationContextAssertProviderTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private ConfigurableApplicationContext mockContext;
|
||||
|
||||
@@ -65,43 +61,45 @@ public class ApplicationContextAssertProviderTests {
|
||||
|
||||
@Test
|
||||
public void getWhenTypeIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Type must not be null");
|
||||
ApplicationContextAssertProvider.get(null, ApplicationContext.class,
|
||||
this.mockContextSupplier);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(null,
|
||||
ApplicationContext.class, this.mockContextSupplier))
|
||||
.withMessageContaining("Type must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenTypeIsClassShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Type must not be null");
|
||||
ApplicationContextAssertProvider.get(null, ApplicationContext.class,
|
||||
this.mockContextSupplier);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(null,
|
||||
ApplicationContext.class, this.mockContextSupplier))
|
||||
.withMessageContaining("Type must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenContextTypeIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Type must be an interface");
|
||||
ApplicationContextAssertProvider.get(
|
||||
TestAssertProviderApplicationContextClass.class, ApplicationContext.class,
|
||||
this.mockContextSupplier);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(
|
||||
TestAssertProviderApplicationContextClass.class,
|
||||
ApplicationContext.class, this.mockContextSupplier))
|
||||
.withMessageContaining("Type must be an interface");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenContextTypeIsClassShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ContextType must not be null");
|
||||
ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
|
||||
null, this.mockContextSupplier);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(
|
||||
TestAssertProviderApplicationContext.class, null,
|
||||
this.mockContextSupplier))
|
||||
.withMessageContaining("ContextType must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhenSupplierIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ContextType must be an interface");
|
||||
ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
|
||||
StaticApplicationContext.class, this.mockContextSupplier);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ApplicationContextAssertProvider.get(
|
||||
TestAssertProviderApplicationContext.class,
|
||||
StaticApplicationContext.class, this.mockContextSupplier))
|
||||
.withMessageContaining("ContextType must be an interface");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,8 +116,8 @@ public class ApplicationContextAssertProviderTests {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(
|
||||
this.startupFailureSupplier);
|
||||
assertThat((Object) context).isNotNull();
|
||||
expectStartupFailure();
|
||||
context.getBean("foo");
|
||||
assertThatIllegalStateException().isThrownBy(() -> context.getBean("foo"))
|
||||
.withCause(this.startupFailure).withMessageContaining("failed to start");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,8 +131,9 @@ public class ApplicationContextAssertProviderTests {
|
||||
public void getSourceContextWhenContextFailsShouldThrowException() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(
|
||||
this.startupFailureSupplier);
|
||||
expectStartupFailure();
|
||||
context.getSourceApplicationContext();
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> context.getSourceApplicationContext())
|
||||
.withCause(this.startupFailure).withMessageContaining("failed to start");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,8 +148,9 @@ public class ApplicationContextAssertProviderTests {
|
||||
public void getSourceContextOfTypeWhenContextFailsToStartShouldThrowException() {
|
||||
ApplicationContextAssertProvider<ApplicationContext> context = get(
|
||||
this.startupFailureSupplier);
|
||||
expectStartupFailure();
|
||||
context.getSourceApplicationContext(ApplicationContext.class);
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
() -> context.getSourceApplicationContext(ApplicationContext.class))
|
||||
.withCause(this.startupFailure).withMessageContaining("failed to start");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -213,12 +213,6 @@ public class ApplicationContextAssertProviderTests {
|
||||
verify(this.mockContext).close();
|
||||
}
|
||||
|
||||
private void expectStartupFailure() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("failed to start");
|
||||
this.thrown.expectCause(equalTo(this.startupFailure));
|
||||
}
|
||||
|
||||
private ApplicationContextAssertProvider<ApplicationContext> get(
|
||||
Supplier<ApplicationContext> contextSupplier) {
|
||||
return ApplicationContextAssertProvider.get(
|
||||
|
||||
@@ -18,15 +18,15 @@ package org.springframework.boot.test.context.assertj;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.test.context.assertj.ApplicationContextAssert.Scope;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link ApplicationContextAssert}.
|
||||
@@ -36,9 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class ApplicationContextAssertTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private StaticApplicationContext parent;
|
||||
|
||||
private StaticApplicationContext context;
|
||||
@@ -60,9 +57,9 @@ public class ApplicationContextAssertTests {
|
||||
|
||||
@Test
|
||||
public void createWhenApplicationContextIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ApplicationContext must not be null");
|
||||
new ApplicationContextAssert<>(null, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ApplicationContextAssert<>(null, null))
|
||||
.withMessageContaining("ApplicationContext must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,17 +81,17 @@ public class ApplicationContextAssertTests {
|
||||
|
||||
@Test
|
||||
public void hasBeanWhenHasNoBeanShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("no such bean");
|
||||
assertThat(getAssert(this.context)).hasBean("foo");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).hasBean("foo"))
|
||||
.withMessageContaining("no such bean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasBeanWhenNotStartedShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(String
|
||||
.format("but context failed to start:%n java.lang.RuntimeException"));
|
||||
assertThat(getAssert(this.failure)).hasBean("foo");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).hasBean("foo"))
|
||||
.withMessageContaining(String.format(
|
||||
"but context failed to start:%n java.lang.RuntimeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,36 +102,36 @@ public class ApplicationContextAssertTests {
|
||||
|
||||
@Test
|
||||
public void hasSingleBeanWhenHasNoBeansShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("to have a single bean of type");
|
||||
assertThat(getAssert(this.context)).hasSingleBean(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(getAssert(this.context)).hasSingleBean(Foo.class))
|
||||
.withMessageContaining("to have a single bean of type");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasSingleBeanWhenHasMultipleShouldFail() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("but found:");
|
||||
assertThat(getAssert(this.context)).hasSingleBean(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(getAssert(this.context)).hasSingleBean(Foo.class))
|
||||
.withMessageContaining("but found:");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasSingleBeanWhenFailedToStartShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("to have a single bean of type");
|
||||
this.thrown.expectMessage(String
|
||||
.format("but context failed to start:%n java.lang.RuntimeException"));
|
||||
assertThat(getAssert(this.failure)).hasSingleBean(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(getAssert(this.failure)).hasSingleBean(Foo.class))
|
||||
.withMessageContaining("to have a single bean of type")
|
||||
.withMessageContaining(String.format(
|
||||
"but context failed to start:%n java.lang.RuntimeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasSingleBeanWhenInParentShouldFail() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("but found:");
|
||||
assertThat(getAssert(this.context)).hasSingleBean(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(getAssert(this.context)).hasSingleBean(Foo.class))
|
||||
.withMessageContaining("but found:");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,27 +148,27 @@ public class ApplicationContextAssertTests {
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfTypeWhenHasBeanOfTypeShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("but found");
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).doesNotHaveBean(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(getAssert(this.context)).doesNotHaveBean(Foo.class))
|
||||
.withMessageContaining("but found");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfTypeWhenFailedToStartShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("not to have any beans of type");
|
||||
this.thrown.expectMessage(String
|
||||
.format("but context failed to start:%n java.lang.RuntimeException"));
|
||||
assertThat(getAssert(this.failure)).doesNotHaveBean(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(getAssert(this.failure)).doesNotHaveBean(Foo.class))
|
||||
.withMessageContaining("not to have any beans of type")
|
||||
.withMessageContaining(String.format(
|
||||
"but context failed to start:%n java.lang.RuntimeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfTypeWhenInParentShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("but found");
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).doesNotHaveBean(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(getAssert(this.context)).doesNotHaveBean(Foo.class))
|
||||
.withMessageContaining("but found");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -188,18 +185,20 @@ public class ApplicationContextAssertTests {
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfNameWhenHasBeanOfTypeShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("but found");
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
assertThat(getAssert(this.context)).doesNotHaveBean("foo");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(
|
||||
() -> assertThat(getAssert(this.context)).doesNotHaveBean("foo"))
|
||||
.withMessageContaining("but found");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveBeanOfNameWhenFailedToStartShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("not to have any beans of name");
|
||||
this.thrown.expectMessage("failed to start");
|
||||
assertThat(getAssert(this.failure)).doesNotHaveBean("foo");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(
|
||||
() -> assertThat(getAssert(this.failure)).doesNotHaveBean("foo"))
|
||||
.withMessageContaining("not to have any beans of name")
|
||||
.withMessageContaining("failed to start");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -217,11 +216,12 @@ public class ApplicationContextAssertTests {
|
||||
|
||||
@Test
|
||||
public void getBeanNamesWhenFailedToStartShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("not to have any beans of name");
|
||||
this.thrown.expectMessage(String
|
||||
.format("but context failed to start:%n java.lang.RuntimeException"));
|
||||
assertThat(getAssert(this.failure)).doesNotHaveBean("foo");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(
|
||||
() -> assertThat(getAssert(this.failure)).doesNotHaveBean("foo"))
|
||||
.withMessageContaining("not to have any beans of name")
|
||||
.withMessageContaining(String.format(
|
||||
"but context failed to start:%n java.lang.RuntimeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -239,18 +239,18 @@ public class ApplicationContextAssertTests {
|
||||
public void getBeanOfTypeWhenHasMultipleBeansShouldFail() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("but found");
|
||||
assertThat(getAssert(this.context)).getBean(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).getBean(Foo.class))
|
||||
.withMessageContaining("but found");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfTypeWhenFailedToStartShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("to contain bean of type");
|
||||
this.thrown.expectMessage(String
|
||||
.format("but context failed to start:%n java.lang.RuntimeException"));
|
||||
assertThat(getAssert(this.failure)).getBean(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).getBean(Foo.class))
|
||||
.withMessageContaining("to contain bean of type")
|
||||
.withMessageContaining(String.format(
|
||||
"but context failed to start:%n java.lang.RuntimeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -270,9 +270,9 @@ public class ApplicationContextAssertTests {
|
||||
public void getBeanOfTypeWhenHasMultipleBeansIncludingParentShouldFail() {
|
||||
this.parent.registerSingleton("foo", Foo.class);
|
||||
this.context.registerSingleton("bar", Foo.class);
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("but found");
|
||||
assertThat(getAssert(this.context)).getBean(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).getBean(Foo.class))
|
||||
.withMessageContaining("but found");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -296,11 +296,11 @@ public class ApplicationContextAssertTests {
|
||||
|
||||
@Test
|
||||
public void getBeanOfNameWhenFailedToStartShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("to contain a bean of name");
|
||||
this.thrown.expectMessage(String
|
||||
.format("but context failed to start:%n java.lang.RuntimeException"));
|
||||
assertThat(getAssert(this.failure)).getBean("foo");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).getBean("foo"))
|
||||
.withMessageContaining("to contain a bean of name")
|
||||
.withMessageContaining(String.format(
|
||||
"but context failed to start:%n java.lang.RuntimeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -317,18 +317,19 @@ public class ApplicationContextAssertTests {
|
||||
@Test
|
||||
public void getBeanOfNameAndTypeWhenHasNoBeanOfNameButDifferentTypeShouldFail() {
|
||||
this.context.registerSingleton("foo", Foo.class);
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("of type");
|
||||
assertThat(getAssert(this.context)).getBean("foo", String.class);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(getAssert(this.context)).getBean("foo", String.class))
|
||||
.withMessageContaining("of type");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBeanOfNameAndTypeWhenFailedToStartShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("to contain a bean of name");
|
||||
this.thrown.expectMessage(String
|
||||
.format("but context failed to start:%n java.lang.RuntimeException"));
|
||||
assertThat(getAssert(this.failure)).getBean("foo", Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).getBean("foo",
|
||||
Foo.class))
|
||||
.withMessageContaining("to contain a bean of name")
|
||||
.withMessageContaining(String.format(
|
||||
"but context failed to start:%n java.lang.RuntimeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -346,11 +347,11 @@ public class ApplicationContextAssertTests {
|
||||
|
||||
@Test
|
||||
public void getBeansWhenFailedToStartShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("to get beans of type");
|
||||
this.thrown.expectMessage(String
|
||||
.format("but context failed to start:%n java.lang.RuntimeException"));
|
||||
assertThat(getAssert(this.failure)).getBeans(Foo.class);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).getBeans(Foo.class))
|
||||
.withMessageContaining("to get beans of type")
|
||||
.withMessageContaining(String.format(
|
||||
"but context failed to start:%n java.lang.RuntimeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -376,9 +377,9 @@ public class ApplicationContextAssertTests {
|
||||
|
||||
@Test
|
||||
public void getFailureWhenDidNotFailShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("context started");
|
||||
assertThat(getAssert(this.context)).getFailure();
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).getFailure())
|
||||
.withMessageContaining("context started");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -388,18 +389,18 @@ public class ApplicationContextAssertTests {
|
||||
|
||||
@Test
|
||||
public void hasFailedWhenNotFailedShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("to have failed");
|
||||
assertThat(getAssert(this.context)).hasFailed();
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.context)).hasFailed())
|
||||
.withMessageContaining("to have failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasNotFailedWhenFailedShouldFail() {
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("to have not failed");
|
||||
this.thrown.expectMessage(String
|
||||
.format("but context failed to start:%n java.lang.RuntimeException"));
|
||||
assertThat(getAssert(this.failure)).hasNotFailed();
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(getAssert(this.failure)).hasNotFailed())
|
||||
.withMessageContaining("to have not failed")
|
||||
.withMessageContaining(String.format(
|
||||
"but context failed to start:%n java.lang.RuntimeException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.context.bootstrap;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
@@ -27,6 +25,7 @@ import org.springframework.test.context.BootstrapContext;
|
||||
import org.springframework.test.context.CacheAwareContextLoaderDelegate;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -37,17 +36,15 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class SpringBootTestContextBootstrapperTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void springBootTestWithANonMockWebEnvironmentAndWebAppConfigurationFailsFast() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("@WebAppConfiguration should only be used with "
|
||||
+ "@SpringBootTest when @SpringBootTest is configured with a mock web "
|
||||
+ "environment. Please remove @WebAppConfiguration or reconfigure "
|
||||
+ "@SpringBootTest.");
|
||||
buildTestContext(SpringBootTestNonMockWebEnvironmentAndWebAppConfiguration.class);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> buildTestContext(
|
||||
SpringBootTestNonMockWebEnvironmentAndWebAppConfiguration.class))
|
||||
.withMessageContaining("@WebAppConfiguration should only be used with "
|
||||
+ "@SpringBootTest when @SpringBootTest is configured with a mock web "
|
||||
+ "environment. Please remove @WebAppConfiguration or reconfigure "
|
||||
+ "@SpringBootTest.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,9 +21,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.context.annotation.UserConfigurations;
|
||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
@@ -39,6 +37,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
@@ -52,9 +51,6 @@ import static org.junit.Assert.fail;
|
||||
*/
|
||||
public abstract class AbstractApplicationContextRunnerTests<T extends AbstractApplicationContextRunner<T, C, A>, C extends ConfigurableApplicationContext, A extends ApplicationContextAssertProvider<C>> {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void runWithInitializerShouldInitialize() {
|
||||
AtomicBoolean called = new AtomicBoolean();
|
||||
@@ -178,11 +174,9 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
|
||||
|
||||
@Test
|
||||
public void thrownRuleWorksWithCheckedException() {
|
||||
get().run((context) -> {
|
||||
this.thrown.expect(IOException.class);
|
||||
this.thrown.expectMessage("Expected message");
|
||||
throwCheckedException("Expected message");
|
||||
});
|
||||
get().run((context) -> assertThatIOException()
|
||||
.isThrownBy(() -> throwCheckedException("Expected message"))
|
||||
.withMessageContaining("Expected message"));
|
||||
}
|
||||
|
||||
protected abstract T get();
|
||||
|
||||
@@ -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.
|
||||
@@ -29,7 +29,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
@@ -39,6 +38,7 @@ import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link AbstractJsonMarshalTester}.
|
||||
@@ -58,9 +58,6 @@ public abstract class AbstractJsonMarshalTesterTests {
|
||||
private static final ResolvableType TYPE = ResolvableType
|
||||
.forClass(ExampleObject.class);
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
@@ -97,16 +94,16 @@ public abstract class AbstractJsonMarshalTesterTests {
|
||||
|
||||
@Test
|
||||
public void createWhenResourceLoadClassIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ResourceLoadClass must not be null");
|
||||
createTester(null, ResolvableType.forClass(ExampleObject.class));
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> createTester(null, ResolvableType.forClass(ExampleObject.class)))
|
||||
.withMessageContaining("ResourceLoadClass must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenTypeIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Type must not be null");
|
||||
createTester(getClass(), null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> createTester(getClass(), null))
|
||||
.withMessageContaining("Type must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -22,7 +22,6 @@ import java.io.InputStream;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
@@ -30,6 +29,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link BasicJsonTester}.
|
||||
@@ -40,9 +40,6 @@ public class BasicJsonTesterTests {
|
||||
|
||||
private static final String JSON = "{\"spring\":[\"boot\",\"framework\"]}";
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
@@ -50,9 +47,8 @@ public class BasicJsonTesterTests {
|
||||
|
||||
@Test
|
||||
public void createWhenResourceLoadClassIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ResourceLoadClass must not be null");
|
||||
new BasicJsonTester(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new BasicJsonTester(null))
|
||||
.withMessageContaining("ResourceLoadClass must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.junit.Test;
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link GsonTester}.
|
||||
@@ -35,16 +36,16 @@ public class GsonTesterTests extends AbstractJsonMarshalTesterTests {
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenTestIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("TestInstance must not be null");
|
||||
GsonTester.initFields(null, new GsonBuilder().create());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> GsonTester.initFields(null, new GsonBuilder().create()))
|
||||
.withMessageContaining("TestInstance must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenMarshallerIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Marshaller must not be null");
|
||||
GsonTester.initFields(new InitFieldsTestClass(), (Gson) null);
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> GsonTester.initFields(new InitFieldsTestClass(), (Gson) null))
|
||||
.withMessageContaining("Marshaller must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.junit.Test;
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link JacksonTester}.
|
||||
@@ -34,16 +35,17 @@ public class JacksonTesterTests extends AbstractJsonMarshalTesterTests {
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenTestIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("TestInstance must not be null");
|
||||
JacksonTester.initFields(null, new ObjectMapper());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> JacksonTester.initFields(null, new ObjectMapper()))
|
||||
.withMessageContaining("TestInstance must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenMarshallerIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Marshaller must not be null");
|
||||
JacksonTester.initFields(new InitFieldsTestClass(), (ObjectMapper) null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> JacksonTester.initFields(new InitFieldsTestClass(),
|
||||
(ObjectMapper) null))
|
||||
.withMessageContaining("Marshaller must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -24,7 +24,6 @@ import java.io.InputStream;
|
||||
import org.assertj.core.api.AssertProvider;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.skyscreamer.jsonassert.JSONCompareMode;
|
||||
import org.skyscreamer.jsonassert.comparator.DefaultComparator;
|
||||
@@ -37,6 +36,7 @@ import org.springframework.test.util.JsonPathExpectationsHelper;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
/**
|
||||
@@ -60,9 +60,6 @@ public class JsonContentAssertTests {
|
||||
private static JSONComparator COMPARATOR = new DefaultComparator(
|
||||
JSONCompareMode.LENIENT);
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
@@ -840,9 +837,10 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void hasJsonPathValueForIndefinitePathWithEmptyResults() {
|
||||
String expression = "$.familyMembers[?(@.name == 'Dilbert')]";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("No value at JSON path \"" + expression + "\"");
|
||||
assertThat(forJson(SIMPSONS)).hasJsonPathValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(
|
||||
() -> assertThat(forJson(SIMPSONS)).hasJsonPathValue(expression))
|
||||
.withMessageContaining("No value at JSON path \"" + expression + "\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -853,28 +851,28 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void doesNotHaveJsonPathValueForAnEmptyArray() {
|
||||
String expression = "$.emptyArray";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected no value at JSON path \"" + expression + "\" but found: []");
|
||||
assertThat(forJson(TYPES)).doesNotHaveJsonPathValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(TYPES)).doesNotHaveJsonPathValue(expression))
|
||||
.withMessageContaining("Expected no value at JSON path \"" + expression
|
||||
+ "\" but found: []");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveJsonPathValueForAnEmptyMap() {
|
||||
String expression = "$.emptyMap";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected no value at JSON path \"" + expression + "\" but found: {}");
|
||||
assertThat(forJson(TYPES)).doesNotHaveJsonPathValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(TYPES)).doesNotHaveJsonPathValue(expression))
|
||||
.withMessageContaining("Expected no value at JSON path \"" + expression
|
||||
+ "\" but found: {}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveJsonPathValueForIndefinitePathWithResults() {
|
||||
String expression = "$.familyMembers[?(@.name == 'Bart')]";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("Expected no value at JSON path \"" + expression
|
||||
+ "\" but found: [{\"name\":\"Bart\"}]");
|
||||
assertThat(forJson(SIMPSONS)).doesNotHaveJsonPathValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(SIMPSONS)).doesNotHaveJsonPathValue(expression))
|
||||
.withMessageContaining("Expected no value at JSON path \"" + expression
|
||||
+ "\" but found: [{\"name\":\"Bart\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -907,19 +905,19 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void hasEmptyJsonPathValueForIndefinitePathWithResults() {
|
||||
String expression = "$.familyMembers[?(@.name == 'Bart')]";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("Expected an empty value at JSON path \"" + expression
|
||||
+ "\" but found: [{\"name\":\"Bart\"}]");
|
||||
assertThat(forJson(SIMPSONS)).hasEmptyJsonPathValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(SIMPSONS)).hasEmptyJsonPathValue(expression))
|
||||
.withMessageContaining("Expected an empty value at JSON path \""
|
||||
+ expression + "\" but found: [{\"name\":\"Bart\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasEmptyJsonPathValueForWhitespace() {
|
||||
String expression = "$.whitespace";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("Expected an empty value at JSON path \"" + expression
|
||||
+ "\" but found: ' '");
|
||||
assertThat(forJson(TYPES)).hasEmptyJsonPathValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(TYPES)).hasEmptyJsonPathValue(expression))
|
||||
.withMessageContaining("Expected an empty value at JSON path \""
|
||||
+ expression + "\" but found: ' '");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -956,37 +954,41 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void doesNotHaveEmptyJsonPathValueForIndefinitePathWithEmptyResults() {
|
||||
String expression = "$.familyMembers[?(@.name == 'Dilbert')]";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("Expected a non-empty value at JSON path \""
|
||||
+ expression + "\" but found: []");
|
||||
assertThat(forJson(SIMPSONS)).doesNotHaveEmptyJsonPathValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJson(SIMPSONS))
|
||||
.doesNotHaveEmptyJsonPathValue(expression))
|
||||
.withMessageContaining("Expected a non-empty value at JSON path \""
|
||||
+ expression + "\" but found: []");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveEmptyJsonPathValueForAnEmptyString() {
|
||||
String expression = "$.emptyString";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("Expected a non-empty value at JSON path \""
|
||||
+ expression + "\" but found: ''");
|
||||
assertThat(forJson(TYPES)).doesNotHaveEmptyJsonPathValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJson(TYPES))
|
||||
.doesNotHaveEmptyJsonPathValue(expression))
|
||||
.withMessageContaining("Expected a non-empty value at JSON path \""
|
||||
+ expression + "\" but found: ''");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveEmptyJsonPathValueForForAnEmptyArray() {
|
||||
String expression = "$.emptyArray";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("Expected a non-empty value at JSON path \""
|
||||
+ expression + "\" but found: []");
|
||||
assertThat(forJson(TYPES)).doesNotHaveEmptyJsonPathValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJson(TYPES))
|
||||
.doesNotHaveEmptyJsonPathValue(expression))
|
||||
.withMessageContaining("Expected a non-empty value at JSON path \""
|
||||
+ expression + "\" but found: []");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveEmptyJsonPathValueForAnEmptyMap() {
|
||||
String expression = "$.emptyMap";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("Expected a non-empty value at JSON path \""
|
||||
+ expression + "\" but found: {}");
|
||||
assertThat(forJson(TYPES)).doesNotHaveEmptyJsonPathValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJson(TYPES))
|
||||
.doesNotHaveEmptyJsonPathValue(expression))
|
||||
.withMessageContaining("Expected a non-empty value at JSON path \""
|
||||
+ expression + "\" but found: {}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1002,10 +1004,10 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void hasJsonPathStringValueForNonString() {
|
||||
String expression = "$.bool";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected a string at JSON path \"" + expression + "\" but found: true");
|
||||
assertThat(forJson(TYPES)).hasJsonPathStringValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(TYPES)).hasJsonPathStringValue(expression))
|
||||
.withMessageContaining("Expected a string at JSON path \"" + expression
|
||||
+ "\" but found: true");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1016,10 +1018,10 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void hasJsonPathNumberValueForNonNumber() {
|
||||
String expression = "$.bool";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected a number at JSON path \"" + expression + "\" but found: true");
|
||||
assertThat(forJson(TYPES)).hasJsonPathNumberValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(TYPES)).hasJsonPathNumberValue(expression))
|
||||
.withMessageContaining("Expected a number at JSON path \"" + expression
|
||||
+ "\" but found: true");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1030,10 +1032,10 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void hasJsonPathBooleanValueForNonBoolean() {
|
||||
String expression = "$.num";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected a boolean at JSON path \"" + expression + "\" but found: 5");
|
||||
assertThat(forJson(TYPES)).hasJsonPathBooleanValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(TYPES)).hasJsonPathBooleanValue(expression))
|
||||
.withMessageContaining("Expected a boolean at JSON path \"" + expression
|
||||
+ "\" but found: 5");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1049,10 +1051,10 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void hasJsonPathArrayValueForNonArray() {
|
||||
String expression = "$.str";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected an array at JSON path \"" + expression + "\" but found: 'foo'");
|
||||
assertThat(forJson(TYPES)).hasJsonPathArrayValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(TYPES)).hasJsonPathArrayValue(expression))
|
||||
.withMessageContaining("Expected an array at JSON path \"" + expression
|
||||
+ "\" but found: 'foo'");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1068,10 +1070,11 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void hasJsonPathMapValueForNonMap() {
|
||||
String expression = "$.str";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected a map at JSON path \"" + expression + "\" but found: 'foo'");
|
||||
assertThat(forJson(TYPES)).hasJsonPathMapValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(
|
||||
() -> assertThat(forJson(TYPES)).hasJsonPathMapValue(expression))
|
||||
.withMessageContaining("Expected a map at JSON path \"" + expression
|
||||
+ "\" but found: 'foo'");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1104,10 +1107,11 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void extractingJsonPathStringValueForWrongType() {
|
||||
String expression = "$.num";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected a string at JSON path \"" + expression + "\" but found: 5");
|
||||
assertThat(forJson(TYPES)).extractingJsonPathStringValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJson(TYPES))
|
||||
.extractingJsonPathStringValue(expression))
|
||||
.withMessageContaining("Expected a string at JSON path \"" + expression
|
||||
+ "\" but found: 5");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1123,10 +1127,11 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void extractingJsonPathNumberValueForWrongType() {
|
||||
String expression = "$.str";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected a number at JSON path \"" + expression + "\" but found: 'foo'");
|
||||
assertThat(forJson(TYPES)).extractingJsonPathNumberValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJson(TYPES))
|
||||
.extractingJsonPathNumberValue(expression))
|
||||
.withMessageContaining("Expected a number at JSON path \"" + expression
|
||||
+ "\" but found: 'foo'");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1142,10 +1147,11 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void extractingJsonPathBooleanValueForWrongType() {
|
||||
String expression = "$.str";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("Expected a boolean at JSON path \"" + expression
|
||||
+ "\" but found: 'foo'");
|
||||
assertThat(forJson(TYPES)).extractingJsonPathBooleanValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJson(TYPES))
|
||||
.extractingJsonPathBooleanValue(expression))
|
||||
.withMessageContaining("Expected a boolean at JSON path \"" + expression
|
||||
+ "\" but found: 'foo'");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1167,10 +1173,10 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void extractingJsonPathArrayValueForWrongType() {
|
||||
String expression = "$.str";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected an array at JSON path \"" + expression + "\" but found: 'foo'");
|
||||
assertThat(forJson(TYPES)).extractingJsonPathArrayValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(TYPES)).extractingJsonPathArrayValue(expression))
|
||||
.withMessageContaining("Expected an array at JSON path \"" + expression
|
||||
+ "\" but found: 'foo'");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1192,10 +1198,10 @@ public class JsonContentAssertTests {
|
||||
@Test
|
||||
public void extractingJsonPathMapValueForWrongType() {
|
||||
String expression = "$.str";
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"Expected a map at JSON path \"" + expression + "\" but found: 'foo'");
|
||||
assertThat(forJson(TYPES)).extractingJsonPathMapValue(expression);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forJson(TYPES)).extractingJsonPathMapValue(expression))
|
||||
.withMessageContaining("Expected a map at JSON path \"" + expression
|
||||
+ "\" but found: 'foo'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
package org.springframework.boot.test.json;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link JsonContent}.
|
||||
@@ -36,21 +35,18 @@ public class JsonContentTests {
|
||||
private static final ResolvableType TYPE = ResolvableType
|
||||
.forClass(ExampleObject.class);
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenResourceLoadClassIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ResourceLoadClass must not be null");
|
||||
new JsonContent<ExampleObject>(null, TYPE, JSON);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new JsonContent<ExampleObject>(null, TYPE, JSON))
|
||||
.withMessageContaining("ResourceLoadClass must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenJsonIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("JSON must not be null");
|
||||
new JsonContent<ExampleObject>(getClass(), TYPE, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new JsonContent<ExampleObject>(getClass(), TYPE, null))
|
||||
.withMessageContaining("JSON must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.junit.Test;
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link JsonbTester}.
|
||||
@@ -36,16 +37,16 @@ public class JsonbTesterTests extends AbstractJsonMarshalTesterTests {
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenTestIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("TestInstance must not be null");
|
||||
JsonbTester.initFields(null, JsonbBuilder.create());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> JsonbTester.initFields(null, JsonbBuilder.create()))
|
||||
.withMessageContaining("TestInstance must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initFieldsWhenMarshallerIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Marshaller must not be null");
|
||||
JsonbTester.initFields(new InitFieldsTestClass(), (Jsonb) null);
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> JsonbTester.initFields(new InitFieldsTestClass(), (Jsonb) null))
|
||||
.withMessageContaining("Marshaller must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
package org.springframework.boot.test.json;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link ObjectContent}.
|
||||
@@ -36,14 +35,11 @@ public class ObjectContentTests {
|
||||
private static final ResolvableType TYPE = ResolvableType
|
||||
.forClass(ExampleObject.class);
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenObjectIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Object must not be null");
|
||||
new ObjectContent<ExampleObject>(TYPE, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ObjectContent<ExampleObject>(TYPE, null))
|
||||
.withMessageContaining("Object must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,9 +19,7 @@ package org.springframework.boot.test.mock.mockito;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Answers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -32,6 +30,7 @@ import org.springframework.boot.test.mock.mockito.example.RealExampleService;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Tests for {@link DefinitionsParser}.
|
||||
@@ -40,9 +39,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class DefinitionsParserTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private DefinitionsParser parser = new DefinitionsParser();
|
||||
|
||||
@Test
|
||||
@@ -104,9 +100,9 @@ public class DefinitionsParserTests {
|
||||
|
||||
@Test
|
||||
public void parseMockBeanMissingClassToMock() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Unable to deduce type to mock");
|
||||
this.parser.parse(MockBeanMissingClassToMock.class);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.parser.parse(MockBeanMissingClassToMock.class))
|
||||
.withMessageContaining("Unable to deduce type to mock");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,10 +117,11 @@ public class DefinitionsParserTests {
|
||||
|
||||
@Test
|
||||
public void parseMockBeanMultipleClassesWithName() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage(
|
||||
"The name attribute can only be used when mocking a single class");
|
||||
this.parser.parse(MockBeanMultipleClassesWithName.class);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(
|
||||
() -> this.parser.parse(MockBeanMultipleClassesWithName.class))
|
||||
.withMessageContaining(
|
||||
"The name attribute can only be used when mocking a single class");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,9 +180,9 @@ public class DefinitionsParserTests {
|
||||
|
||||
@Test
|
||||
public void parseSpyBeanMissingClassToMock() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Unable to deduce type to spy");
|
||||
this.parser.parse(SpyBeanMissingClassToMock.class);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.parser.parse(SpyBeanMissingClassToMock.class))
|
||||
.withMessageContaining("Unable to deduce type to spy");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,10 +197,10 @@ public class DefinitionsParserTests {
|
||||
|
||||
@Test
|
||||
public void parseSpyBeanMultipleClassesWithName() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage(
|
||||
"The name attribute can only be used when spying a single class");
|
||||
this.parser.parse(SpyBeanMultipleClassesWithName.class);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.parser.parse(SpyBeanMultipleClassesWithName.class))
|
||||
.withMessageContaining(
|
||||
"The name attribute can only be used when spying a single class");
|
||||
}
|
||||
|
||||
private MockDefinition getMockDefinition(int index) {
|
||||
|
||||
@@ -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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.mock.mockito;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.mock.MockCreationSettings;
|
||||
@@ -28,6 +26,7 @@ import org.springframework.boot.test.mock.mockito.example.ExampleService;
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -40,14 +39,11 @@ public class MockDefinitionTests {
|
||||
private static final ResolvableType EXAMPLE_SERVICE_TYPE = ResolvableType
|
||||
.forClass(ExampleService.class);
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void classToMockMustNotBeNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("TypeToMock must not be null");
|
||||
new MockDefinition(null, null, null, null, false, null, null);
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new MockDefinition(null, null, null, null, false, null, null))
|
||||
.withMessageContaining("TypeToMock must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.mock.mockito;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
@@ -33,6 +31,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Test for {@link MockitoPostProcessor}. See also the integration tests.
|
||||
@@ -43,20 +42,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class MockitoPostProcessorTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void cannotMockMultipleBeans() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
MockitoPostProcessor.register(context);
|
||||
context.register(MultipleBeans.class);
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage(
|
||||
"Unable to register mock bean " + ExampleService.class.getName()
|
||||
+ " expected a single matching bean to replace "
|
||||
+ "but found [example1, example2]");
|
||||
context.refresh();
|
||||
assertThatIllegalStateException().isThrownBy(context::refresh)
|
||||
.withMessageContaining(
|
||||
"Unable to register mock bean " + ExampleService.class.getName()
|
||||
+ " expected a single matching bean to replace "
|
||||
+ "but found [example1, example2]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,12 +59,11 @@ public class MockitoPostProcessorTests {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
MockitoPostProcessor.register(context);
|
||||
context.register(MultipleQualifiedBeans.class);
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage(
|
||||
"Unable to register mock bean " + ExampleService.class.getName()
|
||||
+ " expected a single matching bean to replace "
|
||||
+ "but found [example1, example3]");
|
||||
context.refresh();
|
||||
assertThatIllegalStateException().isThrownBy(context::refresh)
|
||||
.withMessageContaining(
|
||||
"Unable to register mock bean " + ExampleService.class.getName()
|
||||
+ " expected a single matching bean to replace "
|
||||
+ "but found [example1, example3]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.mock.mockito;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.mock.MockCreationSettings;
|
||||
@@ -29,6 +27,7 @@ import org.springframework.boot.test.mock.mockito.example.RealExampleService;
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -41,14 +40,11 @@ public class SpyDefinitionTests {
|
||||
private static final ResolvableType REAL_SERVICE_TYPE = ResolvableType
|
||||
.forClass(RealExampleService.class);
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void classToSpyMustNotBeNull() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("TypeToSpy must not be null");
|
||||
new SpyDefinition(null, null, null, true, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new SpyDefinition(null, null, null, true, null))
|
||||
.withMessageContaining("TypeToSpy must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,18 +87,17 @@ public class SpyDefinitionTests {
|
||||
public void createSpyWhenNullInstanceShouldThrowException() {
|
||||
SpyDefinition definition = new SpyDefinition("name", REAL_SERVICE_TYPE,
|
||||
MockReset.BEFORE, true, null);
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Instance must not be null");
|
||||
definition.createSpy(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> definition.createSpy(null))
|
||||
.withMessageContaining("Instance must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSpyWhenWrongInstanceShouldThrowException() {
|
||||
SpyDefinition definition = new SpyDefinition("name", REAL_SERVICE_TYPE,
|
||||
MockReset.BEFORE, true, null);
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("must be an instance of");
|
||||
definition.createSpy(new ExampleServiceCaller(null));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> definition.createSpy(new ExampleServiceCaller(null)))
|
||||
.withMessageContaining("must be an instance of");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -20,14 +20,13 @@ import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.web.util.UriTemplateHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -41,28 +40,26 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class LocalHostUriTemplateHandlerTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void createWhenEnvironmentIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Environment must not be null");
|
||||
new LocalHostUriTemplateHandler(null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new LocalHostUriTemplateHandler(null))
|
||||
.withMessageContaining("Environment must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenSchemeIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Scheme must not be null");
|
||||
new LocalHostUriTemplateHandler(new MockEnvironment(), null);
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new LocalHostUriTemplateHandler(new MockEnvironment(), null))
|
||||
.withMessageContaining("Scheme must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenHandlerIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Handler must not be null");
|
||||
new LocalHostUriTemplateHandler(new MockEnvironment(), "http", null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new LocalHostUriTemplateHandler(new MockEnvironment(),
|
||||
"http", null))
|
||||
.withMessageContaining("Handler must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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.
|
||||
@@ -17,9 +17,7 @@
|
||||
package org.springframework.boot.test.web.client;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.test.web.client.RequestExpectationManager;
|
||||
@@ -28,6 +26,8 @@ import org.springframework.test.web.client.UnorderedRequestExpectationManager;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
|
||||
|
||||
@@ -40,9 +40,6 @@ public class MockServerRestTemplateCustomizerTests {
|
||||
|
||||
private MockServerRestTemplateCustomizer customizer;
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.customizer = new MockServerRestTemplateCustomizer();
|
||||
@@ -58,9 +55,9 @@ public class MockServerRestTemplateCustomizerTests {
|
||||
|
||||
@Test
|
||||
public void createWhenExpectationManagerClassIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ExpectationManager must not be null");
|
||||
new MockServerRestTemplateCustomizer(null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new MockServerRestTemplateCustomizer(null))
|
||||
.withMessageContaining("ExpectationManager must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,20 +99,20 @@ public class MockServerRestTemplateCustomizerTests {
|
||||
|
||||
@Test
|
||||
public void getServerWhenNoServersAreBoundShouldThrowException() {
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Unable to return a single MockRestServiceServer since "
|
||||
+ "MockServerRestTemplateCustomizer has not been bound to a RestTemplate");
|
||||
this.customizer.getServer();
|
||||
assertThatIllegalStateException().isThrownBy(this.customizer::getServer)
|
||||
.withMessageContaining(
|
||||
"Unable to return a single MockRestServiceServer since "
|
||||
+ "MockServerRestTemplateCustomizer has not been bound to a RestTemplate");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServerWhenMultipleServersAreBoundShouldThrowException() {
|
||||
this.customizer.customize(new RestTemplate());
|
||||
this.customizer.customize(new RestTemplate());
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Unable to return a single MockRestServiceServer since "
|
||||
+ "MockServerRestTemplateCustomizer has been bound to more than one RestTemplate");
|
||||
this.customizer.getServer();
|
||||
assertThatIllegalStateException().isThrownBy(this.customizer::getServer)
|
||||
.withMessageContaining(
|
||||
"Unable to return a single MockRestServiceServer since "
|
||||
+ "MockServerRestTemplateCustomizer has been bound to more than one RestTemplate");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,9 +19,7 @@ package org.springframework.boot.test.web.client;
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
@@ -37,6 +35,8 @@ import org.springframework.test.web.client.RequestMatcher;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -51,9 +51,6 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
*/
|
||||
public class RootUriRequestExpectationManagerTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private String uri = "http://example.com";
|
||||
|
||||
@Mock
|
||||
@@ -72,16 +69,17 @@ public class RootUriRequestExpectationManagerTests {
|
||||
|
||||
@Test
|
||||
public void createWhenRootUriIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("RootUri must not be null");
|
||||
new RootUriRequestExpectationManager(null, this.delegate);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(
|
||||
() -> new RootUriRequestExpectationManager(null, this.delegate))
|
||||
.withMessageContaining("RootUri must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenExpectationManagerIsNullShouldThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ExpectationManager must not be null");
|
||||
new RootUriRequestExpectationManager(this.uri, null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new RootUriRequestExpectationManager(this.uri, null))
|
||||
.withMessageContaining("ExpectationManager must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,9 +119,9 @@ public class RootUriRequestExpectationManagerTests {
|
||||
given(this.delegate.validateRequest(any(ClientHttpRequest.class)))
|
||||
.willThrow(new AssertionError(
|
||||
"Request URI expected:</hello> was:<http://example.com/bad>"));
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage("Request URI expected:<http://example.com/hello>");
|
||||
this.manager.validateRequest(request);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> this.manager.validateRequest(request))
|
||||
.withMessageContaining("Request URI expected:<http://example.com/hello>");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -182,10 +180,10 @@ public class RootUriRequestExpectationManagerTests {
|
||||
MockRestServiceServer server = RootUriRequestExpectationManager
|
||||
.bindTo(restTemplate);
|
||||
server.expect(requestTo("/hello")).andRespond(withSuccess());
|
||||
this.thrown.expect(AssertionError.class);
|
||||
this.thrown.expectMessage(
|
||||
"expected:<http://example.com/hello> but was:<http://spring.io/hello>");
|
||||
restTemplate.getForEntity("http://spring.io/hello", String.class);
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> restTemplate.getForEntity("http://spring.io/hello", String.class))
|
||||
.withMessageContaining(
|
||||
"expected:<http://example.com/hello> but was:<http://spring.io/hello>");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -24,9 +24,7 @@ import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.WebConnection;
|
||||
import com.gargoylesoftware.htmlunit.WebRequest;
|
||||
import com.gargoylesoftware.htmlunit.WebResponse;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@@ -34,6 +32,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -47,9 +46,6 @@ import static org.mockito.Mockito.verify;
|
||||
@SuppressWarnings("resource")
|
||||
public class LocalHostWebClientTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<WebRequest> requestCaptor;
|
||||
|
||||
@@ -59,9 +55,9 @@ public class LocalHostWebClientTests {
|
||||
|
||||
@Test
|
||||
public void createWhenEnvironmentIsNullWillThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Environment must not be null");
|
||||
new LocalHostWebClient(null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new LocalHostWebClient(null))
|
||||
.withMessageContaining("Environment must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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,9 +23,7 @@ import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.WebClientOptions;
|
||||
import com.gargoylesoftware.htmlunit.WebRequest;
|
||||
import com.gargoylesoftware.htmlunit.WebWindow;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@@ -34,6 +32,7 @@ import org.openqa.selenium.Capabilities;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -47,9 +46,6 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class LocalHostWebConnectionHtmlUnitDriverTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private WebClient webClient;
|
||||
|
||||
@@ -60,33 +56,34 @@ public class LocalHostWebConnectionHtmlUnitDriverTests {
|
||||
|
||||
@Test
|
||||
public void createWhenEnvironmentIsNullWillThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Environment must not be null");
|
||||
new LocalHostWebConnectionHtmlUnitDriver(null);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new LocalHostWebConnectionHtmlUnitDriver(null))
|
||||
.withMessageContaining("Environment must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithJavascriptFlagWhenEnvironmentIsNullWillThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Environment must not be null");
|
||||
new LocalHostWebConnectionHtmlUnitDriver(null, true);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new LocalHostWebConnectionHtmlUnitDriver(null, true))
|
||||
.withMessageContaining("Environment must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithBrowserVersionWhenEnvironmentIsNullWillThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Environment must not be null");
|
||||
new LocalHostWebConnectionHtmlUnitDriver(null, BrowserVersion.CHROME);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new LocalHostWebConnectionHtmlUnitDriver(null,
|
||||
BrowserVersion.CHROME))
|
||||
.withMessageContaining("Environment must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithCapabilitiesWhenEnvironmentIsNullWillThrowException() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Environment must not be null");
|
||||
Capabilities capabilities = mock(Capabilities.class);
|
||||
given(capabilities.getBrowserName()).willReturn("htmlunit");
|
||||
given(capabilities.getVersion()).willReturn("chrome");
|
||||
new LocalHostWebConnectionHtmlUnitDriver(null, capabilities);
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new LocalHostWebConnectionHtmlUnitDriver(null, capabilities))
|
||||
.withMessageContaining("Environment must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user