Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7574141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:21:44+00:00 2026-05-30T16:21:44+00:00

When using annotation based validation for a form bean, what is the best practice

  • 0

When using annotation based validation for a form bean, what is the best practice for unit-testing those beans in order to ensure that correct validations annotations are specified for each field?

For example, if you have:

public class MyForm {
    @NotNull
    private String name;
}

What is the best way to verify that @NotNull is applied to it?

One obvious way is to create a validator, throw a null at it and expect it to fail. But in my view this is not the best way as you’ll be testing the behaviour and implementation of @NotNull using that rather than trusting the framework.

Ideally I would want to use reflection or a utility that gives me the possibility of just asserting that an @NotNull (and any other) validation is applied to a given field, rather than having to send various combination of values that fail validation.

Is there an elegant way of doing this, or am I on the right track in general?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:21:45+00:00Added an answer on May 30, 2026 at 4:21 pm

    You can also write unit tests for your Beans which are annotated usin JSR303 using validator factory.
    See example:
    http://musingsofaprogrammingaddict.blogspot.com/2009/02/using-bean-validation-with-spring.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm investigating an annotation-based approach to validating Spring beans using spring modules . In
I am using annotation based validation but for one of the forms I am
I'm looking for an annotation-based validation framework, that would allow me to validate parameter
I would like to specify JNDI name for an EJB3 bean using annotation, but
What are the best practices for using Java's @Override annotation and why? It seems
I'm using the Data Annotation validation extensively in ASP.NET MVC 2. This new feature
Is there any ant task based tool using which, we can generate annotation based
I have been trying to set up Spring 3 annotation-based validation, guided by http://static.springsource.org/spring/docs/3.0.0.RC3/spring-framework-reference/html/ch05s07.html
I am using annotation based declarative approach for spring aop. sample code ClassA{ @Transactional(readOnly
I have an application which is using annotation annotation based dependency injection for service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.