Migrate from ExpectedException rule to AssertJ

Replace ExpectedException JUnit rules with AssertJ exception
assertions.

Closes gh-14336
This commit is contained in:
Phillip Webb
2018-10-01 11:18:16 -07:00
parent 42cb0effc4
commit d76bba5e6f
273 changed files with 2752 additions and 3624 deletions

View File

@@ -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.
@@ -18,9 +18,7 @@ package org.springframework.boot.devtools;
import ch.qos.logback.classic.Logger;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
@@ -29,6 +27,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Tests for {@link RemoteUrlPropertyExtractor}.
@@ -37,9 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class RemoteUrlPropertyExtractorTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@After
public void preventRunFailuresFromPollutingLoggerContext() {
((Logger) LoggerFactory.getLogger(RemoteUrlPropertyExtractorTests.class))
@@ -48,24 +44,23 @@ public class RemoteUrlPropertyExtractorTests {
@Test
public void missingUrl() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("No remote URL specified");
doTest();
assertThatIllegalStateException().isThrownBy(() -> doTest())
.withMessageContaining("No remote URL specified");
}
@Test
public void malformedUrl() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Malformed URL '::://wibble'");
doTest("::://wibble");
assertThatIllegalStateException().isThrownBy(() -> doTest("::://wibble"))
.withMessageContaining("Malformed URL '::://wibble'");
}
@Test
public void multipleUrls() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Multiple URLs specified");
doTest("http://localhost:8080", "http://localhost:9090");
assertThatIllegalStateException()
.isThrownBy(
() -> doTest("http://localhost:8080", "http://localhost:9090"))
.withMessageContaining("Multiple URLs specified");
}
@Test

View File

@@ -28,7 +28,6 @@ import org.apache.jasper.EmbeddedServletOptions;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -56,6 +55,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -71,9 +71,6 @@ import static org.mockito.Mockito.verify;
*/
public class LocalDevToolsAutoConfigurationTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public MockRestarter mockRestarter = new MockRestarter();
@@ -168,8 +165,8 @@ public class LocalDevToolsAutoConfigurationTests {
Map<String, Object> properties = new HashMap<>();
properties.put("spring.devtools.livereload.enabled", false);
this.context = initializeAndRun(Config.class, properties);
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean(OptionalLiveReloadServer.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(OptionalLiveReloadServer.class));
}
@Test
@@ -203,8 +200,8 @@ public class LocalDevToolsAutoConfigurationTests {
Map<String, Object> properties = new HashMap<>();
properties.put("spring.devtools.restart.enabled", false);
this.context = initializeAndRun(Config.class, properties);
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean(ClassPathFileSystemWatcher.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ClassPathFileSystemWatcher.class));
}
@Test

View File

@@ -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.
@@ -20,7 +20,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -41,6 +40,7 @@ import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;
/**
@@ -58,9 +58,6 @@ public class RemoteDevToolsAutoConfigurationTests {
@Rule
public MockRestarter mockRestarter = new MockRestarter();
@Rule
public ExpectedException thrown = ExpectedException.none();
private AnnotationConfigWebApplicationContext context;
private MockHttpServletRequest request;
@@ -86,8 +83,8 @@ public class RemoteDevToolsAutoConfigurationTests {
@Test
public void disabledIfRemoteSecretIsMissing() {
loadContext("a:b");
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean(DispatcherFilter.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(DispatcherFilter.class));
}
@Test
@@ -144,8 +141,8 @@ public class RemoteDevToolsAutoConfigurationTests {
public void disableRestart() {
loadContext("spring.devtools.remote.secret:supersecret",
"spring.devtools.remote.restart.enabled:false");
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean("remoteRestartHandlerMapper");
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean("remoteRestartHandlerMapper"));
}
@Test

View File

@@ -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.
@@ -20,10 +20,10 @@ import java.io.File;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link TriggerFileFilter}.
@@ -32,17 +32,13 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class TriggerFileFilterTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Test
public void nameMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Name must not be null");
new TriggerFileFilter(null);
assertThatIllegalArgumentException().isThrownBy(() -> new TriggerFileFilter(null))
.withMessageContaining("Name must not be null");
}
@Test

View File

@@ -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,13 +19,12 @@ package org.springframework.boot.devtools.classpath;
import java.util.LinkedHashSet;
import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.devtools.filewatch.ChangedFiles;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link ClassPathChangedEvent}.
@@ -34,16 +33,13 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class ClassPathChangedEventTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private Object source = new Object();
@Test
public void changeSetMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ChangeSet must not be null");
new ClassPathChangedEvent(this.source, null, false);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassPathChangedEvent(this.source, null, false))
.withMessageContaining("ChangeSet must not be null");
}
@Test

View File

@@ -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,9 +22,7 @@ import java.util.LinkedHashSet;
import java.util.Set;
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,7 @@ import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
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.never;
import static org.mockito.Mockito.verify;
@@ -48,9 +47,6 @@ import static org.mockito.Mockito.verify;
*/
public class ClassPathFileChangeListenerTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Mock
private ApplicationEventPublisher eventPublisher;
@@ -70,18 +66,18 @@ public class ClassPathFileChangeListenerTests {
@Test
public void eventPublisherMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("EventPublisher must not be null");
new ClassPathFileChangeListener(null, this.restartStrategy,
this.fileSystemWatcher);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassPathFileChangeListener(null,
this.restartStrategy, this.fileSystemWatcher))
.withMessageContaining("EventPublisher must not be null");
}
@Test
public void restartStrategyMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("RestartStrategy must not be null");
new ClassPathFileChangeListener(this.eventPublisher, null,
this.fileSystemWatcher);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassPathFileChangeListener(this.eventPublisher,
null, this.fileSystemWatcher))
.withMessageContaining("RestartStrategy must not be null");
}
@Test

View File

@@ -26,7 +26,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.boot.devtools.filewatch.FileSystemWatcher;
@@ -40,6 +39,7 @@ import org.springframework.core.env.MapPropertySource;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.mock;
/**
@@ -49,19 +49,16 @@ import static org.mockito.Mockito.mock;
*/
public class ClassPathFileSystemWatcherTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Test
public void urlsMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Urls must not be null");
URL[] urls = null;
new ClassPathFileSystemWatcher(mock(FileSystemWatcherFactory.class),
mock(ClassPathRestartStrategy.class), urls);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassPathFileSystemWatcher(
mock(FileSystemWatcherFactory.class),
mock(ClassPathRestartStrategy.class), (URL[]) null))
.withMessageContaining("Urls must not be null");
}
@Test

View File

@@ -21,9 +21,7 @@ import java.util.Collections;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.SpringApplication;
@@ -38,6 +36,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Integration tests for the configuration of development-time properties
@@ -46,9 +45,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class DevToolPropertiesIntegrationTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private ConfigurableApplicationContext context;
@Before
@@ -90,8 +86,8 @@ public class DevToolPropertiesIntegrationTests {
BeanConditionConfiguration.class);
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run();
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean(MyBean.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(MyBean.class));
}
@Test

View File

@@ -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.
@@ -20,12 +20,12 @@ import java.io.File;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link ChangedFile}.
@@ -34,31 +34,28 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class ChangedFileTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Test
public void sourceFolderMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("SourceFolder must not be null");
new ChangedFile(null, this.temp.newFile(), Type.ADD);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ChangedFile(null, this.temp.newFile(), Type.ADD))
.withMessageContaining("SourceFolder must not be null");
}
@Test
public void fileMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("File must not be null");
new ChangedFile(this.temp.newFolder(), null, Type.ADD);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ChangedFile(this.temp.newFolder(), null, Type.ADD))
.withMessageContaining("File must not be null");
}
@Test
public void typeMustNotBeNull() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Type must not be null");
new ChangedFile(this.temp.newFile(), this.temp.newFolder(), null);
assertThatIllegalArgumentException().isThrownBy(
() -> new ChangedFile(this.temp.newFile(), this.temp.newFolder(), null))
.withMessageContaining("Type must not be null");
}
@Test

View File

@@ -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,12 +23,12 @@ import java.util.concurrent.TimeUnit;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link FileSnapshot}.
@@ -42,24 +42,20 @@ public class FileSnapshotTests {
private static final long MODIFIED = new Date().getTime()
- TimeUnit.DAYS.toMillis(10);
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void fileMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("File must not be null");
new FileSnapshot(null);
assertThatIllegalArgumentException().isThrownBy(() -> new FileSnapshot(null))
.withMessageContaining("File must not be null");
}
@Test
public void fileMustNotBeAFolder() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("File must not be a folder");
new FileSnapshot(this.temporaryFolder.newFolder());
assertThatIllegalArgumentException()
.isThrownBy(() -> new FileSnapshot(this.temporaryFolder.newFolder()))
.withMessageContaining("File must not be a folder");
}
@Test

View File

@@ -30,13 +30,14 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
import org.springframework.util.FileCopyUtils;
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.mockito.Mockito.mock;
/**
@@ -46,9 +47,6 @@ import static org.mockito.Mockito.mock;
*/
public class FileSystemWatcherTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private FileSystemWatcher watcher;
private List<Set<ChangedFiles>> changes = Collections
@@ -64,62 +62,66 @@ public class FileSystemWatcherTests {
@Test
public void pollIntervalMustBePositive() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("PollInterval must be positive");
new FileSystemWatcher(true, Duration.ofMillis(0), Duration.ofMillis(1));
assertThatIllegalArgumentException()
.isThrownBy(() -> new FileSystemWatcher(true, Duration.ofMillis(0),
Duration.ofMillis(1)))
.withMessageContaining("PollInterval must be positive");
}
@Test
public void quietPeriodMustBePositive() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("QuietPeriod must be positive");
new FileSystemWatcher(true, Duration.ofMillis(1), Duration.ofMillis(0));
assertThatIllegalArgumentException()
.isThrownBy(() -> new FileSystemWatcher(true, Duration.ofMillis(1),
Duration.ofMillis(0)))
.withMessageContaining("QuietPeriod must be positive");
}
@Test
public void pollIntervalMustBeGreaterThanQuietPeriod() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("PollInterval must be greater than QuietPeriod");
new FileSystemWatcher(true, Duration.ofMillis(1), Duration.ofMillis(1));
assertThatIllegalArgumentException()
.isThrownBy(() -> new FileSystemWatcher(true, Duration.ofMillis(1),
Duration.ofMillis(1)))
.withMessageContaining("PollInterval must be greater than QuietPeriod");
}
@Test
public void listenerMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("FileChangeListener must not be null");
this.watcher.addListener(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> this.watcher.addListener(null))
.withMessageContaining("FileChangeListener must not be null");
}
@Test
public void cannotAddListenerToStartedListener() {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("FileSystemWatcher already started");
this.watcher.start();
this.watcher.addListener(mock(FileChangeListener.class));
assertThatIllegalStateException()
.isThrownBy(
() -> this.watcher.addListener(mock(FileChangeListener.class)))
.withMessageContaining("FileSystemWatcher already started");
}
@Test
public void sourceFolderMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Folder must not be null");
this.watcher.addSourceFolder(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> this.watcher.addSourceFolder(null))
.withMessageContaining("Folder must not be null");
}
@Test
public void sourceFolderMustNotBeAFile() {
File folder = new File("pom.xml");
assertThat(folder.isFile()).isTrue();
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Folder 'pom.xml' must not be a file");
this.watcher.addSourceFolder(new File("pom.xml"));
assertThatIllegalArgumentException()
.isThrownBy(() -> this.watcher.addSourceFolder(new File("pom.xml")))
.withMessageContaining("Folder 'pom.xml' must not be a file");
}
@Test
public void cannotAddSourceFolderToStartedListener() throws Exception {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("FileSystemWatcher already started");
this.watcher.start();
this.watcher.addSourceFolder(this.temp.newFolder());
assertThatIllegalStateException()
.isThrownBy(() -> this.watcher.addSourceFolder(this.temp.newFolder()))
.withMessageContaining("FileSystemWatcher already started");
}
@Test

View File

@@ -22,13 +22,13 @@ import java.io.IOException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link FolderSnapshot}.
@@ -37,9 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class FolderSnapshotTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -55,17 +52,15 @@ public class FolderSnapshotTests {
@Test
public void folderMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Folder must not be null");
new FolderSnapshot(null);
assertThatIllegalArgumentException().isThrownBy(() -> new FolderSnapshot(null))
.withMessageContaining("Folder must not be null");
}
@Test
public void folderMustNotBeFile() throws Exception {
File file = this.temporaryFolder.newFile();
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Folder '" + file + "' must not be a file");
new FolderSnapshot(file);
assertThatIllegalArgumentException().isThrownBy(() -> new FolderSnapshot(file))
.withMessageContaining("Folder '" + file + "' must not be a file");
}
@Test
@@ -106,17 +101,18 @@ public class FolderSnapshotTests {
@Test
public void getChangedFilesSnapshotMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Snapshot must not be null");
this.initialSnapshot.getChangedFiles(null, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> this.initialSnapshot.getChangedFiles(null, null))
.withMessageContaining("Snapshot must not be null");
}
@Test
public void getChangedFilesSnapshotMustBeTheSameSourceFolder() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Snapshot source folder must be '" + this.folder + "'");
this.initialSnapshot
.getChangedFiles(new FolderSnapshot(createTestFolderStructure()), null);
assertThatIllegalArgumentException()
.isThrownBy(() -> this.initialSnapshot.getChangedFiles(
new FolderSnapshot(createTestFolderStructure()), null))
.withMessageContaining(
"Snapshot source folder must be '" + this.folder + "'");
}
@Test

View File

@@ -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.
@@ -21,11 +21,10 @@ import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
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.assertThatIOException;
/**
* Tests for {@link ConnectionInputStream}.
@@ -37,9 +36,6 @@ public class ConnectionInputStreamTests {
private static final byte[] NO_BYTES = {};
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void readHeader() throws Exception {
String header = "";
@@ -68,19 +64,18 @@ public class ConnectionInputStreamTests {
public void checkedRead() throws Exception {
ConnectionInputStream inputStream = new ConnectionInputStream(
new ByteArrayInputStream(NO_BYTES));
this.thrown.expect(IOException.class);
this.thrown.expectMessage("End of stream");
inputStream.checkedRead();
assertThatIOException().isThrownBy(inputStream::checkedRead)
.withMessageContaining("End of stream");
}
@Test
public void checkedReadArray() throws Exception {
byte[] buffer = new byte[100];
ConnectionInputStream inputStream = new ConnectionInputStream(
new ByteArrayInputStream(NO_BYTES));
this.thrown.expect(IOException.class);
this.thrown.expectMessage("End of stream");
byte[] buffer = new byte[100];
inputStream.checkedRead(buffer, 0, buffer.length);
assertThatIOException()
.isThrownBy(() -> inputStream.checkedRead(buffer, 0, buffer.length))
.withMessageContaining("End of stream");
}
private static class LimitedInputStream extends FilterInputStream {

View File

@@ -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.
@@ -20,11 +20,11 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
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.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Tests for {@link Frame}.
@@ -33,21 +33,17 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class FrameTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void payloadMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Payload must not be null");
new Frame((String) null);
assertThatIllegalArgumentException().isThrownBy(() -> new Frame((String) null))
.withMessageContaining("Payload must not be null");
}
@Test
public void typeMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Type must not be null");
new Frame((Frame.Type) null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new Frame((Frame.Type) null))
.withMessageContaining("Type must not be null");
}
@Test
@@ -92,17 +88,17 @@ public class FrameTests {
@Test
public void readFragmentedNotSupported() throws Exception {
byte[] bytes = new byte[] { 0x0F };
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Fragmented frames are not supported");
Frame.read(newConnectionInputStream(bytes));
assertThatIllegalStateException()
.isThrownBy(() -> Frame.read(newConnectionInputStream(bytes)))
.withMessageContaining("Fragmented frames are not supported");
}
@Test
public void readLargeFramesNotSupported() throws Exception {
byte[] bytes = new byte[] { (byte) 0x80, (byte) 0xFF };
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Large frames are not supported");
Frame.read(newConnectionInputStream(bytes));
assertThatIllegalStateException()
.isThrownBy(() -> Frame.read(newConnectionInputStream(bytes)))
.withMessageContaining("Large frames are not supported");
}
@Test

View File

@@ -29,7 +29,6 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.devtools.classpath.ClassPathChangedEvent;
@@ -46,6 +45,7 @@ import org.springframework.mock.http.client.MockClientHttpRequest;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link ClassPathChangeUploader}.
@@ -55,9 +55,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class ClassPathChangeUploaderTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@@ -74,30 +71,32 @@ public class ClassPathChangeUploaderTests {
@Test
public void urlMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("URL must not be empty");
new ClassPathChangeUploader(null, this.requestFactory);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassPathChangeUploader(null, this.requestFactory))
.withMessageContaining("URL must not be empty");
}
@Test
public void urlMustNotBeEmpty() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("URL must not be empty");
new ClassPathChangeUploader("", this.requestFactory);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassPathChangeUploader("", this.requestFactory))
.withMessageContaining("URL must not be empty");
}
@Test
public void requestFactoryMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("RequestFactory must not be null");
new ClassPathChangeUploader("http://localhost:8080", null);
assertThatIllegalArgumentException()
.isThrownBy(
() -> new ClassPathChangeUploader("http://localhost:8080", null))
.withMessageContaining("RequestFactory must not be null");
}
@Test
public void urlMustNotBeMalformed() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Malformed URL 'htttttp:///ttest'");
new ClassPathChangeUploader("htttttp:///ttest", this.requestFactory);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassPathChangeUploader("htttttp:///ttest",
this.requestFactory))
.withMessageContaining("Malformed URL 'htttttp:///ttest'");
}
@Test

View File

@@ -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.
@@ -20,9 +20,7 @@ import java.io.IOException;
import java.net.URI;
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;
@@ -34,6 +32,7 @@ import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpResponse;
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.never;
import static org.mockito.Mockito.verify;
@@ -47,9 +46,6 @@ public class DelayedLiveReloadTriggerTests {
private static final String URL = "http://localhost:8080";
@Rule
public ExpectedException thrown = ExpectedException.none();
@Mock
private OptionalLiveReloadServer liveReloadServer;
@@ -84,30 +80,32 @@ public class DelayedLiveReloadTriggerTests {
@Test
public void liveReloadServerMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("LiveReloadServer must not be null");
new DelayedLiveReloadTrigger(null, this.requestFactory, URL);
assertThatIllegalArgumentException().isThrownBy(
() -> new DelayedLiveReloadTrigger(null, this.requestFactory, URL))
.withMessageContaining("LiveReloadServer must not be null");
}
@Test
public void requestFactoryMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("RequestFactory must not be null");
new DelayedLiveReloadTrigger(this.liveReloadServer, null, URL);
assertThatIllegalArgumentException().isThrownBy(
() -> new DelayedLiveReloadTrigger(this.liveReloadServer, null, URL))
.withMessageContaining("RequestFactory must not be null");
}
@Test
public void urlMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("URL must not be empty");
new DelayedLiveReloadTrigger(this.liveReloadServer, this.requestFactory, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new DelayedLiveReloadTrigger(this.liveReloadServer,
this.requestFactory, null))
.withMessageContaining("URL must not be empty");
}
@Test
public void urlMustNotBeEmpty() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("URL must not be empty");
new DelayedLiveReloadTrigger(this.liveReloadServer, this.requestFactory, "");
assertThatIllegalArgumentException()
.isThrownBy(() -> new DelayedLiveReloadTrigger(this.liveReloadServer,
this.requestFactory, ""))
.withMessageContaining("URL must not be empty");
}
@Test

View File

@@ -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.devtools.remote.client;
import java.io.IOException;
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;
@@ -32,6 +30,7 @@ import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.mock.web.MockHttpServletRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.given;
/**
@@ -42,9 +41,6 @@ import static org.mockito.BDDMockito.given;
*/
public class HttpHeaderInterceptorTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private String name;
private String value;
@@ -77,30 +73,30 @@ public class HttpHeaderInterceptorTests {
@Test
public void constructorNullHeaderName() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Name must not be empty");
new HttpHeaderInterceptor(null, this.value);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpHeaderInterceptor(null, this.value))
.withMessageContaining("Name must not be empty");
}
@Test
public void constructorEmptyHeaderName() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Name must not be empty");
new HttpHeaderInterceptor("", this.value);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpHeaderInterceptor("", this.value))
.withMessageContaining("Name must not be empty");
}
@Test
public void constructorNullHeaderValue() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Value must not be empty");
new HttpHeaderInterceptor(this.name, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpHeaderInterceptor(this.name, null))
.withMessageContaining("Value must not be empty");
}
@Test
public void constructorEmptyHeaderValue() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Value must not be empty");
new HttpHeaderInterceptor(this.name, "");
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpHeaderInterceptor(this.name, ""))
.withMessageContaining("Value must not be empty");
}
@Test

View File

@@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -49,6 +48,7 @@ import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -67,9 +67,6 @@ public class RemoteClientConfigurationTests {
@Rule
public OutputCapture output = new OutputCapture();
@Rule
public ExpectedException thrown = ExpectedException.none();
private AnnotationConfigServletWebServerApplicationContext context;
private AnnotationConfigApplicationContext clientContext;
@@ -104,9 +101,9 @@ public class RemoteClientConfigurationTests {
@Test
public void failIfNoSecret() {
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("required to secure your connection");
configure("http://localhost", false);
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> configure("http://localhost", false))
.withMessageContaining("required to secure your connection");
}
@Test
@@ -126,15 +123,15 @@ public class RemoteClientConfigurationTests {
@Test
public void liveReloadDisabled() {
configure("spring.devtools.livereload.enabled:false");
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean(OptionalLiveReloadServer.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(OptionalLiveReloadServer.class));
}
@Test
public void remoteRestartDisabled() {
configure("spring.devtools.remote.restart.enabled:false");
this.thrown.expect(NoSuchBeanDefinitionException.class);
this.context.getBean(ClassPathFileSystemWatcher.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.context.getBean(ClassPathFileSystemWatcher.class));
}
private void configure(String... pairs) {

View File

@@ -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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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;
@@ -39,6 +37,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
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.willReturn;
import static org.mockito.Mockito.mock;
@@ -52,9 +51,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
*/
public class DispatcherFilterTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Mock
private Dispatcher dispatcher;
@@ -77,9 +73,8 @@ public class DispatcherFilterTests {
@Test
public void dispatcherMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Dispatcher must not be null");
new DispatcherFilter(null);
assertThatIllegalArgumentException().isThrownBy(() -> new DispatcherFilter(null))
.withMessageContaining("Dispatcher must not be null");
}
@Test

View File

@@ -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.
@@ -21,9 +21,7 @@ import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -37,6 +35,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
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.inOrder;
@@ -52,9 +51,6 @@ import static org.mockito.Mockito.withSettings;
*/
public class DispatcherTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Mock
private AccessManager accessManager;
@@ -77,16 +73,16 @@ public class DispatcherTests {
@Test
public void accessManagerMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("AccessManager must not be null");
new Dispatcher(null, Collections.emptyList());
assertThatIllegalArgumentException()
.isThrownBy(() -> new Dispatcher(null, Collections.emptyList()))
.withMessageContaining("AccessManager must not be null");
}
@Test
public void mappersMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Mappers must not be null");
new Dispatcher(this.accessManager, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new Dispatcher(this.accessManager, null))
.withMessageContaining("Mappers must not be null");
}
@Test

View File

@@ -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,15 +17,14 @@
package org.springframework.boot.devtools.remote.server;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.mock.web.MockHttpServletRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link HttpHeaderAccessManager}.
@@ -39,9 +38,6 @@ public class HttpHeaderAccessManagerTests {
private static final String SECRET = "password";
@Rule
public ExpectedException thrown = ExpectedException.none();
private MockHttpServletRequest request;
private ServerHttpRequest serverRequest;
@@ -57,30 +53,30 @@ public class HttpHeaderAccessManagerTests {
@Test
public void headerNameMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("HeaderName must not be empty");
new HttpHeaderAccessManager(null, SECRET);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpHeaderAccessManager(null, SECRET))
.withMessageContaining("HeaderName must not be empty");
}
@Test
public void headerNameMustNotBeEmpty() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("HeaderName must not be empty");
new HttpHeaderAccessManager("", SECRET);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpHeaderAccessManager("", SECRET))
.withMessageContaining("HeaderName must not be empty");
}
@Test
public void expectedSecretMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ExpectedSecret must not be empty");
new HttpHeaderAccessManager(HEADER, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpHeaderAccessManager(HEADER, null))
.withMessageContaining("ExpectedSecret must not be empty");
}
@Test
public void expectedSecretMustNotBeEmpty() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ExpectedSecret must not be empty");
new HttpHeaderAccessManager(HEADER, "");
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpHeaderAccessManager(HEADER, ""))
.withMessageContaining("ExpectedSecret must not be empty");
}
@Test

View File

@@ -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.devtools.remote.server;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.ServerHttpRequest;
@@ -30,6 +28,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link HttpStatusHandler}.
@@ -38,9 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class HttpStatusHandlerTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private MockHttpServletRequest servletRequest;
private MockHttpServletResponse servletResponse;
@@ -59,9 +55,8 @@ public class HttpStatusHandlerTests {
@Test
public void statusMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Status must not be null");
new HttpStatusHandler(null);
assertThatIllegalArgumentException().isThrownBy(() -> new HttpStatusHandler(null))
.withMessageContaining("Status must not be null");
}
@Test

View File

@@ -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.
@@ -18,15 +18,14 @@ package org.springframework.boot.devtools.remote.server;
import javax.servlet.http.HttpServletRequest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.mock.web.MockHttpServletRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.mock;
/**
@@ -37,30 +36,27 @@ import static org.mockito.Mockito.mock;
*/
public class UrlHandlerMapperTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private Handler handler = mock(Handler.class);
@Test
public void requestUriMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("URL must not be empty");
new UrlHandlerMapper(null, this.handler);
assertThatIllegalArgumentException()
.isThrownBy(() -> new UrlHandlerMapper(null, this.handler))
.withMessageContaining("URL must not be empty");
}
@Test
public void requestUriMustNotBeEmpty() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("URL must not be empty");
new UrlHandlerMapper("", this.handler);
assertThatIllegalArgumentException()
.isThrownBy(() -> new UrlHandlerMapper("", this.handler))
.withMessageContaining("URL must not be empty");
}
@Test
public void requestUrlMustStartWithSlash() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("URL must start with '/'");
new UrlHandlerMapper("tunnel", this.handler);
assertThatIllegalArgumentException()
.isThrownBy(() -> new UrlHandlerMapper("tunnel", this.handler))
.withMessageContaining("URL must start with '/'");
}
@Test

View File

@@ -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,13 +19,13 @@ package org.springframework.boot.devtools.restart;
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Tests for {@link MainMethod}.
@@ -34,9 +34,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class MainMethodTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private static ThreadLocal<MainMethod> mainMethod = new ThreadLocal<>();
private Method actualMain;
@@ -48,9 +45,8 @@ public class MainMethodTests {
@Test
public void threadMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Thread must not be null");
new MainMethod(null);
assertThatIllegalArgumentException().isThrownBy(() -> new MainMethod(null))
.withMessageContaining("Thread must not be null");
}
@Test
@@ -63,16 +59,16 @@ public class MainMethodTests {
@Test
public void missingArgsMainMethod() throws Exception {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to find main method");
new TestThread(MissingArgs::main).test();
assertThatIllegalStateException()
.isThrownBy(() -> new TestThread(MissingArgs::main).test())
.withMessageContaining("Unable to find main method");
}
@Test
public void nonStatic() throws Exception {
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to find main method");
new TestThread(() -> new NonStaticMain().main()).test();
assertThatIllegalStateException()
.isThrownBy(() -> new TestThread(() -> new NonStaticMain().main()).test())
.withMessageContaining("Unable to find main method");
}
private static class TestThread extends Thread {

View File

@@ -26,7 +26,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile;
@@ -43,6 +42,8 @@ import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
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.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -56,9 +57,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
*/
public class RestarterTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public OutputCapture out = new OutputCapture();
@@ -75,9 +73,8 @@ public class RestarterTests {
@Test
public void cantGetInstanceBeforeInitialize() {
Restarter.clearInstance();
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Restarter has not been initialized");
Restarter.getInstance();
assertThatIllegalStateException().isThrownBy(Restarter::getInstance)
.withMessageContaining("Restarter has not been initialized");
}
@Test
@@ -103,9 +100,9 @@ public class RestarterTests {
@Test
public void addUrlsMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Urls must not be null");
Restarter.getInstance().addUrls(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> Restarter.getInstance().addUrls(null))
.withMessageContaining("Urls must not be null");
}
@Test
@@ -122,9 +119,9 @@ public class RestarterTests {
@Test
public void addClassLoaderFilesMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ClassLoaderFiles must not be null");
Restarter.getInstance().addClassLoaderFiles(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> Restarter.getInstance().addClassLoaderFiles(null))
.withMessageContaining("ClassLoaderFiles must not be null");
}
@Test

View File

@@ -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.devtools.restart.classloader;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link ClassLoaderFile}.
@@ -33,35 +32,32 @@ public class ClassLoaderFileTests {
public static final byte[] BYTES = "ABC".getBytes();
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void kindMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Kind must not be null");
new ClassLoaderFile(null, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassLoaderFile(null, null))
.withMessageContaining("Kind must not be null");
}
@Test
public void addedContentsMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Contents must not be null");
new ClassLoaderFile(Kind.ADDED, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassLoaderFile(Kind.ADDED, null))
.withMessageContaining("Contents must not be null");
}
@Test
public void modifiedContentsMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Contents must not be null");
new ClassLoaderFile(Kind.MODIFIED, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassLoaderFile(Kind.MODIFIED, null))
.withMessageContaining("Contents must not be null");
}
@Test
public void deletedContentsMustBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Contents must be null");
new ClassLoaderFile(Kind.DELETED, new byte[10]);
assertThatIllegalArgumentException()
.isThrownBy(() -> new ClassLoaderFile(Kind.DELETED, new byte[10]))
.withMessageContaining("Contents must be null");
}
@Test

View File

@@ -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,14 +22,13 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Iterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.mock;
/**
@@ -39,23 +38,20 @@ import static org.mockito.Mockito.mock;
*/
public class ClassLoaderFilesTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private ClassLoaderFiles files = new ClassLoaderFiles();
@Test
public void addFileNameMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Name must not be null");
this.files.addFile(null, mock(ClassLoaderFile.class));
assertThatIllegalArgumentException()
.isThrownBy(() -> this.files.addFile(null, mock(ClassLoaderFile.class)))
.withMessageContaining("Name must not be null");
}
@Test
public void addFileFileMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("File must not be null");
this.files.addFile("test", null);
assertThatIllegalArgumentException()
.isThrownBy(() -> this.files.addFile("test", null))
.withMessageContaining("File must not be null");
}
@Test
@@ -161,9 +157,8 @@ public class ClassLoaderFilesTests {
@Test
public void classLoaderFilesMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ClassLoaderFiles must not be null");
new ClassLoaderFiles(null);
assertThatIllegalArgumentException().isThrownBy(() -> new ClassLoaderFiles(null))
.withMessageContaining("ClassLoaderFiles must not be null");
}
@Test

View File

@@ -32,7 +32,6 @@ import java.util.zip.ZipEntry;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind;
@@ -40,6 +39,8 @@ import org.springframework.util.FileCopyUtils;
import org.springframework.util.StreamUtils;
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 RestartClassLoader}.
@@ -54,9 +55,6 @@ public class RestartClassLoaderTests {
private static final String PACKAGE_PATH = PACKAGE.replace('.', '/');
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@@ -95,16 +93,16 @@ public class RestartClassLoaderTests {
@Test
public void parentMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Parent must not be null");
new RestartClassLoader(null, new URL[] {});
assertThatIllegalArgumentException()
.isThrownBy(() -> new RestartClassLoader(null, new URL[] {}))
.withMessageContaining("Parent must not be null");
}
@Test
public void updatedFilesMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("UpdatedFiles must not be null");
new RestartClassLoader(this.parentClassLoader, new URL[] {}, null);
assertThatIllegalArgumentException().isThrownBy(
() -> new RestartClassLoader(this.parentClassLoader, new URL[] {}, null))
.withMessageContaining("UpdatedFiles must not be null");
}
@Test
@@ -185,16 +183,16 @@ public class RestartClassLoaderTests {
public void getDeletedClass() throws Exception {
String name = PACKAGE_PATH + "/Sample.class";
this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.DELETED, null));
this.thrown.expect(ClassNotFoundException.class);
this.reloadClassLoader.loadClass(PACKAGE + ".Sample");
assertThatExceptionOfType(ClassNotFoundException.class)
.isThrownBy(() -> this.reloadClassLoader.loadClass(PACKAGE + ".Sample"));
}
@Test
public void getUpdatedClass() throws Exception {
String name = PACKAGE_PATH + "/Sample.class";
this.updatedFiles.addFile(name, new ClassLoaderFile(Kind.MODIFIED, new byte[10]));
this.thrown.expect(ClassFormatError.class);
this.reloadClassLoader.loadClass(PACKAGE + ".Sample");
assertThatExceptionOfType(ClassFormatError.class)
.isThrownBy(() -> this.reloadClassLoader.loadClass(PACKAGE + ".Sample"));
}
@Test

View File

@@ -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.devtools.restart.server;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -33,14 +32,11 @@ import static org.mockito.Mockito.verify;
*/
public class HttpRestartServerHandlerTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void serverMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Server must not be null");
new HttpRestartServerHandler(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpRestartServerHandler(null))
.withMessageContaining("Server must not be null");
}
@Test

View File

@@ -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.
@@ -21,9 +21,7 @@ import java.io.IOException;
import java.io.ObjectOutputStream;
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;
@@ -38,6 +36,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
@@ -48,9 +47,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
*/
public class HttpRestartServerTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Mock
private RestartServer delegate;
@@ -67,16 +63,16 @@ public class HttpRestartServerTests {
@Test
public void sourceFolderUrlFilterMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("SourceFolderUrlFilter must not be null");
new HttpRestartServer((SourceFolderUrlFilter) null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpRestartServer((SourceFolderUrlFilter) null))
.withMessageContaining("SourceFolderUrlFilter must not be null");
}
@Test
public void restartServerMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("RestartServer must not be null");
new HttpRestartServer((RestartServer) null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpRestartServer((RestartServer) null))
.withMessageContaining("RestartServer must not be null");
}
@Test

View File

@@ -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.
@@ -26,7 +26,6 @@ import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile;
@@ -35,6 +34,7 @@ import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link RestartServer}.
@@ -43,17 +43,14 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class RestartServerTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Test
public void sourceFolderUrlFilterMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("SourceFolderUrlFilter must not be null");
new RestartServer((SourceFolderUrlFilter) null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new RestartServer((SourceFolderUrlFilter) null))
.withMessageContaining("SourceFolderUrlFilter must not be null");
}
@Test

View File

@@ -28,7 +28,6 @@ import java.util.concurrent.Executor;
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;
@@ -38,6 +37,7 @@ import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.http.HttpStatus;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -52,9 +52,6 @@ import static org.mockito.Mockito.verify;
*/
public class HttpTunnelConnectionTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public OutputCapture outputCapture = new OutputCapture();
@@ -79,30 +76,30 @@ public class HttpTunnelConnectionTests {
@Test
public void urlMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("URL must not be empty");
new HttpTunnelConnection(null, this.requestFactory);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpTunnelConnection(null, this.requestFactory))
.withMessageContaining("URL must not be empty");
}
@Test
public void urlMustNotBeEmpty() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("URL must not be empty");
new HttpTunnelConnection("", this.requestFactory);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpTunnelConnection("", this.requestFactory))
.withMessageContaining("URL must not be empty");
}
@Test
public void urlMustNotBeMalformed() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Malformed URL 'htttttp:///ttest'");
new HttpTunnelConnection("htttttp:///ttest", this.requestFactory);
assertThatIllegalArgumentException().isThrownBy(
() -> new HttpTunnelConnection("htttttp:///ttest", this.requestFactory))
.withMessageContaining("Malformed URL 'htttttp:///ttest'");
}
@Test
public void requestFactoryMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("RequestFactory must not be null");
new HttpTunnelConnection(this.url, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpTunnelConnection(this.url, null))
.withMessageContaining("RequestFactory must not be null");
}
@Test

View File

@@ -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.
@@ -25,11 +25,10 @@ import java.nio.channels.Channels;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
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.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -41,23 +40,19 @@ import static org.mockito.Mockito.verify;
*/
public class TunnelClientTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private MockTunnelConnection tunnelConnection = new MockTunnelConnection();
@Test
public void listenPortMustNotBeNegative() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ListenPort must be greater than or equal to 0");
new TunnelClient(-5, this.tunnelConnection);
assertThatIllegalArgumentException()
.isThrownBy(() -> new TunnelClient(-5, this.tunnelConnection))
.withMessageContaining("ListenPort must be greater than or equal to 0");
}
@Test
public void tunnelConnectionMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("TunnelConnection must not be null");
new TunnelClient(1, null);
assertThatIllegalArgumentException().isThrownBy(() -> new TunnelClient(1, null))
.withMessageContaining("TunnelConnection must not be null");
}
@Test

View File

@@ -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.
@@ -21,11 +21,11 @@ import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
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.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Tests for {@link HttpTunnelPayloadForwarder}.
@@ -34,14 +34,11 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class HttpTunnelPayloadForwarderTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void targetChannelMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("TargetChannel must not be null");
new HttpTunnelPayloadForwarder(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpTunnelPayloadForwarder(null))
.withMessageContaining("TargetChannel must not be null");
}
@Test
@@ -70,11 +67,11 @@ public class HttpTunnelPayloadForwarderTests {
public void overflow() throws Exception {
WritableByteChannel channel = Channels.newChannel(new ByteArrayOutputStream());
HttpTunnelPayloadForwarder forwarder = new HttpTunnelPayloadForwarder(channel);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Too many messages queued");
for (int i = 2; i < 130; i++) {
forwarder.forward(payload(i, "data" + i));
}
assertThatIllegalStateException().isThrownBy(() -> {
for (int i = 2; i < 130; i++) {
forwarder.forward(payload(i, "data" + i));
}
}).withMessageContaining("Too many messages queued");
}
private HttpTunnelPayload payload(long sequence, String data) {

View File

@@ -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.
@@ -25,9 +25,7 @@ import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
@@ -37,6 +35,8 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
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.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -48,21 +48,18 @@ import static org.mockito.Mockito.mock;
*/
public class HttpTunnelPayloadTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void sequenceMustBePositive() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Sequence must be positive");
new HttpTunnelPayload(0, ByteBuffer.allocate(1));
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpTunnelPayload(0, ByteBuffer.allocate(1)))
.withMessageContaining("Sequence must be positive");
}
@Test
public void dataMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Data must not be null");
new HttpTunnelPayload(1, null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpTunnelPayload(1, null))
.withMessageContaining("Data must not be null");
}
@Test
@@ -102,9 +99,8 @@ public class HttpTunnelPayloadTests {
MockHttpServletRequest servletRequest = new MockHttpServletRequest();
servletRequest.setContent("hello".getBytes());
HttpInputMessage request = new ServletServerHttpRequest(servletRequest);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Missing sequence header");
HttpTunnelPayload.get(request);
assertThatIllegalStateException().isThrownBy(() -> HttpTunnelPayload.get(request))
.withMessageContaining("Missing sequence header");
}
@Test

View File

@@ -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.devtools.tunnel.server;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -33,14 +32,11 @@ import static org.mockito.Mockito.verify;
*/
public class HttpTunnelServerHandlerTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void serverMustNotBeNull() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Server must not be null");
new HttpTunnelServerHandler(null);
assertThatIllegalArgumentException()
.isThrownBy(() -> new HttpTunnelServerHandler(null))
.withMessageContaining("Server must not be null");
}
@Test

View File

@@ -28,9 +28,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
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;
@@ -46,6 +44,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -66,9 +65,6 @@ public class HttpTunnelServerTests {
private static final String SEQ_HEADER = "x-seq";
@Rule
public ExpectedException thrown = ExpectedException.none();
private HttpTunnelServer server;
@Mock
@@ -103,9 +99,8 @@ public class HttpTunnelServerTests {
@Test
public void serverConnectionIsRequired() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("ServerConnection must not be null");
new HttpTunnelServer(null);
assertThatIllegalArgumentException().isThrownBy(() -> new HttpTunnelServer(null))
.withMessageContaining("ServerConnection must not be null");
}
@Test
@@ -124,9 +119,9 @@ public class HttpTunnelServerTests {
@Test
public void longPollTimeoutMustBePositiveValue() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("LongPollTimeout must be a positive value");
this.server.setLongPollTimeout(0);
assertThatIllegalArgumentException()
.isThrownBy(() -> this.server.setLongPollTimeout(0))
.withMessageContaining("LongPollTimeout must be a positive value");
}
@Test
@@ -257,9 +252,9 @@ public class HttpTunnelServerTests {
@Test
public void disconnectTimeoutMustBePositive() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("DisconnectTimeout must be a positive value");
this.server.setDisconnectTimeout(0);
assertThatIllegalArgumentException()
.isThrownBy(() -> this.server.setDisconnectTimeout(0))
.withMessageContaining("DisconnectTimeout must be a positive value");
}
@Test

View File

@@ -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,11 +16,10 @@
package org.springframework.boot.devtools.tunnel.server;
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.assertThatIllegalArgumentException;
/**
* Tests for {@link StaticPortProvider}.
@@ -29,14 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class StaticPortProviderTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void portMustBePositive() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Port must be positive");
new StaticPortProvider(0);
assertThatIllegalArgumentException().isThrownBy(() -> new StaticPortProvider(0))
.withMessageContaining("Port must be positive");
}
@Test