1   /*
2    * Copyright 2004-2009 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.action;
17  
18  import static org.easymock.EasyMock.createMock;
19  import static org.easymock.EasyMock.replay;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.seasar.cubby.mock.MockActionContext;
27  
28  public class SendErrorTest {
29  
30  	private HttpServletRequest request;
31  
32  	private HttpServletResponse response;
33  
34  	@Before
35  	public void setupMock() {
36  		request = createMock(HttpServletRequest.class);
37  		response = createMock(HttpServletResponse.class);
38  	}
39  
40  	@Test
41  	public void sendError() throws Exception {
42  		response.sendError(HttpServletResponse.SC_NOT_FOUND);
43  		replay(request, response);
44  
45  		SendError sendError = new SendError(HttpServletResponse.SC_NOT_FOUND);
46  		ActionContext actionContext = new MockActionContext(null, null, null);
47  		sendError.execute(actionContext, request, response);
48  	}
49  
50  	@Test
51  	public void sendErrorWithMessage() throws Exception {
52  		response.sendError(HttpServletResponse.SC_NOT_FOUND, "NOT FOUND");
53  		replay(request, response);
54  
55  		SendError sendError = new SendError(HttpServletResponse.SC_NOT_FOUND,
56  				"NOT FOUND");
57  		ActionContext actionContext = new MockActionContext(null, null, null);
58  		sendError.execute(actionContext, request, response);
59  	}
60  }