java.lang.AssertionError: java.lang.AssertionError: Expected :lastName is required Actual :loginName is required

Prathyusha

Need help to understand what i am doing wrong. Here is my test case with list of users, where the required fields for user set to null, If the required field is missing, throwing an argument exception with message.Also checked my method it seems good.

//Test case begins  
    @Test(groups = {"unit"})
    public void testProcessOrderWithMissingFieldsForUsers() throws Exception {
        GenericOrder order = getOrder();
              List<User> users = order.getUsers();
              User user = users.get(0);
              user.setLastName(null);
              user.setLoginName(null);
              user.setEmailAddress(null);
              user.setRole(null);
        try {
                 orderService.processOrder(order);
              } catch (ArgumentException aex) {
                 Assert.assertEquals(aex.getFieldErrors().get(0).getMessage(),"lastName is required");
                 Assert.assertEquals(aex.getFieldErrors().get(1).getMessage(), "loginName is required");
                 Assert.assertEquals(aex.getFieldErrors().get(2).getMessage(), "emailAddress is required");
                    Assert.assertEquals(aex.getFieldErrors().get(3).getMessage(), "role is required");
              }
digitalbrikes

It is likely the errors are not in the order you expect them.

Further it would be better to split the test so that each validation is verified individually. In other words have ...WithMissingLastName, ...WithMissingLogin, ...WithMissingEmailAdress, ...WithMissingRole tests.

This makes for easier diagnostics and it is probably closer to what you really intend to test.

Also your test will not fail if the validation is never applied. One way to protect against that is to call the fail method inside the try/catch block.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Is it required to manually destroy and close the open streams of a java.lang.Process?

From Dev

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum

From Dev

Spring 3.2.5 error "java.lang.AssertionError: No ModelAndView found" for all my controller Unit Test

From Dev

java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling

From Dev

java.lang.AssertionError: Content type not set while junit Spring MVC Controller?

From Dev

java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required when starting tomcat

From Dev

java.lang.AssertionError: Content type not set - Spring Controller Junit Tests

From Dev

java.lang.IllegalStateException: A SockJsMessageCodec is required but not available:

From Dev

@Value -> Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'

From Dev

Uncaught exception during compilation: java.lang.AssertionError

From Dev

Spring NumberFormatException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long

From Dev

java.lang.IllegalStateException: Required view not found even after setContentView()

From Dev

Error java.lang.AssertionError: expected: null<null> but was: java.lang.String<null> what does it mean?

From Dev

Roboelectric is giving me a java.lang.IllegalArgumentException: INTERNET permission is required

From Dev

Android Mockito java.lang.AssertionError:

From Dev

How to resolve java.lang.AssertionError when creating OkHttpClient in mockito?

From Dev

IntelliJ to jar is giving "java.lang.NullPointerException: Location is required."

From Dev

android java.lang.AssertionError: java.lang.NoSuchMethodException - Proguard

From Dev

java.lang.AssertionError: Cassandra daemon did not start within timeout

From Dev

Class required a bean of type 'java.lang.String' that could not be found

From Dev

MockMvc and Mockito - java.lang.AssertionError: JSON path "$" Expected: a collection with size <2> but: collection size was <0>

From Dev

java.lang.AssertionError thrown by compiler when adding generated method with parameters

From Dev

java.lang.AssertionError: Status expected:<200> but was:<405>

From Dev

EasyMock java.lang.AssertionError: Unexpected method call

From Dev

java.lang.AssertionError:expected: 1, actual: 0 spring webflow junit

From Dev

Selenium(Java), java.lang.AssertionError

From Dev

How to check for java.lang.AssertionError (JUnit 5)

From Dev

JUnit testing with H2 database -java.lang.AssertionError

From Dev

java.lang.AssertionError: Status expected:<200> but was:<201>

Related Related

  1. 1

    Is it required to manually destroy and close the open streams of a java.lang.Process?

  2. 2

    Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum

  3. 3

    Spring 3.2.5 error "java.lang.AssertionError: No ModelAndView found" for all my controller Unit Test

  4. 4

    java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling

  5. 5

    java.lang.AssertionError: Content type not set while junit Spring MVC Controller?

  6. 6

    java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required when starting tomcat

  7. 7

    java.lang.AssertionError: Content type not set - Spring Controller Junit Tests

  8. 8

    java.lang.IllegalStateException: A SockJsMessageCodec is required but not available:

  9. 9

    @Value -> Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'

  10. 10

    Uncaught exception during compilation: java.lang.AssertionError

  11. 11

    Spring NumberFormatException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long

  12. 12

    java.lang.IllegalStateException: Required view not found even after setContentView()

  13. 13

    Error java.lang.AssertionError: expected: null<null> but was: java.lang.String<null> what does it mean?

  14. 14

    Roboelectric is giving me a java.lang.IllegalArgumentException: INTERNET permission is required

  15. 15

    Android Mockito java.lang.AssertionError:

  16. 16

    How to resolve java.lang.AssertionError when creating OkHttpClient in mockito?

  17. 17

    IntelliJ to jar is giving "java.lang.NullPointerException: Location is required."

  18. 18

    android java.lang.AssertionError: java.lang.NoSuchMethodException - Proguard

  19. 19

    java.lang.AssertionError: Cassandra daemon did not start within timeout

  20. 20

    Class required a bean of type 'java.lang.String' that could not be found

  21. 21

    MockMvc and Mockito - java.lang.AssertionError: JSON path "$" Expected: a collection with size <2> but: collection size was <0>

  22. 22

    java.lang.AssertionError thrown by compiler when adding generated method with parameters

  23. 23

    java.lang.AssertionError: Status expected:<200> but was:<405>

  24. 24

    EasyMock java.lang.AssertionError: Unexpected method call

  25. 25

    java.lang.AssertionError:expected: 1, actual: 0 spring webflow junit

  26. 26

    Selenium(Java), java.lang.AssertionError

  27. 27

    How to check for java.lang.AssertionError (JUnit 5)

  28. 28

    JUnit testing with H2 database -java.lang.AssertionError

  29. 29

    java.lang.AssertionError: Status expected:<200> but was:<201>

HotTag

Archive