@@ -0,0 +1,2684 @@
+package javasnack.net;%0A%0Aimport static org.testng.Assert.assertFalse;%0Aimport static org.testng.Assert.assertTrue;%0A%0Aimport java.net.CookiePolicy;%0Aimport java.net.HttpCookie;%0Aimport java.net.URI;%0Aimport java.net.URISyntaxException;%0A%0Aimport org.testng.annotations.Test;%0A%0Apublic class TestCookiePolicy1 %7B%0A%0A    @Test%0A    public void testAcceptOriginServer() throws URISyntaxException %7B%0A        final CookiePolicy cp = CookiePolicy.ACCEPT_ORIGINAL_SERVER;%0A        final URI setcookieUri = new URI(%22http://www.example.com/%22);%0A        HttpCookie c0 = new HttpCookie(%22c0%22, %22v0%22);%0A        // reject empty domain cookie (actually, default CookieManager set requested uri as default)%0A        assertFalse(cp.shouldAccept(setcookieUri, c0));%0A%0A        // accept identical domain cookie%0A        c0.setDomain(%22www.example.com%22);%0A        assertTrue(cp.shouldAccept(setcookieUri, c0));%0A%0A        // reject parent or sub domain cookie%0A        c0.setDomain(%22example.com%22);%0A        assertFalse(cp.shouldAccept(setcookieUri, c0));%0A        c0.setDomain(%22aaa.www.example.com%22);%0A        assertFalse(cp.shouldAccept(setcookieUri, c0));%0A%0A        // reject outer domain cookie%0A        c0.setDomain(%22foo.bar.baz%22);%0A        assertFalse(cp.shouldAccept(setcookieUri, c0));%0A    %7D%0A%0A    @Test%0A    public void testAcceptAll() throws URISyntaxException %7B%0A        final CookiePolicy cp = CookiePolicy.ACCEPT_ALL;%0A        final URI setcookieUri = new URI(%22http://www.example.com/%22);%0A        HttpCookie c0 = new HttpCookie(%22c0%22, %22v0%22);%0A        // accept all%0A        assertTrue(cp.shouldAccept(setcookieUri, c0));%0A%0A        c0.setDomain(%22www.example.com%22);%0A        assertTrue(cp.shouldAccept(setcookieUri, c0));%0A%0A        c0.setDomain(%22example.com%22);%0A        assertTrue(cp.shouldAccept(setcookieUri, c0));%0A        c0.setDomain(%22aaa.www.example.com%22);%0A        assertTrue(cp.shouldAccept(setcookieUri, c0));%0A%0A        c0.setDomain(%22foo.bar.baz%22);%0A        assertTrue(cp.shouldAccept(setcookieUri, c0));%0A    %7D%0A%0A    @Test%0A    public void testAcceptNone() throws URISyntaxException %7B%0A        final CookiePolicy cp = CookiePolicy.ACCEPT_NONE;%0A        final URI setcookieUri = new URI(%22http://www.example.com/%22);%0A        HttpCookie c0 = new HttpCookie(%22c0%22, %22v0%22);%0A        // reject all%0A        assertFalse(cp.shouldAccept(setcookieUri, c0));%0A%0A        c0.setDomain(%22www.example.com%22);%0A        assertFalse(cp.shouldAccept(setcookieUri, c0));%0A%0A        c0.setDomain(%22example.com%22);%0A        assertFalse(cp.shouldAccept(setcookieUri, c0));%0A        c0.setDomain(%22aaa.www.example.com%22);%0A        assertFalse(cp.shouldAccept(setcookieUri, c0));%0A%0A        c0.setDomain(%22foo.bar.baz%22);%0A        assertFalse(cp.shouldAccept(setcookieUri, c0));%0A    %7D%0A%7D%0A

add TestCookiePolicy1.java