Skip to content

Commit 91b0cb9

Browse files
DiegoKrupitzaschauder
authored andcommitted
Remove of useless throws ... in jUnit tests.
A lot of jUnit tests had in the method header a `throws` that is useless. For example `throws Exception` on a method where no exception is thrown. Removing this noice will make the tests more redable. Original pull request spring-projects#2433
1 parent d0c3b1a commit 91b0cb9

27 files changed

+89
-91
lines changed

src/test/java/org/springframework/data/jpa/domain/support/AuditingBeanFactoryPostProcessorUnitTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ DefaultListableBeanFactory getBeanFactory() {
5959
}
6060

6161
@Test
62-
void beanConfigurerAspectShouldBeConfiguredAfterPostProcessing() throws Exception {
62+
void beanConfigurerAspectShouldBeConfiguredAfterPostProcessing() {
6363

6464
processor.postProcessBeanFactory(beanFactory);
6565

src/test/java/org/springframework/data/jpa/domain/support/AuditingNamespaceUnitTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ String getConfigFile() {
3939
}
4040

4141
@Test
42-
void registersBeanDefinitions() throws Exception {
42+
void registersBeanDefinitions() {
4343

4444
BeanDefinition definition = beanFactory.getBeanDefinition(AuditingEntityListener.class.getName());
4545
PropertyValue propertyValue = definition.getPropertyValues().getPropertyValue("auditingHandler");

src/test/java/org/springframework/data/jpa/repository/EclipseLinkNamespaceUserRepositoryTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -106,7 +106,7 @@ void bindsNativeQueryResultsToProjectionByName() {}
106106
* Ignores the test. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is fixed.
107107
*/
108108
@Override
109-
void findByEmptyArrayOfIntegers() throws Exception {}
109+
void findByEmptyArrayOfIntegers() {}
110110

111111
/**
112112
* Ignores the test. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is fixed.
@@ -119,13 +119,13 @@ void findByAgeWithEmptyArrayOfIntegersOrFirstName() {
119119
* Ignores the test. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is fixed.
120120
*/
121121
@Override
122-
void findByEmptyCollectionOfIntegers() throws Exception {}
122+
void findByEmptyCollectionOfIntegers() {}
123123

124124
/**
125125
* Ignores the test. Reconsider once https://bugs.eclipse.org/bugs/show_bug.cgi?id=533240 is fixed.
126126
*/
127127
@Override
128-
void findByEmptyCollectionOfStrings() throws Exception {}
128+
void findByEmptyCollectionOfStrings() {}
129129

130130
/**
131131
* Ignores the test for EclipseLink.

src/test/java/org/springframework/data/jpa/repository/EclipseLinkUserRepositoryFinderTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2021 the original author or authors.
2+
* Copyright 2011-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ class EclipseLinkUserRepositoryFinderTests extends UserRepositoryFinderTests {
2929

3030
@Disabled
3131
@Override
32-
void executesNotInQueryCorrectly() throws Exception {}
32+
void executesNotInQueryCorrectly() {}
3333

3434
@Disabled
3535
@Override

src/test/java/org/springframework/data/jpa/repository/ORMInfrastructureTests.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,10 +40,9 @@ public class ORMInfrastructureTests {
4040
/**
4141
* Tests, that the context got initialized and injected correctly.
4242
*
43-
* @throws Exception
4443
*/
4544
@Test
46-
void contextInitialized() throws Exception {
45+
void contextInitialized() {
4746

4847
assertThat(context).isNotNull();
4948
}

src/test/java/org/springframework/data/jpa/repository/OpenJpaParentRepositoryIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2013-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,5 +23,5 @@ class OpenJpaParentRepositoryIntegrationTests extends ParentRepositoryIntegratio
2323

2424
@Override
2525
@Disabled
26-
void testWithJoin() throws Exception {}
26+
void testWithJoin() {}
2727
}

src/test/java/org/springframework/data/jpa/repository/OpenJpaUserRepositoryFinderTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2021 the original author or authors.
2+
* Copyright 2011-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,5 +29,5 @@ class OpenJpaUserRepositoryFinderTests extends UserRepositoryFinderTests {
2929

3030
@Disabled
3131
@Override
32-
void findsByLastnameIgnoringCaseLike() throws Exception {}
32+
void findsByLastnameIgnoringCaseLike() {}
3333
}

src/test/java/org/springframework/data/jpa/repository/ParentRepositoryIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2013-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -84,7 +84,7 @@ public Predicate toPredicate(Root<Parent> root, CriteriaQuery<?> query, Criteria
8484
}
8585

8686
@Test // DATAJPA-287
87-
void testWithJoin() throws Exception {
87+
void testWithJoin() {
8888
Page<Parent> page = repository.findAll(new Specification<Parent>() {
8989
@Override
9090
public Predicate toPredicate(Root<Parent> root, CriteriaQuery<?> query, CriteriaBuilder cb) {

src/test/java/org/springframework/data/jpa/repository/RepositoryWithIdClassKeyTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,7 +61,7 @@ public class RepositoryWithIdClassKeyTests {
6161
* Specification 2.4.1.3 Derived Identities Example 2</a>
6262
*/
6363
@Test // DATAJPA-413
64-
void shouldSaveAndLoadEntitiesWithDerivedIdentities() throws Exception {
64+
void shouldSaveAndLoadEntitiesWithDerivedIdentities() {
6565

6666
Site site = siteRepository.save(new Site());
6767
Item item = itemRepository.save(new Item(123, 456));

src/test/java/org/springframework/data/jpa/repository/RoleRepositoryIntegrationTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2021 the original author or authors.
2+
* Copyright 2011-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,15 +45,15 @@ public class RoleRepositoryIntegrationTests {
4545
@Autowired RoleRepository repository;
4646

4747
@Test
48-
void createsRole() throws Exception {
48+
void createsRole() {
4949

5050
Role reference = new Role("ADMIN");
5151
Role result = repository.save(reference);
5252
assertThat(result).isEqualTo(reference);
5353
}
5454

5555
@Test
56-
void updatesRole() throws Exception {
56+
void updatesRole() {
5757

5858
Role reference = new Role("ADMIN");
5959
Role result = repository.save(reference);

src/test/java/org/springframework/data/jpa/repository/UserRepositoryFinderTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -144,7 +144,7 @@ void executesInKeywordForPageCorrectly() {
144144
}
145145

146146
@Test
147-
void executesNotInQueryCorrectly() throws Exception {
147+
void executesNotInQueryCorrectly() {
148148

149149
List<User> result = userRepository.findByFirstnameNotIn(Arrays.asList("Dave", "Carter"));
150150

@@ -160,7 +160,7 @@ void findsByLastnameIgnoringCase() {
160160
}
161161

162162
@Test // DATAJPA-92
163-
void findsByLastnameIgnoringCaseLike() throws Exception {
163+
void findsByLastnameIgnoringCaseLike() {
164164

165165
List<User> result = userRepository.findByLastnameIgnoringCaseLike("BeAUfo%");
166166

src/test/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigDefinitionParserTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@
3333
class JpaRepositoryConfigDefinitionParserTests {
3434

3535
@Test
36-
void getsTransactionManagerSet() throws Exception {
36+
void getsTransactionManagerSet() {
3737

3838
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
3939
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);

src/test/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigExtensionUnitTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2013-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -92,7 +92,7 @@ void doesNotRegisterProcessorIfAutoRegistered() {
9292
}
9393

9494
@Test // DATAJPA-525
95-
void guardsAgainstNullJavaTypesReturnedFromJpaMetamodel() throws Exception {
95+
void guardsAgainstNullJavaTypesReturnedFromJpaMetamodel() {
9696

9797
ApplicationContext context = mock(ApplicationContext.class);
9898
EntityManagerFactory emf = mock(EntityManagerFactory.class);

src/test/java/org/springframework/data/jpa/repository/query/Jpa21UtilsUnitTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2021 the original author or authors.
2+
* Copyright 2015-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@
3333
class Jpa21UtilsUnitTests {
3434

3535
@Test // DATAJPA-696
36-
void shouldBuildCorrectSubgraphForJpaEntityGraph() throws Exception {
36+
void shouldBuildCorrectSubgraphForJpaEntityGraph() {
3737

3838
EntityGraph<?> entityGraph = mock(EntityGraph.class);
3939
Subgraph<?> subgraph = mock(Subgraph.class);

src/test/java/org/springframework/data/jpa/repository/query/JpaQueryMethodUnitTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -275,7 +275,7 @@ void returnsDefaultCountQueryNameBasedOnConfiguredNamedQueryName() throws Except
275275
}
276276

277277
@Test // DATAJPA-185
278-
void rejectsInvalidNamedParameter() throws Exception {
278+
void rejectsInvalidNamedParameter() {
279279

280280
assertThatThrownBy(() -> getQueryMethod(InvalidRepository.class, "findByAnnotatedQuery", String.class))
281281
.isInstanceOf(IllegalStateException.class)
@@ -344,8 +344,8 @@ void shouldFindEntityGraphAnnotationOnOverriddenSimpleJpaRepositoryMethodFindOne
344344
doReturn(User.class).when(metadata).getDomainType();
345345
doReturn(User.class).when(metadata).getReturnedDomainClass((Method) any());
346346

347-
JpaQueryMethod method = new JpaQueryMethod(JpaRepositoryOverride.class.getMethod("findOne", Integer.class), metadata,
348-
factory, extractor);
347+
JpaQueryMethod method = new JpaQueryMethod(JpaRepositoryOverride.class.getMethod("findOne", Integer.class),
348+
metadata, factory, extractor);
349349

350350
assertThat(method.getEntityGraph()).isNotNull();
351351
assertThat(method.getEntityGraph().getName()).isEqualTo("User.detail");

src/test/java/org/springframework/data/jpa/repository/query/ParameterBinderUnitTests.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -123,15 +123,15 @@ void bindWorksWithNullForPageable() throws Exception {
123123
}
124124

125125
@Test
126-
void usesIndexedParametersIfNoParamAnnotationPresent() throws Exception {
126+
void usesIndexedParametersIfNoParamAnnotationPresent() {
127127

128128
Object[] values = { "foo" };
129129
bind(useIndexedParameters, values);
130130
verify(query).setParameter(eq(1), any());
131131
}
132132

133133
@Test
134-
void usesParameterNameIfAnnotated() throws Exception {
134+
void usesParameterNameIfAnnotated() {
135135

136136
when(query.setParameter(eq("username"), any())).thenReturn(query);
137137

@@ -185,8 +185,7 @@ void shouldSetTemporalQueryParameterToTimestamp() throws Exception {
185185
}
186186

187187
@Test // DATAJPA-107
188-
void shouldThrowIllegalArgumentExceptionIfIsAnnotatedWithTemporalParamAndParameterTypeIsNotDate()
189-
throws Exception {
188+
void shouldThrowIllegalArgumentExceptionIfIsAnnotatedWithTemporalParamAndParameterTypeIsNotDate() throws Exception {
190189
Method method = SampleRepository.class.getMethod("invalidWithTemporalTypeParameter", String.class);
191190

192191
assertThatIllegalArgumentException().isThrownBy(() -> new JpaParameters(method));

src/test/java/org/springframework/data/jpa/repository/query/QueryUtilsUnitTests.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ class QueryUtilsUnitTests {
5151
private static final String QUERY_WITH_AS = "select u from User as u where u.username = ?";
5252

5353
@Test
54-
void createsCountQueryCorrectly() throws Exception {
54+
void createsCountQueryCorrectly() {
5555
assertCountQuery(QUERY, COUNT_QUERY);
5656
}
5757

@@ -64,47 +64,47 @@ void createsCountQueriesCorrectlyForCapitalLetterJPQL() {
6464
}
6565

6666
@Test
67-
void createsCountQueryForDistinctQueries() throws Exception {
67+
void createsCountQueryForDistinctQueries() {
6868

6969
assertCountQuery("select distinct u from User u where u.foo = ?",
7070
"select count(distinct u) from User u where u.foo = ?");
7171
}
7272

7373
@Test
74-
void createsCountQueryForConstructorQueries() throws Exception {
74+
void createsCountQueryForConstructorQueries() {
7575

7676
assertCountQuery("select distinct new User(u.name) from User u where u.foo = ?",
7777
"select count(distinct u) from User u where u.foo = ?");
7878
}
7979

8080
@Test
81-
void createsCountQueryForJoins() throws Exception {
81+
void createsCountQueryForJoins() {
8282

8383
assertCountQuery("select distinct new User(u.name) from User u left outer join u.roles r WHERE r = ?",
8484
"select count(distinct u) from User u left outer join u.roles r WHERE r = ?");
8585
}
8686

8787
@Test
88-
void createsCountQueryForQueriesWithSubSelects() throws Exception {
88+
void createsCountQueryForQueriesWithSubSelects() {
8989

9090
assertCountQuery("select u from User u left outer join u.roles r where r in (select r from Role)",
9191
"select count(u) from User u left outer join u.roles r where r in (select r from Role)");
9292
}
9393

9494
@Test
95-
void createsCountQueryForAliasesCorrectly() throws Exception {
95+
void createsCountQueryForAliasesCorrectly() {
9696

9797
assertCountQuery("select u from User as u", "select count(u) from User as u");
9898
}
9999

100100
@Test
101-
void allowsShortJpaSyntax() throws Exception {
101+
void allowsShortJpaSyntax() {
102102

103103
assertCountQuery(SIMPLE_QUERY, COUNT_QUERY);
104104
}
105105

106106
@Test
107-
void detectsAliasCorrectly() throws Exception {
107+
void detectsAliasCorrectly() {
108108

109109
assertThat(detectAlias(QUERY)).isEqualTo("u");
110110
assertThat(detectAlias(SIMPLE_QUERY)).isEqualTo("u");

0 commit comments

Comments
 (0)