View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
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    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.attachment;
16  
17  import java.net.URL;
18  import java.util.Collections;
19  
20  import org.htmlunit.HttpMethod;
21  import org.htmlunit.Page;
22  import org.htmlunit.WebResponse;
23  import org.htmlunit.WebResponseData;
24  import org.htmlunit.http.HttpStatus;
25  import org.junit.Assert;
26  import org.junit.Test;
27  
28  /**
29   * Tests for {@link AttachmentHandler}.
30   *
31   * @author Ronald Brill
32   */
33  public class AttachmentHandlerTest {
34  
35      /**
36       * @throws Exception if an error occurs
37       */
38      @Test
39      public void noHeaders() throws Exception {
40          final WebResponseData data = new WebResponseData("HtmlUnit".getBytes(),
41                  HttpStatus.OK_200, HttpStatus.OK_200_MSG, Collections.emptyList());
42          final WebResponse response = new WebResponse(data, new URL("http://test.com"), HttpMethod.GET, 1000);
43          final AttachmentHandler attachmentHandler = new AttachmentHandler() {
44  
45              @Override
46              public void handleAttachment(final Page page, final String attachmentFilename) {
47                  // mock
48              }
49          };
50  
51          Assert.assertFalse(attachmentHandler.isAttachment(response));
52      }
53  }