removed superfluous throws in tests

This commit is contained in:
Stefan Spieker committed 2021-05-02 00:16:50 +02:00
1 parent 53823453a2
commit afd748142e
23 files changed
+54 -54

No files matched your search

+1 -1
View File
@@ -269,7 +269,7 @@ public class FilePathTest {
d.zip(NullOutputStream.NULL_OUTPUT_STREAM,"**/*");
}
@Test public void normalization() throws Exception {
@Test public void normalization() {
compare("abc/def\\ghi","abc/def\\ghi"); // allow mixed separators
{// basic '.' trimming
+9 -9
View File
@@ -98,7 +98,7 @@ public class FunctionsTest {
@Test
@PrepareForTest(Stapler.class)
public void testGetActionUrl_absolutePath() throws Exception{
public void testGetActionUrl_absolutePath() {
String contextPath = "/jenkins";
StaplerRequest req = createMockRequest(contextPath);
String[] paths = {
@@ -115,7 +115,7 @@ public class FunctionsTest {
@Test
@PrepareForTest(Stapler.class)
public void testGetActionUrl_relativePath() throws Exception{
public void testGetActionUrl_relativePath() {
String contextPath = "/jenkins";
String itUrl = "iturl/";
StaplerRequest req = createMockRequest(contextPath);
@@ -134,7 +134,7 @@ public class FunctionsTest {
@Test
@PrepareForTest({Stapler.class, Jenkins.class})
public void testGetRelativeLinkTo_JobContainedInView() throws Exception{
public void testGetRelativeLinkTo_JobContainedInView() {
Jenkins j = createMockJenkins();
ItemGroup parent = j;
String contextPath = "/jenkins";
@@ -153,7 +153,7 @@ public class FunctionsTest {
@Test
@PrepareForTest({Stapler.class, Jenkins.class})
public void testGetRelativeLinkTo_JobFromComputer() throws Exception{
public void testGetRelativeLinkTo_JobFromComputer() {
Jenkins j = createMockJenkins();
ItemGroup parent = j;
String contextPath = "/jenkins";
@@ -170,7 +170,7 @@ public class FunctionsTest {
@Ignore("too expensive to make it correct")
@Test
@PrepareForTest({Stapler.class, Jenkins.class})
public void testGetRelativeLinkTo_JobNotContainedInView() throws Exception{
public void testGetRelativeLinkTo_JobNotContainedInView() {
Jenkins j = createMockJenkins();
ItemGroup parent = j;
String contextPath = "/jenkins";
@@ -190,7 +190,7 @@ public class FunctionsTest {
@Test
@PrepareForTest({Stapler.class,Jenkins.class})
public void testGetRelativeLinkTo_JobContainedInViewWithinItemGroup() throws Exception{
public void testGetRelativeLinkTo_JobContainedInViewWithinItemGroup() {
Jenkins j = createMockJenkins();
TopLevelItemAndItemGroup parent = mock(TopLevelItemAndItemGroup.class);
when(parent.getShortUrl()).thenReturn("parent/");
@@ -210,7 +210,7 @@ public class FunctionsTest {
@Issue("JENKINS-17713")
@PrepareForTest({Stapler.class, Jenkins.class})
@Test public void getRelativeLinkTo_MavenModules() throws Exception {
@Test public void getRelativeLinkTo_MavenModules() {
Jenkins j = createMockJenkins();
StaplerRequest req = createMockRequest("/jenkins");
mockStatic(Stapler.class);
@@ -286,7 +286,7 @@ public class FunctionsTest {
@Test
@PrepareForTest(Stapler.class)
public void testGetActionUrl_unparseable() throws Exception{
public void testGetActionUrl_unparseable() {
assertNull(Functions.getActionUrl(null, createMockAction("http://example.net/stuff?something=^woohoo")));
}
@@ -351,7 +351,7 @@ public class FunctionsTest {
}
@Issue("JENKINS-20800")
@Test public void printLogRecordHtml() throws Exception {
@Test public void printLogRecordHtml() {
LogRecord lr = new LogRecord(Level.INFO, "Bad input <xml/>");
lr.setLoggerName("test");
assertEquals("Bad input &lt;xml/&gt;\n", Functions.printLogRecordHtml(lr, null)[3]);
+2 -2
View File
@@ -102,7 +102,7 @@ public class LauncherTest {
}
@Issue("JENKINS-18368")
@Test public void decoratedByEnvMaintainsIsUnix() throws Exception {
@Test public void decoratedByEnvMaintainsIsUnix() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
TaskListener listener = new StreamBuildListener(output);
Launcher remoteLauncher = new Launcher.RemoteLauncher(listener, FilePath.localChannel, false);
@@ -114,7 +114,7 @@ public class LauncherTest {
}
@Issue("JENKINS-18368")
@Test public void decoratedByPrefixMaintainsIsUnix() throws Exception {
@Test public void decoratedByPrefixMaintainsIsUnix() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
TaskListener listener = new StreamBuildListener(output);
Launcher remoteLauncher = new Launcher.RemoteLauncher(listener, FilePath.localChannel, false);
@@ -56,7 +56,7 @@ public class AbstractItemTest {
}
@Test
public void testSearchNameIsName() throws Exception {
public void testSearchNameIsName() {
final String name = "the item name jlrtlekjtekrjkjr";
StubAbstractItem i = new StubAbstractItem();
i.doSetName(name);
@@ -496,7 +496,7 @@ public class FingerprintTest {
return msg.isEmpty();
}
else {
return msg.isEmpty() ? false : e.getMessage().contains(msg);
return !msg.isEmpty() && e.getMessage().contains(msg);
}
}
}
@@ -10,7 +10,7 @@ class TestUserIdMapper extends UserIdMapper {
private File usersDirectory;
private IdStrategy idStrategy;
TestUserIdMapper(File usersDirectory, IdStrategy idStrategy) throws IOException {
TestUserIdMapper(File usersDirectory, IdStrategy idStrategy) {
this.usersDirectory = usersDirectory;
this.idStrategy = idStrategy;
}
@@ -295,7 +295,7 @@ public class UserIdMapperTest {
}
@Test
public void testXmlFileCorrupted() throws IOException {
public void testXmlFileCorrupted() {
assertThrows(IOException.class, () -> createUserIdMapper(IdStrategy.CASE_INSENSITIVE));
}
@@ -83,7 +83,7 @@ public class ViewTest {
* Get all items recursively when View implements ViewGroup at the same time
*/
@Test
public void getAllItems() throws Exception {
public void getAllItems() {
final View leftView = Mockito.mock(View.class);
final View rightView = Mockito.mock(View.class);
@@ -254,7 +254,7 @@ public class ViewTest {
}
@Override
public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) {
return null;
}
}
@@ -74,13 +74,13 @@ public class SCMListenerTest {
}
private static class L1 extends L {
@Override public void onChangeLogParsed(AbstractBuild<?,?> build, BuildListener listener, ChangeLogSet<?> changelog) throws Exception {
@Override public void onChangeLogParsed(AbstractBuild<?,?> build, BuildListener listener, ChangeLogSet<?> changelog) {
cnt++;
}
}
private static class L2 extends L {
@Override public void onChangeLogParsed(Run<?,?> build, SCM scm, TaskListener listener, ChangeLogSet<?> changelog) throws Exception {
@Override public void onChangeLogParsed(Run<?,?> build, SCM scm, TaskListener listener, ChangeLogSet<?> changelog) {
cnt++;
}
}
@@ -92,4 +92,4 @@ public class SCMListenerTest {
}
}
}
}
@@ -288,7 +288,7 @@ public class CronTabTest {
new CronTab("H(0-59) H(0-23) H(1-31) H(1-12) H(0-7)");
}
@Test public void rangeBoundsCheckFailHour() throws Exception {
@Test public void rangeBoundsCheckFailHour() {
try {
new CronTab("H H(12-24) * * *");
fail();
@@ -297,7 +297,7 @@ public class CronTabTest {
}
}
@Test public void rangeBoundsCheckFailMinute() throws Exception {
@Test public void rangeBoundsCheckFailMinute() {
try {
new CronTab("H(33-66) * * * *");
fail();
@@ -35,7 +35,7 @@ public class DescribableListTest {
@Issue("JENKINS-49054")
@Test
public void exceptionDuringUnmarshalling() throws Exception {
public void exceptionDuringUnmarshalling() {
Data data = new Data();
data.list.add(new Datum(1));
data.list.add(new Datum(2));
@@ -34,7 +34,7 @@ public class GraphTest {
public static final int DEFAULT_H = 300;
@Test
public void testDimensions() throws Exception {
public void testDimensions() {
final Dimension keep = Graph.safeDimension(Graph.MAX_AREA/1_000, 1000, DEFAULT_W, DEFAULT_H);
Assert.assertEquals(Graph.MAX_AREA/1_000, keep.width);
Assert.assertEquals(1_000, keep.height);
@@ -32,7 +32,7 @@ import org.junit.Test;
public class MultipartFormDataParserTest {
@Test
public void testIsMultipart() throws Exception {
public void testIsMultipart() {
Assert.assertFalse("Wrongly identified \"multipart/form-data\"", MultipartFormDataParser.isMultiPartForm(null));
Assert.assertFalse("Wrongly identified \"multipart/form-data\"", MultipartFormDataParser.isMultiPartForm("blah"));
@@ -47,7 +47,7 @@ public class RetrierTest {
// Begin the process
Boolean finalResult = r.start();
Assert.assertTrue(finalResult == null ? false : finalResult);
Assert.assertTrue(finalResult != null && finalResult);
String text = Messages.Retrier_Success(ACTION, SUCCESSFUL_ATTEMPT);
assertTrue(String.format("The log should contain '%s'", text), handler.getView().stream().anyMatch(m -> m.getMessage().contains(text)));
@@ -100,7 +100,7 @@ public class RetrierTest {
Assert.assertTrue(timeElapsed >= SLEEP);
// Check result is true
Assert.assertTrue(finalResult == null ? false : finalResult);
Assert.assertTrue(finalResult != null && finalResult);
// Check the log tell us the sleep time
String text = Messages.Retrier_Sleeping(SLEEP, ACTION);
@@ -142,7 +142,7 @@ public class RetrierTest {
// Begin the process
Boolean finalResult = r.start();
Assert.assertFalse(finalResult == null ? false : finalResult);
Assert.assertFalse(finalResult != null && finalResult);
String text = Messages.Retrier_NoSuccess(ACTION, ATTEMPTS);
assertTrue(String.format("The log should contain '%s'", text), handler.getView().stream().anyMatch(m -> m.getMessage().contains(text)));
@@ -221,7 +221,7 @@ public class RetrierTest {
// Begin the process catching the allowed exception
Boolean finalResult = r.start();
Assert.assertTrue(finalResult == null ? false : finalResult);
Assert.assertTrue(finalResult != null && finalResult);
// The action was a success
String textSuccess = Messages.Retrier_Success(ACTION, ATTEMPTS);
@@ -265,7 +265,7 @@ public class RetrierTest {
// Begin the process catching the allowed exception
Boolean finalResult = r.start();
Assert.assertTrue(finalResult == null ? false : finalResult);
Assert.assertTrue(finalResult != null && finalResult);
// The action was a success
String textSuccess = Messages.Retrier_Success(ACTION, ATTEMPTS);
@@ -70,7 +70,7 @@ public class RobustReflectionConverterTest {
}
@Test
public void classOwnership() throws Exception {
public void classOwnership() {
XStream xs = new XStream2(new XStream2.ClassOwnership() {
@Override public String ownerOf(Class<?> clazz) {
Owner o = clazz.getAnnotation(Owner.class);
@@ -8,7 +8,7 @@ public class SecretUtilTest {
@Issue("JENKINS-47500")
@Test
public void decrypt() throws Exception {
public void decrypt() {
String data = "{}";
try {
@@ -23,7 +23,7 @@ public class SecretUtilTest {
@Issue("JENKINS-47500")
@Test
public void decryptJustSpace() throws Exception {
public void decryptJustSpace() {
String data = " ";
try {
@@ -37,7 +37,7 @@ public class SecretUtilTest {
@Issue("JENKINS-47500")
@Test
public void decryptWithSpace() throws Exception {
public void decryptWithSpace() {
String data = "{ }";
try {
@@ -51,7 +51,7 @@ public class SecretUtilTest {
@Issue("JENKINS-47500")
@Test
public void decryptWithSpaces() throws Exception {
public void decryptWithSpaces() {
String data = "{ }";
try {
@@ -45,7 +45,7 @@ public class JenkinsLocationConfigurationTest {
config = mock(JenkinsLocationConfiguration.class, Mockito.CALLS_REAL_METHODS);
Answer<String> mockVoid = new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
public String answer(InvocationOnMock invocation) {
return "stub";
}
};
@@ -244,7 +244,7 @@ public class AbstractLazyLoadRunMapTest {
}
@Test
public void eagerLoading() throws IOException {
public void eagerLoading() {
Map.Entry[] b = a.entrySet().toArray(new Map.Entry[3]);
((Build)b[0].getValue()).asserts(5);
((Build)b[1].getValue()).asserts(3);
@@ -41,7 +41,7 @@ public class RedactSecretJsonInErrorMessageSanitizerTest {
}
@Test
public void simpleWithSecret() throws Exception {
public void simpleWithSecret() {
assertRedaction(
"{'a': 'secret', 'b': 'other', '$redact': 'a'}",
"{'a': '[value redacted]', 'b': 'other', '$redact': 'a'}"
@@ -49,7 +49,7 @@ public class RedactSecretJsonInErrorMessageSanitizerTest {
}
@Test
public void singleWithRedactedInArray() throws Exception {
public void singleWithRedactedInArray() {
assertRedaction(
"{'a': 'secret', 'b': 'other', '$redact': ['a']}",
"{'a': '[value redacted]', 'b': 'other', '$redact': ['a']}"
@@ -57,7 +57,7 @@ public class RedactSecretJsonInErrorMessageSanitizerTest {
}
@Test
public void objectRedactedAcceptedButNotProcessed() throws Exception {
public void objectRedactedAcceptedButNotProcessed() {
assertRedaction(
"{'a': 'secret', 'b': 'other', '$redact': {'a': 'a'}}",
"{'a': 'secret', 'b': 'other', '$redact': {'a': 'a'}}"
@@ -65,7 +65,7 @@ public class RedactSecretJsonInErrorMessageSanitizerTest {
}
@Test
public void weirdValuesInRedactedAcceptedButNotProcessed() throws Exception {
public void weirdValuesInRedactedAcceptedButNotProcessed() {
assertRedaction(
"{'a': 'secret', 'b': 'other', '$redact': [null, true, false, 1, 2, 'a']}",
"{'a': '[value redacted]', 'b': 'other', '$redact': [null, true, false, 1, 2, 'a']}"
@@ -73,7 +73,7 @@ public class RedactSecretJsonInErrorMessageSanitizerTest {
}
@Test
public void ensureTrueAndOneAsStringAreSupportedAsRedactedKey() throws Exception {
public void ensureTrueAndOneAsStringAreSupportedAsRedactedKey() {
//only null is not supported, as passing 'null' is considered as null
assertRedaction(
"{'true': 'secret1', '1': 'secret3', 'b': 'other', '$redact': ['true', '1']}",
@@ -82,7 +82,7 @@ public class RedactSecretJsonInErrorMessageSanitizerTest {
}
@Test
public void redactFullBranch() throws Exception {
public void redactFullBranch() {
assertRedaction(
"{'a': {'s1': 'secret1', 's2': 'secret2', 's3': [1,2,3]}, 'b': [4,5,6], 'c': 'other', '$redact': ['a', 'b']}",
"{'a': '[value redacted]', 'b': '[value redacted]', 'c': 'other', '$redact': ['a', 'b']}"
@@ -98,7 +98,7 @@ public class RedactSecretJsonInErrorMessageSanitizerTest {
}
@Test
public void redactedKeyWithoutCorrespondences() throws Exception {
public void redactedKeyWithoutCorrespondences() {
assertRedaction(
"{'a1': 'secret1', 'a2': 'secret2', 'b': 'other', '$redact': ['a0', 'a1', 'a2', 'a3']}",
"{'a1': '[value redacted]', 'a2': '[value redacted]', 'b': 'other', '$redact': ['a0', 'a1', 'a2', 'a3']}"
@@ -114,7 +114,7 @@ public class RedactSecretJsonInErrorMessageSanitizerTest {
}
@Test
public void noInteractionBetweenLevels() throws Exception {
public void noInteractionBetweenLevels() {
assertRedaction(
"{'a': 'secret', 'b': 'other', 'c': 'other', '$redact': 'a', 'sub': {'a': 'other', 'b': 'secret', 'c': 'other', '$redact': 'b'}}",
"{'a': '[value redacted]', 'b': 'other', 'c': 'other', '$redact': 'a', 'sub': {'a': 'other', 'b': '[value redacted]', 'c': 'other', '$redact': 'b'}}"
@@ -1617,7 +1617,7 @@ public class VirtualFileTest {
}
@Override
public boolean isDescendant(String childRelativePath) throws IOException {
public boolean isDescendant(String childRelativePath) {
return true;
}
@@ -340,7 +340,7 @@ public class HistoryPageFilterTest {
@Test
@Issue("JENKINS-40718")
public void should_search_builds_by_build_variables() throws IOException {
public void should_search_builds_by_build_variables() {
Iterable<ModelObject> runs = Arrays.asList(
new MockBuild(2).withBuildVariables(Collections.singletonMap("env", "dummyEnv")),
new MockBuild(1).withBuildVariables(Collections.singletonMap("env", "otherEnv")));
@@ -507,7 +507,7 @@ public class HistoryPageFilterTest {
return parameterValues;
}
MockBuild withSensitiveBuildParameters(String paramName, String paramValue) throws IOException {
MockBuild withSensitiveBuildParameters(String paramName, String paramValue) {
addAction(new ParametersAction(Collections.singletonList(createSensitiveStringParameterValue(paramName, paramValue)),
Collections.singletonList(paramName)));
return this;
@@ -117,7 +117,7 @@ public class XMLUtilsTest {
}
@Test
public void testParse_with_XXE() throws IOException, XPathExpressionException {
public void testParse_with_XXE() throws IOException {
try {
final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE foo [\n" +
@@ -11,7 +11,7 @@ public class FieldUtilsTest {
@Issue("JENKINS-64390")
@Test
public void setProtectedFieldValue_Should_fail_silently_to_set_public_final_fields_in_InnerClass() throws Exception {
public void setProtectedFieldValue_Should_fail_silently_to_set_public_final_fields_in_InnerClass() {
InnerClassWithPublicFinalField sut = new InnerClassWithPublicFinalField();
FieldUtils.setProtectedFieldValue("myField", sut, "test");
assertEquals("original", sut.getMyField());
@@ -19,21 +19,21 @@ public class FieldUtilsTest {
@Test
@Issue("JENKINS-64390")
public void setProtectedFieldValue_Should_fail_silently_to_set_public_final_fields_in_OuterClass() throws Exception {
public void setProtectedFieldValue_Should_fail_silently_to_set_public_final_fields_in_OuterClass() {
OuterClassWithPublicFinalField sut = new OuterClassWithPublicFinalField();
FieldUtils.setProtectedFieldValue("myField", sut, "test");
assertEquals("original", sut.getMyField());
}
@Test
public void setProtectedFieldValue_Should_Succeed() throws Exception {
public void setProtectedFieldValue_Should_Succeed() {
InnerClassWithProtectedField sut = new InnerClassWithProtectedField();
FieldUtils.setProtectedFieldValue("myProtectedField", sut, "test");
assertEquals("test", sut.getMyNonFinalField());
}
@Test
public void setNonExistingField_Should_Fail() throws Exception {
public void setNonExistingField_Should_Fail() {
InnerClassWithProtectedField sut = new InnerClassWithProtectedField();
assertThrows(Exception.class, () -> FieldUtils.setProtectedFieldValue("bogus", sut, "whatever"));
}