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 7921467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:35:42+00:00 2026-06-03T16:35:42+00:00

I have a Spring validator that contains the following code. errors.rejectValue(myFieldName, errors.required, new Object[]

  • 0

I have a Spring validator that contains the following code.

errors.rejectValue("myFieldName", "errors.required", new Object[] { "My Field" }, "Field required");

I want to test that the errors.required message is being picked up. I haven’t been able to find out how. What I have so far in jUnit is:

FieldError fieldError = errors.getFieldErrors().get(0);
assertEquals("myFieldName", fieldError.getField());
assertEquals("errors.required", fieldError.getCode());
//TODO: test that the message was picked up

Does anyone know how to grab the full message, with it’s arguments, etc?

  • 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-06-03T16:35:44+00:00Added an answer on June 3, 2026 at 4:35 pm

    I managed to find a solution.

    Inside my jUnit test, I wire in the MessageSource.

    @Autowired
    private MessageSource messageSource;
    

    Then I wrote a convenience method.

    private String getConfiguredMessage(FieldError fieldError) {
        return messageSource.getMessage(fieldError.getCode(), 
                                        fieldError.getArguments(), 
                                        Locale.US);
    }
    

    Using this method, I can find out what the configured message will be.

    assertEquals("My Field is required.", getConfiguredMessage(fieldError));
    

    Although this solution doesn’t truly “get” the message from the error, it serves it’s purpose.

    Hope this helps someone in the future.

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

Sidebar

Related Questions

I Have a hidden field that contains a value and my code block within
I have a WordPress template that contains the following element: <html xmlns=http://www.w3.org/1999/xhtml <?php language_attributes('xhtml');
I have a form object that is being filled correctly automagically by Spring. Within
I have a class that inherits ActiveRecordValidationBase that contains the following property: [Property] [ValidateDecimal]
I have the following class that checks for errors: public bool ValidateAccountDeletion(Account account) {
Is it possible to have Spring inject the JPA entityManager object into my DAO
I am using the following regex in .NET to validate that a string contains
I have form object that I set to request in GET request handler in
I have a class like so, that I create myself somewhere in my code:
I have a rails application that models a house. house contains rooms and rooms

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.