Home | History | Annotate | Download | only in net
      1 /* Licensed to the Apache Software Foundation (ASF) under one or more
      2  * contributor license agreements.  See the NOTICE file distributed with
      3  * this work for additional information regarding copyright ownership.
      4  * The ASF licenses this file to You under the Apache License, Version 2.0
      5  * (the "License"); you may not use this file except in compliance with
      6  * the License.  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, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package org.apache.harmony.luni.tests.java.net;
     18 
     19 import java.io.IOException;
     20 import java.net.CookieHandler;
     21 import java.net.NetPermission;
     22 import java.net.URI;
     23 import java.security.Permission;
     24 import java.util.Map;
     25 
     26 import junit.framework.TestCase;
     27 
     28 public class CookieHandlerTest extends TestCase {
     29 
     30     /**
     31      * @tests java.net.CookieHandler#getDefault()
     32      */
     33     public void test_GetDefault() {
     34         assertNull(CookieHandler.getDefault());
     35     }
     36 
     37     /**
     38      * @tests java.net.CookieHandler#setDefault(CookieHandler)
     39      */
     40     public void test_SetDefault_java_net_cookieHandler() {
     41         MockCookieHandler rc1 = new MockCookieHandler();
     42         MockCookieHandler rc2 = new MockCookieHandler();
     43         CookieHandler.setDefault(rc1);
     44         assertSame(CookieHandler.getDefault(), rc1);
     45         CookieHandler.setDefault(rc2);
     46         assertSame(CookieHandler.getDefault(), rc2);
     47         CookieHandler.setDefault(null);
     48         assertNull(CookieHandler.getDefault());
     49     }
     50 
     51     class MockCookieHandler extends CookieHandler {
     52 
     53         public Map get(URI uri, Map requestHeaders) throws IOException {
     54             return null;
     55         }
     56 
     57         public void put(URI uri, Map responseHeaders) throws IOException {
     58             // empty
     59         }
     60 
     61     }
     62 }
     63