File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
main/java/org/springframework/test/web/servlet/result
test/java/org/springframework/test/web/servlet/result Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright 2002-2012 the original author or authors.
2+ * Copyright 2002-2013 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -87,6 +87,21 @@ public void match(MvcResult result) throws Exception {
8787 };
8888 }
8989
90+ /**
91+ * Assert the given model attributes do not exist
92+ */
93+ public ResultMatcher attributeDoesNotExist (final String ... names ) {
94+ return new ResultMatcher () {
95+ @ Override
96+ public void match (MvcResult result ) throws Exception {
97+ ModelAndView mav = getModelAndView (result );
98+ for (String name : names ) {
99+ assertTrue ("Model attribute '" + name + "' exists" , mav .getModel ().get (name ) == null );
100+ }
101+ }
102+ };
103+ }
104+
90105 /**
91106 * Assert the given model attribute(s) have errors.
92107 */
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2002-2012 the original author or authors.
2+ * Copyright 2002-2013 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -70,7 +70,17 @@ public void attributeExists_doesNotExist() throws Exception {
7070 this .matchers .attributeExists ("bad" ).match (this .mvcResult );
7171 }
7272
73- @ Test
73+ @ Test
74+ public void attributeDoesNotExist () throws Exception {
75+ this .matchers .attributeDoesNotExist ("bad" ).match (this .mvcResult );
76+ }
77+
78+ @ Test (expected =AssertionError .class )
79+ public void attributeDoesNotExist_doesExist () throws Exception {
80+ this .matchers .attributeDoesNotExist ("good" ).match (this .mvcResultWithError );
81+ }
82+
83+ @ Test
7484 public void attribute_equal () throws Exception {
7585 this .matchers .attribute ("good" , is ("good" )).match (this .mvcResult );
7686 }
You can’t perform that action at this time.
0 commit comments