
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
59 lines
1.7 KiB
Plaintext
59 lines
1.7 KiB
Plaintext
== Why is this an issue?
|
||
|
||
The Spring framework comes with dedicated classes to help writing better and simpler unit tests. In particular, when testing applications built on top of Spring MVC, it is recommended to use Spring's ``++ModelAndViewAssert++`` assertions class, instead of manually testing MVC's properties.
|
||
|
||
|
||
|
||
|
||
This rule raises an issue when Spring's ``++ModelAndViewAssert++`` assertions should be used instead of manual testing.
|
||
|
||
|
||
=== Noncompliant code example
|
||
|
||
[source,java]
|
||
----
|
||
ModelAndView mav = getMyModelAndView();
|
||
|
||
Assert.assertEquals("register", mav.getViewName());
|
||
Assert.assertTrue((Boolean) mav.getModelMap().get("myAttribute"));
|
||
Assert.assertFalse((Boolean) mav.getModelMap().get("myAttribute"));
|
||
Assert.assertEquals(myObject, mav.getModelMap().get("myAttribute"));
|
||
----
|
||
|
||
|
||
=== Compliant solution
|
||
|
||
[source,java]
|
||
----
|
||
ModelAndView mav = getMyModelAndView();
|
||
|
||
ModelAndViewAssert.assertViewName(mav, "register");
|
||
ModelAndViewAssert.assertModelAttributeValue(mav, "myAttribute", Boolean.TRUE);
|
||
ModelAndViewAssert.assertModelAttributeValue(mav, "myAttribute", Boolean.FALSE);
|
||
ModelAndViewAssert.assertModelAttributeValue(mav, "myAttribute", myObject);
|
||
----
|
||
|
||
|
||
== Resources
|
||
|
||
* https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/testing.html#unit-testing-spring-mvc[Unit Testing Spring MVC]
|
||
* https://docs.spring.io/spring-framework/docs/5.2.8.RELEASE/javadoc-api/org/springframework/test/web/ModelAndViewAssert.html[ModelAndViewAssert Javadoc]
|
||
|
||
ifdef::env-github,rspecator-view[]
|
||
|
||
'''
|
||
== Implementation Specification
|
||
(visible only on this page)
|
||
|
||
=== Message
|
||
|
||
Replace this assertion by "ModelAndViewAssert.assert<...>"
|
||
|
||
|
||
=== Highlighting
|
||
|
||
The statement doing the assertion
|
||
|
||
|
||
endif::env-github,rspecator-view[]
|