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

  • Home
  • SEARCH
  • 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 6063255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:08:42+00:00 2026-05-23T09:08:42+00:00

@Autowired private Validator validator; @Test public void testValidateMethodOfPaymentBadCreditCard() { final MethodOfPayment mop = new

  • 0
@Autowired
private Validator validator;

    @Test
        public void testValidateMethodOfPaymentBadCreditCard() {
            final MethodOfPayment mop = new MethodOfPayment();
            command.setDescription("1234567890");
            final Set<ConstraintViolation<MethodOfPayment>> constraintViolations = this.validator.validateProperty(mop, "cardNumber", Default.class);
            Assert.assertFalse(constraintViolations.isEmpty());
            for (final ConstraintViolation<MethodOfPayment> cv : constraintViolations) {
                Assert.assertEquals(cv.getMessage(), "{error.invalid.cardNumber}");
            }
        }

The unit class has instance of define in my xml.

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>

my methodofpayment is annotated with

@CreditCardNumber(message="{error.invalid.cardNumber}")
    public String getCardNumber() {
        return this.cardNumber;
    }

This test fails on line saying the constraint violation is empty. I thought it should not be empty right?

What is wrong?
What kind of data fails for credit card validation?

  • 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-23T09:08:43+00:00Added an answer on May 23, 2026 at 9:08 am

    null is considered as valid value for most constraints defined in Bean Validation and Hibernate Validator.

    Hence you won’t get a constraint violation if you don’t assign a value to the cardNumber property or annotate it with @NotNull (btw. your listing seems a bit strange, where does command come from?)

    The validator for @CreditCardNumber uses the Luhn algorithm for checking credit card numbers.

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

Sidebar

Related Questions

My code: @Component public class A { @Autowired private B b; public void method()
I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {/services-test-config.xml}) public class MySericeTest { @Autowired
(Java Spring WebApp) I have: public class PersonValidator implements Validator { private PersonDAO d;
Class A { private B instanceB; @Autowired public setInstanceB(B instanceB) { this.instanceB = instanceB;
Let's say we have a class: public class MyClass { @Autowired private AnotherBean anotherBean;
I wanted to understand how exactly the @Autowired annotation works. import com.test.WorkFlowDAO; public class
Here is the code: public class Customer { @Autowired private Person person; //some business
Here is my service layer: @Service @RemoteProxy public class ReturnToDWR{ @Autowired private DAOLayer daoLayer;
I've got the following class: @Service public class TestService{ @Autowired private Integer size; private
import org.springframework.beans.factory.annotation.Autowired; class MyService { @Autowired private DependencyOne dependencyOne; @Autowired private DependencyTwo dependencyTwo; public

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.