/** * Creates and returns a new {@code InternetDomainName} by prepending the argument and a dot to * the current name. For example, {@code InternetDomainName.from("foo.com").child("www.bar")} * returns a new {@code InternetDomainName} with the value {@code www.bar.foo.com}. Only lenient * validation is performed, as described {@link #from(String) here}. * * @throws NullPointerException if leftParts is null * @throws IllegalArgumentException if the resulting name is not valid */ public InternetDomainName child(String leftParts) { return from(checkNotNull(leftParts) + "." + name); }
public void testValid() { for (String name : VALID_NAME) { InternetDomainName.from(name); } }
/** * Returns the ancestor of the current domain at the given number of levels "higher" (rightward) * in the subdomain list. The number of levels must be non-negative, and less than {@code N-1}, * where {@code N} is the number of parts in the domain. * * <p>TODO: Reasonable candidate for addition to public API. */ private InternetDomainName ancestor(int levels) { return from(DOT_JOINER.join(parts.subList(levels, parts.size()))); }
public PackageSanityTests() { setDefault(InternetDomainName.class, InternetDomainName.from("google.com")); } }
public void testInvalid() { for (String name : INVALID_NAME) { try { InternetDomainName.from(name); fail("Should have been invalid: '" + name + "'"); } catch (IllegalArgumentException expected) { } } }
public void testInvalidTopPrivateDomain() { ImmutableSet<String> badCookieDomains = ImmutableSet.of("co.uk", "foo", "com"); for (String domain : badCookieDomains) { try { InternetDomainName.from(domain).topPrivateDomain(); fail(domain); } catch (IllegalStateException expected) { } } }
public void testParent() { assertEquals("com", InternetDomainName.from("google.com").parent().toString()); assertEquals("uk", InternetDomainName.from("co.uk").parent().toString()); assertEquals("google.com", InternetDomainName.from("www.google.com").parent().toString()); try { InternetDomainName.from("com").parent(); fail("'com' should throw ISE on .parent() call"); } catch (IllegalStateException expected) { } }
@GwtIncompatible // NullPointerTester public void testNulls() { final NullPointerTester tester = new NullPointerTester(); tester.testAllPublicStaticMethods(InternetDomainName.class); tester.testAllPublicInstanceMethods(InternetDomainName.from("google.com")); } }
public void testParentChild() { InternetDomainName origin = InternetDomainName.from("foo.com"); InternetDomainName parent = origin.parent(); assertEquals("com", parent.toString()); // These would throw an exception if leniency were not preserved during parent() and child() // calls. InternetDomainName child = parent.child(LOTS_OF_DELTAS); child.child(LOTS_OF_DELTAS); }
public void testChild() { InternetDomainName domain = InternetDomainName.from("foo.com"); assertEquals("www.foo.com", domain.child("www").toString()); try { domain.child("www."); fail("www..google.com should have been invalid"); } catch (IllegalArgumentException expected) { } }
public void testUnderPublicSuffix() { for (String name : SOMEWHERE_UNDER_PS) { final InternetDomainName domain = InternetDomainName.from(name); assertFalse(name, domain.isPublicSuffix()); assertTrue(name, domain.hasPublicSuffix()); assertTrue(name, domain.isUnderPublicSuffix()); } }
public void testUnderRegistrySuffix() { for (String name : SOMEWHERE_UNDER_RS) { final InternetDomainName domain = InternetDomainName.from(name); assertFalse(name, domain.isRegistrySuffix()); assertTrue(name, domain.hasRegistrySuffix()); assertTrue(name, domain.isUnderRegistrySuffix()); } }
public void testUnderTopDomainUnderRegistrySuffix() { for (String name : UNDER_TOP_UNDER_REGISTRY_SUFFIX) { final InternetDomainName domain = InternetDomainName.from(name); assertFalse(name, domain.isRegistrySuffix()); assertTrue(name, domain.hasRegistrySuffix()); assertTrue(name, domain.isUnderRegistrySuffix()); assertFalse(name, domain.isTopDomainUnderRegistrySuffix()); } }
public void testRegistrySuffixMultipleUnders() { // PSL has both *.uk and *.sch.uk; the latter should win. // See http://code.google.com/p/guava-libraries/issues/detail?id=1176 InternetDomainName domain = InternetDomainName.from("www.essex.sch.uk"); assertTrue(domain.hasRegistrySuffix()); assertEquals("essex.sch.uk", domain.registrySuffix().toString()); assertEquals("www.essex.sch.uk", domain.topDomainUnderRegistrySuffix().toString()); }
public void testRegistrySuffixExclusion() { InternetDomainName domain = InternetDomainName.from("foo.city.yokohama.jp"); assertTrue(domain.hasRegistrySuffix()); assertEquals("yokohama.jp", domain.registrySuffix().toString()); // Behold the weirdness! assertFalse(domain.registrySuffix().isRegistrySuffix()); }
public void testPublicSuffixExclusion() { InternetDomainName domain = InternetDomainName.from("foo.city.yokohama.jp"); assertTrue(domain.hasPublicSuffix()); assertEquals("yokohama.jp", domain.publicSuffix().toString()); // Behold the weirdness! assertFalse(domain.publicSuffix().isPublicSuffix()); }
public void testPublicSuffixMultipleUnders() { // PSL has both *.uk and *.sch.uk; the latter should win. // See http://code.google.com/p/guava-libraries/issues/detail?id=1176 InternetDomainName domain = InternetDomainName.from("www.essex.sch.uk"); assertTrue(domain.hasPublicSuffix()); assertEquals("essex.sch.uk", domain.publicSuffix().toString()); assertEquals("www.essex.sch.uk", domain.topPrivateDomain().toString()); }
public void testUnderPrivateDomain() { for (String name : UNDER_PRIVATE_DOMAIN) { final InternetDomainName domain = InternetDomainName.from(name); assertFalse(name, domain.isPublicSuffix()); assertTrue(name, domain.hasPublicSuffix()); assertTrue(name, domain.isUnderPublicSuffix()); assertFalse(name, domain.isTopPrivateDomain()); } }
public void testTopPrivateDomain() { for (String name : TOP_PRIVATE_DOMAIN) { final InternetDomainName domain = InternetDomainName.from(name); assertFalse(name, domain.isPublicSuffix()); assertTrue(name, domain.hasPublicSuffix()); assertTrue(name, domain.isUnderPublicSuffix()); assertTrue(name, domain.isTopPrivateDomain()); assertEquals(domain.parent(), domain.publicSuffix()); } }
public void testTopDomainUnderRegistrySuffix() { for (String name : TOP_UNDER_REGISTRY_SUFFIX) { final InternetDomainName domain = InternetDomainName.from(name); assertFalse(name, domain.isRegistrySuffix()); assertTrue(name, domain.hasRegistrySuffix()); assertTrue(name, domain.isUnderRegistrySuffix()); assertTrue(name, domain.isTopDomainUnderRegistrySuffix()); assertEquals(domain.parent(), domain.registrySuffix()); } }