Remove unnecessary throws declaration in tests

See gh-26441
This commit is contained in:
weixsun
2021-05-13 00:22:53 +08:00
committed by Stephane Nicoll
parent 574655dc84
commit 8a2be288a3
129 changed files with 345 additions and 369 deletions

View File

@@ -53,7 +53,7 @@ class BuildpackResolversTests extends AbstractJsonTests {
}
@Test
void resolveAllWithBuilderBuildpackReferenceReturnsExpectedBuildpack() throws IOException {
void resolveAllWithBuilderBuildpackReferenceReturnsExpectedBuildpack() {
BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:paketo-buildpacks/spring-boot@3.5.0");
Buildpacks buildpacks = BuildpackResolvers.resolveAll(this.resolverContext, Collections.singleton(reference));
assertThat(buildpacks.getBuildpacks()).hasSize(1);
@@ -92,7 +92,7 @@ class BuildpackResolversTests extends AbstractJsonTests {
}
@Test
void resolveAllWithInvalidLocatorThrowsException() throws IOException {
void resolveAllWithInvalidLocatorThrowsException() {
BuildpackReference reference = BuildpackReference.of("unknown-buildpack@0.0.1");
assertThatIllegalArgumentException()
.isThrownBy(() -> BuildpackResolvers.resolveAll(this.resolverContext, Collections.singleton(reference)))

View File

@@ -105,7 +105,7 @@ class ImageBuildpackTests extends AbstractJsonTests {
}
@Test
void resolveWhenFullyQualifiedReferenceWithInvalidImageReferenceThrowsException() throws Exception {
void resolveWhenFullyQualifiedReferenceWithInvalidImageReferenceThrowsException() {
BuildpackReference reference = BuildpackReference.of("docker://buildpack@0.0.1");
BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
assertThatIllegalArgumentException().isThrownBy(() -> ImageBuildpack.resolve(resolverContext, reference))
@@ -113,7 +113,7 @@ class ImageBuildpackTests extends AbstractJsonTests {
}
@Test
void resolveWhenUnqualifiedReferenceWithInvalidImageReferenceReturnsNull() throws Exception {
void resolveWhenUnqualifiedReferenceWithInvalidImageReferenceReturnsNull() {
BuildpackReference reference = BuildpackReference.of("buildpack@0.0.1");
BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -41,7 +41,7 @@ class MappedObjectTests extends AbstractJsonTests {
}
@Test
void ofReadsJson() throws Exception {
void ofReadsJson() {
assertThat(this.mapped.getNode()).isNotNull();
}

View File

@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
class ConfigurationMetadataRepositoryJsonBuilderTests extends AbstractConfigurationMetadataTests {
@Test
void nullResource() throws IOException {
void nullResource() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ConfigurationMetadataRepositoryJsonBuilder.create().withJsonResource(null));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -46,7 +46,7 @@ class JsonReaderTests extends AbstractConfigurationMetadataTests {
}
@Test
void invalidMetadata() throws IOException {
void invalidMetadata() {
assertThatIllegalStateException().isThrownBy(() -> readFor("invalid")).withCauseInstanceOf(JSONException.class);
}

View File

@@ -243,7 +243,7 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
}
@Test
void parseArrayConfig() throws Exception {
void parseArrayConfig() {
ConfigurationMetadata metadata = compile(SimpleArrayProperties.class);
assertThat(metadata).has(Metadata.withGroup("array").ofType(SimpleArrayProperties.class));
assertThat(metadata).has(Metadata.withProperty("array.primitive", "java.lang.Integer[]"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -41,14 +41,14 @@ class IntegratingWithActuatorDocumentationTests {
GradleBuild gradleBuild;
@TestTemplate
void basicBuildInfo() throws IOException {
void basicBuildInfo() {
this.gradleBuild.script("src/docs/gradle/integrating-with-actuator/build-info-basic").build("bootBuildInfo");
assertThat(new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties"))
.isFile();
}
@TestTemplate
void buildInfoCustomValues() throws IOException {
void buildInfoCustomValues() {
this.gradleBuild.script("src/docs/gradle/integrating-with-actuator/build-info-custom-values")
.build("bootBuildInfo");
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");
@@ -61,7 +61,7 @@ class IntegratingWithActuatorDocumentationTests {
}
@TestTemplate
void buildInfoAdditional() throws IOException {
void buildInfoAdditional() {
this.gradleBuild.script("src/docs/gradle/integrating-with-actuator/build-info-additional")
.build("bootBuildInfo");
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");

View File

@@ -16,8 +16,6 @@
package org.springframework.boot.gradle.docs;
import java.io.IOException;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
@@ -41,14 +39,14 @@ class PublishingDocumentationTests {
@DisabledForJreRange(min = JRE.JAVA_16)
@TestTemplate
void mavenUpload() throws IOException {
void mavenUpload() {
assertThat(this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("5.6")
.script("src/docs/gradle/publishing/maven").build("deployerRepository").getOutput())
.contains("https://repo.example.com");
}
@TestTemplate
void mavenPublish() throws IOException {
void mavenPublish() {
assertThat(this.gradleBuild.script("src/docs/gradle/publishing/maven-publish").build("publishingConfiguration")
.getOutput()).contains("MavenPublication").contains("https://repo.example.com");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -65,25 +65,25 @@ class RunningDocumentationTests {
}
@TestTemplate
void bootRunSourceResources() throws IOException {
void bootRunSourceResources() {
assertThat(this.gradleBuild.script("src/docs/gradle/running/boot-run-source-resources")
.build("configuredClasspath").getOutput()).contains(new File("src/main/resources").getPath());
}
@TestTemplate
void bootRunDisableOptimizedLaunch() throws IOException {
void bootRunDisableOptimizedLaunch() {
assertThat(this.gradleBuild.script("src/docs/gradle/running/boot-run-disable-optimized-launch")
.build("optimizedLaunch").getOutput()).contains("false");
}
@TestTemplate
void bootRunSystemPropertyDefaultValue() throws IOException {
void bootRunSystemPropertyDefaultValue() {
assertThat(this.gradleBuild.script("src/docs/gradle/running/boot-run-system-property")
.build("configuredSystemProperties").getOutput()).contains("com.example.property = default");
}
@TestTemplate
void bootRunSystemPropetry() throws IOException {
void bootRunSystemPropetry() {
assertThat(this.gradleBuild.script("src/docs/gradle/running/boot-run-system-property")
.build("-Pexample=custom", "configuredSystemProperties").getOutput())
.contains("com.example.property = custom");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -42,7 +42,7 @@ class BuildInfoDslIntegrationTests {
GradleBuild gradleBuild;
@TestTemplate
void basicJar() throws IOException {
void basicJar() {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
@@ -53,7 +53,7 @@ class BuildInfoDslIntegrationTests {
}
@TestTemplate
void jarWithCustomName() throws IOException {
void jarWithCustomName() {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
@@ -64,7 +64,7 @@ class BuildInfoDslIntegrationTests {
}
@TestTemplate
void basicWar() throws IOException {
void basicWar() {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
@@ -75,7 +75,7 @@ class BuildInfoDslIntegrationTests {
}
@TestTemplate
void warWithCustomName() throws IOException {
void warWithCustomName() {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
@@ -86,7 +86,7 @@ class BuildInfoDslIntegrationTests {
}
@TestTemplate
void additionalProperties() throws IOException {
void additionalProperties() {
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
Properties properties = buildInfoProperties();
@@ -99,7 +99,7 @@ class BuildInfoDslIntegrationTests {
}
@TestTemplate
void classesDependency() throws IOException {
void classesDependency() {
assertThat(this.gradleBuild.build("classes", "--stacktrace").task(":bootBuildInfo").getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
}

View File

@@ -92,7 +92,7 @@ class BuildInfoIntegrationTests {
}
@TestTemplate
void notUpToDateWhenExecutedTwiceWithFixedTimeAndChangedProjectVersion() throws IOException {
void notUpToDateWhenExecutedTwiceWithFixedTimeAndChangedProjectVersion() {
assertThat(this.gradleBuild.scriptProperty("projectVersion", "0.1.0").build("buildInfo").task(":buildInfo")
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.scriptProperty("projectVersion", "0.2.0").build("buildInfo").task(":buildInfo")

View File

@@ -86,7 +86,7 @@ abstract class AbstractBootArchiveIntegrationTests {
}
@TestTemplate
void basicBuild() throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException {
void basicBuild() {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
}
@@ -106,7 +106,7 @@ abstract class AbstractBootArchiveIntegrationTests {
}
@TestTemplate
void upToDateWhenBuiltTwice() throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException {
void upToDateWhenBuiltTwice() {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
@@ -114,8 +114,7 @@ abstract class AbstractBootArchiveIntegrationTests {
}
@TestTemplate
void upToDateWhenBuiltTwiceWithLaunchScriptIncluded()
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException {
void upToDateWhenBuiltTwiceWithLaunchScriptIncluded() {
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName).task(":" + this.taskName)
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName).task(":" + this.taskName)
@@ -167,7 +166,7 @@ abstract class AbstractBootArchiveIntegrationTests {
}
@TestTemplate
void duplicatesAreHandledGracefully() throws IOException {
void duplicatesAreHandledGracefully() {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
}
@@ -257,7 +256,7 @@ abstract class AbstractBootArchiveIntegrationTests {
}
@TestTemplate
void layersWithCustomSourceSet() throws IOException {
void layersWithCustomSourceSet() {
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
}

View File

@@ -66,7 +66,7 @@ public class BootBuildImageRegistryIntegrationTests {
}
@TestTemplate
void buildsImageAndPublishesToRegistry() throws IOException, InterruptedException {
void buildsImageAndPublishesToRegistry() throws IOException {
writeMainClass();
String repoName = "test-image";
String imageName = this.registryAddress + "/" + repoName;

View File

@@ -17,8 +17,6 @@
package org.springframework.boot.gradle.tasks.bundling;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
@@ -43,7 +41,7 @@ class MavenIntegrationTests {
GradleBuild gradleBuild;
@TestTemplate
void bootJarCanBeUploaded() throws FileNotFoundException, IOException {
void bootJarCanBeUploaded() {
BuildResult result = this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.0.0")
.build("uploadBootArchives");
assertThat(result.task(":uploadBootArchives").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
@@ -53,7 +51,7 @@ class MavenIntegrationTests {
}
@TestTemplate
void bootWarCanBeUploaded() throws IOException {
void bootWarCanBeUploaded() {
BuildResult result = this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("6.0.0")
.build("uploadBootArchives");
assertThat(result.task(":uploadBootArchives").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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,8 +17,6 @@
package org.springframework.boot.gradle.tasks.bundling;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
@@ -41,7 +39,7 @@ class MavenPublishingIntegrationTests {
GradleBuild gradleBuild;
@TestTemplate
void bootJarCanBePublished() throws FileNotFoundException, IOException {
void bootJarCanBePublished() {
BuildResult result = this.gradleBuild.build("publish");
assertThat(result.task(":publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(artifactWithSuffix("jar")).isFile();
@@ -50,7 +48,7 @@ class MavenPublishingIntegrationTests {
}
@TestTemplate
void bootWarCanBePublished() throws IOException {
void bootWarCanBePublished() {
BuildResult result = this.gradleBuild.build("publish");
assertThat(result.task(":publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(artifactWithSuffix("war")).isFile();

View File

@@ -75,7 +75,7 @@ class ExtractCommandTests {
}
@Test
void runExtractsLayers() throws Exception {
void runExtractsLayers() {
given(this.context.getArchiveFile()).willReturn(this.jarFile);
given(this.context.getWorkingDir()).willReturn(this.extract);
this.command.run(Collections.emptyMap(), Collections.emptyList());

View File

@@ -51,7 +51,7 @@ class IndexedLayersTests {
}
@Test
void createWhenIndexFileIsMalformedThrowsException() throws Exception {
void createWhenIndexFileIsMalformedThrowsException() {
assertThatIllegalStateException().isThrownBy(() -> new IndexedLayers("test"))
.withMessage("Layer index file is malformed");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -43,7 +43,7 @@ class FileUtilsTests {
private File originDirectory;
@BeforeEach
void init() throws IOException {
void init() {
this.outputDirectory = new File(this.tempDir, "remove");
this.originDirectory = new File(this.tempDir, "keep");
this.outputDirectory.mkdirs();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -52,7 +52,7 @@ class LayersIndexTests {
}
@Test
void writeToWhenSimpleNamesSortsAlphabetically() throws Exception {
void writeToWhenSimpleNamesSortsAlphabetically() {
LayersIndex index = new LayersIndex(LAYER_A);
index.add(LAYER_A, "cat");
index.add(LAYER_A, "dog");

View File

@@ -42,7 +42,7 @@ class ClassPathIndexFileTests {
File temp;
@Test
void loadIfPossibleWhenRootIsNotFileReturnsNull() throws IOException {
void loadIfPossibleWhenRootIsNotFileReturnsNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ClassPathIndexFile.loadIfPossible(new URL("https://example.com/file"), "test.idx"))
.withMessage("URL does not reference a file");
@@ -95,7 +95,7 @@ class ClassPathIndexFileTests {
}
}
private ClassPathIndexFile copyAndLoadTestIndexFile() throws IOException, MalformedURLException {
private ClassPathIndexFile copyAndLoadTestIndexFile() throws IOException {
copyTestIndexFile();
ClassPathIndexFile indexFile = ClassPathIndexFile.loadIfPossible(this.temp.toURI().toURL(), "test.idx");
return indexFile;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -401,7 +401,7 @@ class PropertiesLauncherTests {
assertThat(bytes).isNotEmpty();
}
private void waitFor(String value) throws Exception {
private void waitFor(String value) {
Awaitility.waitAtMost(Duration.ofSeconds(5)).until(this.output::toString, containsString(value));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -96,23 +96,23 @@ class RandomAccessDataFileTests {
}
@Test
void readWhenOffsetIsBeyondEOFShouldThrowException() throws Exception {
void readWhenOffsetIsBeyondEOFShouldThrowException() {
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.read(257, 0));
}
@Test
void readWhenOffsetIsBeyondEndOfSubsectionShouldThrowException() throws Exception {
void readWhenOffsetIsBeyondEndOfSubsectionShouldThrowException() {
RandomAccessData subsection = this.file.getSubsection(0, 10);
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> subsection.read(11, 0));
}
@Test
void readWhenOffsetPlusLengthGreaterThanEOFShouldThrowException() throws Exception {
void readWhenOffsetPlusLengthGreaterThanEOFShouldThrowException() {
assertThatExceptionOfType(EOFException.class).isThrownBy(() -> this.file.read(256, 1));
}
@Test
void readWhenOffsetPlusLengthGreaterThanEndOfSubsectionShouldThrowException() throws Exception {
void readWhenOffsetPlusLengthGreaterThanEndOfSubsectionShouldThrowException() {
RandomAccessData subsection = this.file.getSubsection(0, 10);
assertThatExceptionOfType(EOFException.class).isThrownBy(() -> subsection.read(10, 1));
}
@@ -125,13 +125,13 @@ class RandomAccessDataFileTests {
}
@Test
void inputStreamReadNullBytes() throws Exception {
void inputStreamReadNullBytes() {
assertThatNullPointerException().isThrownBy(() -> this.inputStream.read(null))
.withMessage("Bytes must not be null");
}
@Test
void inputStreamReadNullBytesWithOffset() throws Exception {
void inputStreamReadNullBytesWithOffset() {
assertThatNullPointerException().isThrownBy(() -> this.inputStream.read(null, 0, 1))
.withMessage("Bytes must not be null");
}