Remove unnecessary javadoc from test code if method signature is self-described

Closes: #3332
This commit is contained in:
Yanming Zhou
2024-01-26 10:08:14 +08:00
committed by Christoph Strobl
parent 9a0a99450a
commit 9912e485ed
22 changed files with 7 additions and 303 deletions

View File

@@ -57,33 +57,19 @@ public class AuditableUser extends AbstractAuditable<AuditableUser, Integer> {
this.firstname = firstname;
}
/**
* Returns the firstname.
*
* @return the firstname
*/
public String getFirstname() {
return firstname;
}
/**
* Sets the firstname.
*
* @param firstname the firstname to set
*/
public void setFirstname(final String firstname) {
this.firstname = firstname;
}
public void addRole(AuditableRole role) {
this.roles.add(role);
}
public Set<AuditableRole> getRoles() {
return roles;
}
}

View File

@@ -33,9 +33,6 @@ public class Child {
@ManyToMany(mappedBy = "children")
Set<Parent> parents = new HashSet<>();
/**
* @param parent
*/
public Child add(Parent parent) {
this.parents.add(parent);

View File

@@ -33,50 +33,26 @@ public class Role {
@Id @GeneratedValue private Integer id;
private String name;
/**
* Creates a new instance of {@code Role}.
*/
public Role() {}
/**
* Creates a new preconfigured {@code Role}.
*
* @param name
*/
public Role(final String name) {
this.name = name;
}
/**
* Returns the id.
*
* @return
*/
public Integer getId() {
return id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
@Override
public String toString() {
return PREFIX + name;
}
/**
* Returns whether the role is to be considered new.
*
* @return
*/
public boolean isNew() {
return id == null;
}
}

View File

@@ -26,9 +26,6 @@ public class SampleWithPrimitiveId {
@Id private long id;
/**
* @param id the id to set
*/
public void setId(long id) {
this.id = id;
}

View File

@@ -115,21 +115,10 @@ public class User {
@Temporal(TemporalType.DATE) private Date dateOfBirth;
/**
* Creates a new empty instance of {@code User}.
*/
public User() {
this(null, null, null);
}
/**
* Creates a new instance of {@code User} with preinitialized values for firstname, lastname, email address and roles.
*
* @param firstname
* @param lastname
* @param emailAddress
* @param roles
*/
public User(String firstname, String lastname, String emailAddress, Role... roles) {
this.firstname = firstname;
@@ -142,222 +131,119 @@ public class User {
this.createdAt = new Date();
}
/**
* @return the id
*/
public Integer getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Integer id) {
this.id = id;
}
/**
* Returns the firstname.
*
* @return the firstname
*/
public String getFirstname() {
return firstname;
}
/**
* Sets the firstname.
*
* @param firstname the firstname to set
*/
public void setFirstname(final String firstname) {
this.firstname = firstname;
}
/**
* Returns the lastname.
*
* @return the lastname
*/
public String getLastname() {
return lastname;
}
/**
* Sets the lastname.
*
* @param lastname the lastname to set
*/
public void setLastname(String lastname) {
this.lastname = lastname;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* Returns the email address.
*
* @return the emailAddress
*/
public String getEmailAddress() {
return emailAddress;
}
/**
* Sets the email address.
*
* @param emailAddress the emailAddress to set
*/
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
/**
* @param active the active to set
*/
public void setActive(boolean active) {
this.active = active;
}
/**
* @return the active
*/
public boolean isActive() {
return active;
}
/**
* Returns the user's roles.
*
* @return the roles
*/
public Set<Role> getRoles() {
return roles;
}
/**
* Gives the user a role. Adding a role the user already owns is a no-op.
*/
public void addRole(Role role) {
roles.add(role);
}
/**
* Revokes a role from a user.
*
* @param role
*/
public void removeRole(Role role) {
roles.remove(role);
}
/**
* Returns the colleagues of the user.
*
* @return the colleagues
*/
public Set<User> getColleagues() {
return colleagues;
}
/**
* Adds a new colleague to the user. Adding the user himself as colleague is a no-op.
*
* @param collegue
*/
public void addColleague(User collegue) {
public void addColleague(User colleague) {
// Prevent from adding the user himself as colleague.
if (this.equals(collegue)) {
if (this.equals(colleague)) {
return;
}
colleagues.add(collegue);
collegue.getColleagues().add(this);
colleagues.add(colleague);
colleague.getColleagues().add(this);
}
/**
* Removes a colleague from the list of colleagues.
*
* @param colleague
*/
public void removeColleague(User colleague) {
colleagues.remove(colleague);
colleague.getColleagues().remove(this);
}
/**
* @return the manager
*/
public User getManager() {
return manager;
}
/**
* @param manager the manager to set
*/
public void setManager(User manager) {
this.manager = manager;
}
/**
* @return the createdAt
*/
public Date getCreatedAt() {
return createdAt;
}
/**
* @return the address
*/
public Address getAddress() {
return address;
}
/**
* @param address the address to set
*/
public void setAddress(Address address) {
this.address = address;
}
/**
* @param binaryData the binaryData to set
*/
public void setBinaryData(byte[] binaryData) {
this.binaryData = binaryData;
}
/**
* @return the binaryData
*/
public byte[] getBinaryData() {
return binaryData;
}
@@ -378,16 +264,10 @@ public class User {
return this.getId().equals(that.getId());
}
/**
* @return the attributes
*/
public Set<String> getAttributes() {
return attributes;
}
/**
* @param attributes the attributes to set
*/
public void setAttributes(Set<String> attributes) {
this.attributes = attributes;
}
@@ -406,7 +286,6 @@ public class User {
@Override
public String toString() {
return "User: " + getId() + ", " + getFirstname() + " " + getLastname() + ", " + getEmailAddress();
}
}

View File

@@ -30,44 +30,26 @@ import org.springframework.data.jpa.domain.Specification;
*/
public class UserSpecifications {
/**
* A {@link Specification} to match on a {@link User}'s firstname.
*/
public static Specification<User> userHasFirstname(final String firstname) {
return simplePropertySpec("firstname", firstname);
}
/**
* A {@link Specification} to match on a {@link User}'s lastname.
*/
public static Specification<User> userHasLastname(final String lastname) {
return simplePropertySpec("lastname", lastname);
}
/**
* A {@link Specification} to do a like-match on a {@link User}'s firstname.
*/
public static Specification<User> userHasFirstnameLike(final String expression) {
return (root, query, cb) -> cb.like(root.get("firstname").as(String.class), String.format("%%%s%%", expression));
}
/**
* A {@link Specification} to do an age check.
*
* @param age upper (exclusive) bound of the age
*/
public static Specification<User> userHasAgeLess(final Integer age) {
return (root, query, cb) -> cb.lessThan(root.get("age").as(Integer.class), age);
}
/**
* A {@link Specification} to do a like-match on a {@link User}'s lastname but also adding a sort order on the
* firstname.
*/
public static Specification<User> userHasLastnameLikeWithSort(final String expression) {
return (root, query, cb) -> {

View File

@@ -33,30 +33,18 @@ public class VersionedUser {
@Version
private Long version;
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the version
*/
public Long getVersion() {
return version;
}
/**
* @param version the version to set
*/
public void setVersion(Long version) {
this.version = version;
}

View File

@@ -42,7 +42,7 @@ import org.springframework.data.jpa.repository.QueryRewriter;
import org.springframework.data.repository.cdi.Eager;
/**
* Unit tests for repository with {@link Query} and {@link QueryRewrite} in a CDI environment.
* Unit tests for repository with {@link Query} and {@link QueryRewriter} in a CDI environment.
*
* @author Greg Turnquist
*/
@@ -216,9 +216,6 @@ class JpaQueryRewriterWithCdiIntegrationTests {
/**
* One query rewriter function to rule them all!
*
* @param query
* @param sort
*/
private static String replaceAlias(String query, Sort sort) {

View File

@@ -30,18 +30,12 @@ import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
public class CustomGenericJpaRepository<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements
CustomGenericRepository<T, ID> {
/**
* @param metadata
* @param entityManager
*/
public CustomGenericJpaRepository(JpaEntityInformation<T, ID> metadata, EntityManager entityManager) {
super(metadata, entityManager);
}
@Override
public T customMethod(ID id) {
throw new UnsupportedOperationException("Forced exception for testing purposes.");
}
}

View File

@@ -34,11 +34,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
*/
public class CustomGenericJpaRepositoryFactory extends JpaRepositoryFactory {
/**
* @param entityManager
*/
public CustomGenericJpaRepositoryFactory(EntityManager entityManager) {
super(entityManager);
}

View File

@@ -31,11 +31,5 @@ import org.springframework.data.repository.CrudRepository;
@NoRepositoryBean
public interface CustomGenericRepository<T, ID extends Serializable> extends JpaRepository<T, ID> {
/**
* Custom sample method.
*
* @param id
* @return
*/
T customMethod(ID id);
}

View File

@@ -37,8 +37,6 @@ class EqlComplianceTests {
/**
* Parse the query using {@link EqlParser} then run it through the query-preserving {@link EqlQueryRenderer}.
*
* @param query
*/
private static String parseWithoutChanges(String query) {

View File

@@ -37,8 +37,6 @@ class EqlQueryRendererTests {
/**
* Parse the query using {@link EqlParser} then run it through the query-preserving {@link EqlQueryRenderer}.
*
* @param query
*/
private static String parseWithoutChanges(String query) {

View File

@@ -39,8 +39,6 @@ class HqlQueryRendererTests {
/**
* Parse the query using {@link HqlParser} then run it through the query-preserving {@link HqlQueryRenderer}.
*
* @param query
*/
private static String parseWithoutChanges(String query) {

View File

@@ -168,10 +168,6 @@ class Jpa21UtilsTests {
/**
* Lookup the {@link AttributeNode} with given {@literal nodeName} in the root of the given {@literal graph}.
*
* @param nodeName
* @param graph
* @return
*/
static @Nullable AttributeNode<?> findNode(String nodeName, @Nullable EntityGraph<?> graph) {
@@ -184,10 +180,6 @@ class Jpa21UtilsTests {
/**
* Lookup the {@link AttributeNode} with given {@literal nodeName} in the {@link List} of given {@literal nodes}.
*
* @param nodeName
* @param nodes
* @return
*/
@Nullable
static AttributeNode<?> findNode(String nodeName, List<AttributeNode<?>> nodes) {
@@ -208,10 +200,6 @@ class Jpa21UtilsTests {
/**
* Lookup the {@link AttributeNode} with given {@literal nodeName} in the first {@link Subgraph} of the given
* {@literal node}.
*
* @param attributeName
* @param node
* @return
*/
@Nullable
static AttributeNode<?> findNode(String attributeName, AttributeNode<?> node) {

View File

@@ -205,9 +205,6 @@ class JpaQueryRewriteIntegrationTests {
/**
* One query rewriter function to rule them all!
*
* @param query
* @param sort
*/
private static String replaceAlias(String query, Sort sort) {

View File

@@ -38,8 +38,6 @@ class JpqlQueryRendererTests {
/**
* Parse the query using {@link HqlParser} then run it through the query-preserving {@link HqlQueryRenderer}.
*
* @param query
*/
private static String parseWithoutChanges(String query) {

View File

@@ -30,12 +30,6 @@ import org.springframework.data.jpa.repository.Query;
*/
public interface AuditableUserRepository extends JpaRepository<AuditableUser, Integer> {
/**
* Returns all users with the given firstname.
*
* @param firstname
* @return all users with the given firstname.
*/
List<AuditableUser> findByFirstname(final String firstname);
@Modifying

View File

@@ -40,9 +40,6 @@ public interface RedeclaringRepositoryMethodsRepository extends CrudRepository<U
/**
* Should only find users with the firstname 'Oliver'.
*
* @param page
* @return
*/
@Query("SELECT u FROM User u where u.firstname = 'Oliver'")
Page<User> findAll(Pageable page);

View File

@@ -69,22 +69,19 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
/**
* Retrieve users by their lastname. The finder {@literal User.findByLastname} is declared in
* {@literal META-INF/orm.xml} .
*
* @param lastname
* @return all users with the given lastname
*/
@QueryHints({ @QueryHint(name = "foo", value = "bar") })
List<User> findByLastname(String lastname);
/**
* Redeclaration of {@link CrudRepository#findById(java.io.Serializable)} to change transaction configuration.
* Redeclaration of {@link CrudRepository#findById(java.lang.Object)} to change transaction configuration.
*/
@Transactional
@Override
java.util.Optional<User> findById(Integer primaryKey);
/**
* Redeclaration of {@link CrudRepository#deleteById(java.io.Serializable)}. to make sure the transaction
* Redeclaration of {@link CrudRepository#deleteById(java.lang.Object)}. to make sure the transaction
* configuration of the original method is considered if the redeclaration does not carry a {@link Transactional}
* annotation.
*/
@@ -94,9 +91,6 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
/**
* Retrieve users by their email address. The finder {@literal User.findByEmailAddress} is declared as annotation at
* {@code User}.
*
* @param emailAddress
* @return the user with the given email address
*/
User findByEmailAddress(String emailAddress);
@@ -105,29 +99,17 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
/**
* Retrieves users by the given email and lastname. Acts as a dummy method declaration to test finder query creation.
*
* @param emailAddress
* @param lastname
* @return the user with the given email address and lastname
*/
User findByEmailAddressAndLastname(String emailAddress, String lastname);
/**
* Retrieves users by email address and lastname or firstname. Acts as a dummy method declaration to test finder query
* creation.
*
* @param emailAddress
* @param lastname
* @param username
* @return the users with the given email address and lastname or the given firstname
*/
List<User> findByEmailAddressAndLastnameOrFirstname(String emailAddress, String lastname, String username);
/**
* Retrieves a user by its username using the query annotated to the method.
*
* @param emailAddress
* @return
*/
@Query("select u from User u where u.emailAddress = ?1")
@Transactional(readOnly = true)
@@ -135,20 +117,12 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
/**
* Method to directly create query from and adding a {@link Pageable} parameter to be regarded on query execution.
*
* @param pageable
* @param lastname
* @return
*/
Page<User> findByLastname(Pageable pageable, String lastname);
/**
* Method to directly create query from and adding a {@link Pageable} parameter to be regarded on query execution.
* Just returns the queried {@link Page}'s contents.
*
* @param firstname
* @param pageable
* @return
*/
List<User> findByFirstname(String firstname, Pageable pageable);
@@ -175,8 +149,6 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
/**
* Manipulating query to set all {@link User}'s names to the given one.
*
* @param lastname
*/
@Modifying
@Query("update User u set u.lastname = ?1")
@@ -187,10 +159,6 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
/**
* Method where parameters will be applied by name. Note that the order of the parameters is then not crucial anymore.
*
* @param foo
* @param bar
* @return
*/
@Query("select u from User u where u.lastname = :lastname or u.firstname = :firstname")
List<User> findByLastnameOrFirstname(@Param("firstname") String foo, @Param("lastname") String bar);
@@ -200,10 +168,6 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
/**
* Method to check query creation and named parameter usage go well hand in hand.
*
* @param lastname
* @param firstname
* @return
*/
List<User> findByFirstnameOrLastname(@Param("lastname") String lastname, @Param("firstname") String firstname);

View File

@@ -31,8 +31,6 @@ public interface UserRepositoryCustom {
/**
* Some custom method to implement.
*
* @param user
*/
void someCustomMethod(User user);
}

View File

@@ -47,12 +47,6 @@ public class HidingClassLoader extends ShadowingClassLoader {
this.hidden = hidden;
}
/**
* Creates a new {@link HidingClassLoader} with the packages of the given classes hidden.
*
* @param packages must not be {@literal null}.
* @return
*/
public static HidingClassLoader hide(Class<?>... packages) {
Assert.notNull(packages, "Packages must not be null");
@@ -62,12 +56,6 @@ public class HidingClassLoader extends ShadowingClassLoader {
.collect(Collectors.toList()));
}
/**
* Creates a new {@link HidingClassLoader} with the packages of the given classes hidden.
*
* @param packages must not be {@literal null}.
* @return
*/
public static HidingClassLoader hidePackages(String... packages) {
Assert.notNull(packages, "Packages must not be null");