aboutsummaryrefslogtreecommitdiffstats
path: root/guava-tests/test/com/google/common/net
diff options
context:
space:
mode:
Diffstat (limited to 'guava-tests/test/com/google/common/net')
-rw-r--r--guava-tests/test/com/google/common/net/HostAndPortTest.java232
-rw-r--r--guava-tests/test/com/google/common/net/HostSpecifierTest.java2
-rw-r--r--guava-tests/test/com/google/common/net/HttpHeadersTest.java5
-rw-r--r--guava-tests/test/com/google/common/net/InetAddressesTest.java44
-rw-r--r--guava-tests/test/com/google/common/net/InternetDomainNameTest.java15
-rw-r--r--guava-tests/test/com/google/common/net/MediaTypeTest.java432
-rw-r--r--guava-tests/test/com/google/common/net/PackageSanityTests.java31
-rw-r--r--guava-tests/test/com/google/common/net/TestPlatform.java26
8 files changed, 17 insertions, 770 deletions
diff --git a/guava-tests/test/com/google/common/net/HostAndPortTest.java b/guava-tests/test/com/google/common/net/HostAndPortTest.java
deleted file mode 100644
index 476a63b..0000000
--- a/guava-tests/test/com/google/common/net/HostAndPortTest.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.net;
-
-import com.google.common.testing.SerializableTester;
-
-import junit.framework.TestCase;
-
-/**
- * Tests for {@link HostAndPort}
- *
- * @author Paul Marks
- */
-public class HostAndPortTest extends TestCase {
-
- public void testFromStringWellFormed() {
- // Well-formed inputs.
- checkFromStringCase("google.com", 80, "google.com", 80, false);
- checkFromStringCase("google.com", 80, "google.com", 80, false);
- checkFromStringCase("192.0.2.1", 82, "192.0.2.1", 82, false);
- checkFromStringCase("[2001::1]", 84, "2001::1", 84, false);
- checkFromStringCase("2001::3", 86, "2001::3", 86, false);
- checkFromStringCase("host:", 80, "host", 80, false);
- }
-
- public void testFromStringBadDefaultPort() {
- // Well-formed strings with bad default ports.
- checkFromStringCase("gmail.com:81", -1, "gmail.com", 81, true);
- checkFromStringCase("192.0.2.2:83", -1, "192.0.2.2", 83, true);
- checkFromStringCase("[2001::2]:85", -1, "2001::2", 85, true);
- checkFromStringCase("goo.gl:65535", 65536, "goo.gl", 65535, true);
- // No port, bad default.
- checkFromStringCase("google.com", -1, "google.com", -1, false);
- checkFromStringCase("192.0.2.1", 65536, "192.0.2.1", -1, false);
- checkFromStringCase("[2001::1]", -1, "2001::1", -1, false);
- checkFromStringCase("2001::3", 65536, "2001::3", -1, false);
- }
-
- public void testFromStringUnusedDefaultPort() {
- // Default port, but unused.
- checkFromStringCase("gmail.com:81", 77, "gmail.com", 81, true);
- checkFromStringCase("192.0.2.2:83", 77, "192.0.2.2", 83, true);
- checkFromStringCase("[2001::2]:85", 77, "2001::2", 85, true);
- }
-
- public void testFromStringBadPort() {
- // Out-of-range ports.
- checkFromStringCase("google.com:65536", 1, null, 99, false);
- checkFromStringCase("google.com:9999999999", 1, null, 99, false);
- // Invalid port parts.
- checkFromStringCase("google.com:port", 1, null, 99, false);
- checkFromStringCase("google.com:-25", 1, null, 99, false);
- checkFromStringCase("google.com:+25", 1, null, 99, false);
- checkFromStringCase("google.com:25 ", 1, null, 99, false);
- checkFromStringCase("google.com:25\t", 1, null, 99, false);
- checkFromStringCase("google.com:0x25 ", 1, null, 99, false);
- }
-
- public void testFromStringUnparseableNonsense() {
- // Some nonsense that causes parse failures.
- checkFromStringCase("[goo.gl]", 1, null, 99, false);
- checkFromStringCase("[goo.gl]:80", 1, null, 99, false);
- checkFromStringCase("[", 1, null, 99, false);
- checkFromStringCase("[]:", 1, null, 99, false);
- checkFromStringCase("[]:80", 1, null, 99, false);
- checkFromStringCase("[]bad", 1, null, 99, false);
- }
-
- public void testFromStringParseableNonsense() {
- // Examples of nonsense that gets through.
- checkFromStringCase("[[:]]", 86, "[:]", 86, false);
- checkFromStringCase("x:y:z", 87, "x:y:z", 87, false);
- checkFromStringCase("", 88, "", 88, false);
- checkFromStringCase(":", 99, "", 99, false);
- checkFromStringCase(":123", -1, "", 123, true);
- checkFromStringCase("\nOMG\t", 89, "\nOMG\t", 89, false);
- }
-
- private static void checkFromStringCase(
- String hpString,
- int defaultPort,
- String expectHost,
- int expectPort,
- boolean expectHasExplicitPort) {
- HostAndPort hp;
- try {
- hp = HostAndPort.fromString(hpString);
- } catch (IllegalArgumentException e) {
- // Make sure we expected this.
- assertNull(expectHost);
- return;
- }
- assertNotNull(expectHost);
-
- // Apply withDefaultPort(), yielding hp2.
- final boolean badDefaultPort = (defaultPort < 0 || defaultPort > 65535);
- HostAndPort hp2 = null;
- try {
- hp2 = hp.withDefaultPort(defaultPort);
- assertFalse(badDefaultPort);
- } catch (IllegalArgumentException e) {
- assertTrue(badDefaultPort);
- }
-
- // Check the pre-withDefaultPort() instance.
- if (expectHasExplicitPort) {
- assertTrue(hp.hasPort());
- assertEquals(expectPort, hp.getPort());
- } else {
- assertFalse(hp.hasPort());
- try {
- hp.getPort();
- fail("Expected IllegalStateException");
- } catch (IllegalStateException expected) {
- }
- }
- assertEquals(expectHost, hp.getHostText());
-
- // Check the post-withDefaultPort() instance (if any).
- if (!badDefaultPort) {
- try {
- int port = hp2.getPort();
- assertTrue(expectPort != -1);
- assertEquals(expectPort, port);
- } catch (IllegalStateException e) {
- // Make sure we expected this to fail.
- assertEquals(-1, expectPort);
- }
- assertEquals(expectHost, hp2.getHostText());
- }
- }
-
- public void testFromParts() {
- HostAndPort hp = HostAndPort.fromParts("gmail.com", 81);
- assertEquals("gmail.com", hp.getHostText());
- assertTrue(hp.hasPort());
- assertEquals(81, hp.getPort());
-
- try {
- HostAndPort.fromParts("gmail.com:80", 81);
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
-
- try {
- HostAndPort.fromParts("gmail.com", -1);
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
- }
-
- public void testGetPortOrDefault() {
- assertEquals(80, HostAndPort.fromString("host:80").getPortOrDefault(123));
- assertEquals(123, HostAndPort.fromString("host").getPortOrDefault(123));
- }
-
- public void testHashCodeAndEquals() {
- HostAndPort hp1 = HostAndPort.fromString("foo::123");
- HostAndPort hp2 = HostAndPort.fromString("foo::123");
- HostAndPort hp3 = HostAndPort.fromString("[foo::123]");
- HostAndPort hp4 = HostAndPort.fromParts("[foo::123]", 80);
- HostAndPort hp5 = HostAndPort.fromString("[foo::123]:80");
- assertEquals(hp1.hashCode(), hp1.hashCode());
- assertEquals(hp1.hashCode(), hp2.hashCode());
- assertFalse(hp1.hashCode() == hp3.hashCode());
- assertFalse(hp3.hashCode() == hp4.hashCode());
- assertEquals(hp4.hashCode(), hp5.hashCode());
-
- assertTrue(hp1.equals(hp1));
- assertTrue(hp1.equals(hp2));
- assertFalse(hp1.equals(hp3));
- assertFalse(hp3.equals(hp4));
- assertTrue(hp4.equals(hp5));
- assertFalse(hp1.equals(null));
- }
-
- public void testRequireBracketsForIPv6() {
- // Bracketed IPv6 works fine.
- assertEquals("::1", HostAndPort.fromString("[::1]").requireBracketsForIPv6().getHostText());
- assertEquals("::1", HostAndPort.fromString("[::1]:80").requireBracketsForIPv6().getHostText());
- // Non-bracketed non-IPv6 works fine.
- assertEquals("x", HostAndPort.fromString("x").requireBracketsForIPv6().getHostText());
- assertEquals("x", HostAndPort.fromString("x:80").requireBracketsForIPv6().getHostText());
-
- // Non-bracketed IPv6 fails.
- try {
- HostAndPort.fromString("::1").requireBracketsForIPv6();
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
- }
-
- public void testToString() {
- // With ports.
- assertEquals("foo:101", "" + HostAndPort.fromString("foo:101"));
- assertEquals(":102", HostAndPort.fromString(":102").toString());
- assertEquals("[1::2]:103", HostAndPort.fromParts("1::2", 103).toString());
- assertEquals("[::1]:104", HostAndPort.fromString("[::1]:104").toString());
-
- // Without ports.
- assertEquals("foo", "" + HostAndPort.fromString("foo"));
- assertEquals("", HostAndPort.fromString("").toString());
- assertEquals("[1::2]", HostAndPort.fromString("1::2").toString());
- assertEquals("[::1]", HostAndPort.fromString("[::1]").toString());
-
- // Garbage in, garbage out.
- assertEquals("[::]]:107", HostAndPort.fromParts("::]", 107).toString());
- assertEquals("[[:]]:108", HostAndPort.fromString("[[:]]:108").toString());
- }
-
- public void testSerialization() {
- SerializableTester.reserializeAndAssert(HostAndPort.fromParts("host", 80));
- SerializableTester.reserializeAndAssert(HostAndPort.fromString("host"));
- SerializableTester.reserializeAndAssert(HostAndPort.fromString("host:80"));
- SerializableTester.reserializeAndAssert(HostAndPort.fromString("[::1]:104"));
- SerializableTester.reserializeAndAssert(HostAndPort.fromParts("1::2", 103));
- }
-}
diff --git a/guava-tests/test/com/google/common/net/HostSpecifierTest.java b/guava-tests/test/com/google/common/net/HostSpecifierTest.java
index 12c7631..f66c128 100644
--- a/guava-tests/test/com/google/common/net/HostSpecifierTest.java
+++ b/guava-tests/test/com/google/common/net/HostSpecifierTest.java
@@ -87,7 +87,7 @@ public final class HostSpecifierTest extends TestCase {
return HostSpecifier.fromValid(specifier);
}
- public void testNulls() {
+ public void testNulls() throws Exception {
final NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(HostSpecifier.class);
diff --git a/guava-tests/test/com/google/common/net/HttpHeadersTest.java b/guava-tests/test/com/google/common/net/HttpHeadersTest.java
index 4bcf3ff..513767c 100644
--- a/guava-tests/test/com/google/common/net/HttpHeadersTest.java
+++ b/guava-tests/test/com/google/common/net/HttpHeadersTest.java
@@ -30,7 +30,7 @@ import java.util.List;
/**
* Tests for the HttpHeaders class.
*
- * @author Kurt Alfred Kluever
+ * @author Kurt Aflred Kluever
*/
public class HttpHeadersTest extends TestCase {
public void testConstantNameMatchesString() throws Exception {
@@ -47,8 +47,7 @@ public class HttpHeadersTest extends TestCase {
}
private static final ImmutableSet<String> UPPERCASE_ACRONYMS = ImmutableSet.of(
- "ID", "DNT", "GFE", "GSE", "IP", "MD5", "P3P", "TE", "UID", "URL",
- "WWW", "XSS");
+ "ID", "DNT", "GFE", "IP", "MD5", "P3P", "TE", "UID", "URL", "WWW", "XSS");
private static final Splitter SPLITTER = Splitter.on('_');
private static final Joiner JOINER = Joiner.on('-');
diff --git a/guava-tests/test/com/google/common/net/InetAddressesTest.java b/guava-tests/test/com/google/common/net/InetAddressesTest.java
index 90d3285..41564eb 100644
--- a/guava-tests/test/com/google/common/net/InetAddressesTest.java
+++ b/guava-tests/test/com/google/common/net/InetAddressesTest.java
@@ -32,7 +32,7 @@ import java.net.UnknownHostException;
*/
public class InetAddressesTest extends TestCase {
- public void testNulls() {
+ public void testNulls() throws Exception {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(InetAddresses.class);
@@ -241,15 +241,9 @@ public class InetAddressesTest extends TestCase {
assertEquals(expected, InetAddresses.forUriString("[3ffe:0:0:0:0:0:0:1]"));
}
- public void testForUriStringIPv4Mapped() {
- Inet4Address expected = (Inet4Address) InetAddresses.forString("192.0.2.1");
- assertEquals(expected, InetAddresses.forUriString("[::ffff:192.0.2.1]"));
- }
-
public void testIsUriInetAddress() {
assertTrue(InetAddresses.isUriInetAddress("192.168.1.1"));
assertTrue(InetAddresses.isUriInetAddress("[3ffe:0:0:0:0:0:0:1]"));
- assertTrue(InetAddresses.isUriInetAddress("[::ffff:192.0.2.1]"));
assertFalse(InetAddresses.isUriInetAddress("[192.168.1.1"));
assertFalse(InetAddresses.isUriInetAddress("192.168.1.1]"));
@@ -259,8 +253,6 @@ public class InetAddressesTest extends TestCase {
assertFalse(InetAddresses.isUriInetAddress("1:2e"));
assertFalse(InetAddresses.isUriInetAddress("[3ffe:0:0:0:0:0:0:1"));
assertFalse(InetAddresses.isUriInetAddress("3ffe:0:0:0:0:0:0:1]"));
- assertFalse(InetAddresses.isUriInetAddress("3ffe:0:0:0:0:0:0:1"));
- assertFalse(InetAddresses.isUriInetAddress("::ffff:192.0.2.1"));
}
public void testForUriStringBad() {
@@ -326,20 +318,6 @@ public class InetAddressesTest extends TestCase {
} catch (IllegalArgumentException e) {
// expected
}
-
- try {
- InetAddresses.forUriString("3ffe:0:0:0:0:0:0:1");
- fail("expected IllegalArgumentException"); // COV_NF_LINE
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- InetAddresses.forUriString("::ffff:192.0.2.1");
- fail("expected IllegalArgumentException"); // COV_NF_LINE
- } catch (IllegalArgumentException e) {
- // expected
- }
}
public void testCompatIPv4Addresses() {
@@ -489,14 +467,6 @@ public class InetAddressesTest extends TestCase {
assertEquals(flags, teredo.getFlags());
}
- public void testTeredoAddress_nullServer() {
- InetAddresses.TeredoInfo info = new InetAddresses.TeredoInfo(null, null, 80, 1000);
- assertEquals(InetAddresses.forString("0.0.0.0"), info.getServer());
- assertEquals(InetAddresses.forString("0.0.0.0"), info.getClient());
- assertEquals(80, info.getPort());
- assertEquals(1000, info.getFlags());
- }
-
public void testIsatapAddresses() {
InetAddress ipv4 = InetAddresses.forString("1.2.3.4");
String[] validIsatapAddresses = {
@@ -637,6 +607,14 @@ public class InetAddressesTest extends TestCase {
assertTrue(InetAddresses.coerceToInteger(coerced) <= 0xfffffffe);
}
+ public void testHash64To32() {
+ // Make sure the output looks reasonably sane.
+ assertEquals(532412650, InetAddresses.hash64To32(-1));
+ assertEquals(720020139, InetAddresses.hash64To32(0));
+ assertEquals(357654460, InetAddresses.hash64To32(1));
+ assertEquals(-1977349188, InetAddresses.hash64To32(0x7fffffffffffffffL));
+ }
+
public void testToInteger() {
InetAddress ipv4Addr = InetAddresses.forString("127.0.0.1");
assertEquals(0x7f000001, InetAddresses.coerceToInteger(ipv4Addr));
@@ -699,7 +677,7 @@ public class InetAddressesTest extends TestCase {
try {
address = InetAddresses.increment(address);
fail();
- } catch (IllegalArgumentException expected) {}
+ } catch (IllegalArgumentException expected) { }
}
public void testIncrementIPv6() throws UnknownHostException {
@@ -722,6 +700,6 @@ public class InetAddressesTest extends TestCase {
try {
address = InetAddresses.increment(address);
fail();
- } catch (IllegalArgumentException expected) {}
+ } catch (IllegalArgumentException expected) { }
}
}
diff --git a/guava-tests/test/com/google/common/net/InternetDomainNameTest.java b/guava-tests/test/com/google/common/net/InternetDomainNameTest.java
index 7291286..1fb869f 100644
--- a/guava-tests/test/com/google/common/net/InternetDomainNameTest.java
+++ b/guava-tests/test/com/google/common/net/InternetDomainNameTest.java
@@ -370,7 +370,7 @@ public final class InternetDomainNameTest extends TestCase {
}
public void testExclusion() {
- InternetDomainName domain = InternetDomainName.from("foo.nic.uk");
+ InternetDomainName domain = InternetDomainName.from("foo.nhs.uk");
assertTrue(domain.hasPublicSuffix());
assertEquals("uk", domain.publicSuffix().name());
@@ -378,16 +378,6 @@ public final class InternetDomainNameTest extends TestCase {
assertFalse(domain.publicSuffix().isPublicSuffix());
}
- public void testMultipleUnders() {
- // PSL has both *.uk and *.police.uk; the latter should win.
- // See http://code.google.com/p/guava-libraries/issues/detail?id=1176
-
- InternetDomainName domain = InternetDomainName.from("www.essex.police.uk");
- assertTrue(domain.hasPublicSuffix());
- assertEquals("essex.police.uk", domain.publicSuffix().name());
- assertEquals("www.essex.police.uk", domain.topPrivateDomain().name());
- }
-
public void testEquality() {
new EqualsTester()
.addEqualityGroup(
@@ -403,10 +393,11 @@ public final class InternetDomainNameTest extends TestCase {
}
@GwtIncompatible("NullPointerTester")
- public void testNulls() {
+ public void testNulls() throws Exception {
final NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(InternetDomainName.class);
tester.testAllPublicInstanceMethods(InternetDomainName.from("google.com"));
}
+
}
diff --git a/guava-tests/test/com/google/common/net/MediaTypeTest.java b/guava-tests/test/com/google/common/net/MediaTypeTest.java
deleted file mode 100644
index 12efed6..0000000
--- a/guava-tests/test/com/google/common/net/MediaTypeTest.java
+++ /dev/null
@@ -1,432 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.net;
-
-import static com.google.common.base.Charsets.UTF_16;
-import static com.google.common.base.Charsets.UTF_8;
-import static com.google.common.net.MediaType.ANY_APPLICATION_TYPE;
-import static com.google.common.net.MediaType.ANY_AUDIO_TYPE;
-import static com.google.common.net.MediaType.ANY_IMAGE_TYPE;
-import static com.google.common.net.MediaType.ANY_TEXT_TYPE;
-import static com.google.common.net.MediaType.ANY_TYPE;
-import static com.google.common.net.MediaType.ANY_VIDEO_TYPE;
-import static com.google.common.net.MediaType.HTML_UTF_8;
-import static com.google.common.net.MediaType.JPEG;
-import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
-import static java.lang.reflect.Modifier.isFinal;
-import static java.lang.reflect.Modifier.isPublic;
-import static java.lang.reflect.Modifier.isStatic;
-import static java.util.Arrays.asList;
-
-import com.google.common.annotations.Beta;
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.annotations.GwtIncompatible;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.base.Throwables;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableListMultimap;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.testing.EqualsTester;
-import com.google.common.testing.NullPointerTester;
-
-import junit.framework.TestCase;
-
-import java.lang.reflect.Field;
-import java.nio.charset.Charset;
-import java.nio.charset.IllegalCharsetNameException;
-import java.nio.charset.UnsupportedCharsetException;
-
-/**
- * Tests for {@link MediaType}.
- *
- * @author Gregory Kick
- */
-@Beta
-@GwtCompatible(emulated = true)
-public class MediaTypeTest extends TestCase {
- @GwtIncompatible("reflection") public void testParse_useConstants() throws Exception {
- for (MediaType constant : getConstants()) {
- assertSame(constant, MediaType.parse(constant.toString()));
- }
- }
-
- @GwtIncompatible("reflection") public void testCreate_useConstants() throws Exception {
- for (MediaType constant : getConstants()) {
- assertSame(constant, MediaType.create(constant.type(), constant.subtype())
- .withParameters(constant.parameters()));
- }
- }
-
- @GwtIncompatible("reflection") public void testConstants_charset() throws Exception {
- for (Field field : getConstantFields()) {
- Optional<Charset> charset = ((MediaType) field.get(null)).charset();
- if (field.getName().endsWith("_UTF_8")) {
- assertEquals(Optional.of(UTF_8), charset);
- } else {
- assertEquals(Optional.absent(), charset);
- }
- }
- }
-
- @GwtIncompatible("reflection") private static FluentIterable<Field> getConstantFields() {
- return FluentIterable.from(asList(MediaType.class.getDeclaredFields()))
- .filter(new Predicate<Field>() {
- @Override public boolean apply(Field input) {
- int modifiers = input.getModifiers();
- return isPublic(modifiers) && isStatic(modifiers) && isFinal(modifiers)
- && MediaType.class.equals(input.getType());
- }
- });
- }
-
- @GwtIncompatible("reflection") private static FluentIterable<MediaType> getConstants() {
- return getConstantFields()
- .transform(new Function<Field, MediaType>() {
- @Override public MediaType apply(Field input) {
- try {
- return (MediaType) input.get(null);
- } catch (Exception e) {
- throw Throwables.propagate(e);
- }
- }
- });
- }
-
- public void testCreate_invalidType() {
- try {
- MediaType.create("te><t", "plaintext");
- fail();
- } catch (IllegalArgumentException expected) {}
- }
-
- public void testCreate_invalidSubtype() {
- try {
- MediaType.create("text", "pl@intext");
- fail();
- } catch (IllegalArgumentException expected) {}
- }
-
- public void testCreate_wildcardTypeDeclaredSubtype() {
- try {
- MediaType.create("*", "text");
- fail();
- } catch (IllegalArgumentException expected) {}
- }
-
- public void testCreateApplicationType() {
- MediaType newType = MediaType.createApplicationType("yams");
- assertEquals("application", newType.type());
- assertEquals("yams", newType.subtype());
- }
-
- public void testCreateAudioType() {
- MediaType newType = MediaType.createAudioType("yams");
- assertEquals("audio", newType.type());
- assertEquals("yams", newType.subtype());
- }
-
- public void testCreateImageType() {
- MediaType newType = MediaType.createImageType("yams");
- assertEquals("image", newType.type());
- assertEquals("yams", newType.subtype());
- }
-
- public void testCreateTextType() {
- MediaType newType = MediaType.createTextType("yams");
- assertEquals("text", newType.type());
- assertEquals("yams", newType.subtype());
- }
-
- public void testCreateVideoType() {
- MediaType newType = MediaType.createVideoType("yams");
- assertEquals("video", newType.type());
- assertEquals("yams", newType.subtype());
- }
-
- public void testGetType() {
- assertEquals("text", MediaType.parse("text/plain").type());
- assertEquals("application",
- MediaType.parse("application/atom+xml; charset=utf-8").type());
- }
-
- public void testGetSubtype() {
- assertEquals("plain", MediaType.parse("text/plain").subtype());
- assertEquals("atom+xml",
- MediaType.parse("application/atom+xml; charset=utf-8").subtype());
- }
-
- private static final ImmutableListMultimap<String, String> PARAMETERS =
- ImmutableListMultimap.of("a", "1", "a", "2", "b", "3");
-
- public void testGetParameters() {
- assertEquals(ImmutableListMultimap.of(), MediaType.parse("text/plain").parameters());
- assertEquals(ImmutableListMultimap.of("charset", "utf-8"),
- MediaType.parse("application/atom+xml; charset=utf-8").parameters());
- assertEquals(PARAMETERS,
- MediaType.parse("application/atom+xml; a=1; a=2; b=3").parameters());
- }
-
- public void testWithoutParameters() {
- assertSame(MediaType.parse("image/gif"),
- MediaType.parse("image/gif").withoutParameters());
- assertEquals(MediaType.parse("image/gif"),
- MediaType.parse("image/gif; foo=bar").withoutParameters());
- }
-
- public void testWithParameters() {
- assertEquals(MediaType.parse("text/plain; a=1; a=2; b=3"),
- MediaType.parse("text/plain").withParameters(PARAMETERS));
- assertEquals(MediaType.parse("text/plain; a=1; a=2; b=3"),
- MediaType.parse("text/plain; a=1; a=2; b=3").withParameters(PARAMETERS));
- }
-
- public void testWithParameters_invalidAttribute() {
- MediaType mediaType = MediaType.parse("text/plain");
- ImmutableListMultimap<String, String> parameters =
- ImmutableListMultimap.of("a", "1", "@", "2", "b", "3");
- try {
- mediaType.withParameters(parameters);
- fail();
- } catch (IllegalArgumentException expected) {}
- }
-
- public void testWithParameter() {
- assertEquals(MediaType.parse("text/plain; a=1"),
- MediaType.parse("text/plain").withParameter("a", "1"));
- assertEquals(MediaType.parse("text/plain; a=1"),
- MediaType.parse("text/plain; a=1; a=2").withParameter("a", "1"));
- assertEquals(MediaType.parse("text/plain; a=3"),
- MediaType.parse("text/plain; a=1; a=2").withParameter("a", "3"));
- assertEquals(MediaType.parse("text/plain; a=1; a=2; b=3"),
- MediaType.parse("text/plain; a=1; a=2").withParameter("b", "3"));
- }
-
- public void testWithParameter_invalidAttribute() {
- MediaType mediaType = MediaType.parse("text/plain");
- try {
- mediaType.withParameter("@", "2");
- fail();
- } catch (IllegalArgumentException expected) {}
- }
-
- public void testWithCharset() {
- assertEquals(MediaType.parse("text/plain; charset=utf-8"),
- MediaType.parse("text/plain").withCharset(UTF_8));
- assertEquals(MediaType.parse("text/plain; charset=utf-8"),
- MediaType.parse("text/plain; charset=utf-16").withCharset(UTF_8));
- }
-
- public void testHasWildcard() {
- assertFalse(PLAIN_TEXT_UTF_8.hasWildcard());
- assertFalse(JPEG.hasWildcard());
- assertTrue(ANY_TYPE.hasWildcard());
- assertTrue(ANY_APPLICATION_TYPE.hasWildcard());
- assertTrue(ANY_AUDIO_TYPE.hasWildcard());
- assertTrue(ANY_IMAGE_TYPE.hasWildcard());
- assertTrue(ANY_TEXT_TYPE.hasWildcard());
- assertTrue(ANY_VIDEO_TYPE.hasWildcard());
- }
-
- public void testIs() {
- assertTrue(PLAIN_TEXT_UTF_8.is(ANY_TYPE));
- assertTrue(JPEG.is(ANY_TYPE));
- assertTrue(ANY_TEXT_TYPE.is(ANY_TYPE));
- assertTrue(PLAIN_TEXT_UTF_8.is(ANY_TEXT_TYPE));
- assertTrue(PLAIN_TEXT_UTF_8.withoutParameters().is(ANY_TEXT_TYPE));
- assertFalse(JPEG.is(ANY_TEXT_TYPE));
- assertTrue(PLAIN_TEXT_UTF_8.is(PLAIN_TEXT_UTF_8));
- assertTrue(PLAIN_TEXT_UTF_8.is(PLAIN_TEXT_UTF_8.withoutParameters()));
- assertFalse(PLAIN_TEXT_UTF_8.withoutParameters().is(PLAIN_TEXT_UTF_8));
- assertFalse(PLAIN_TEXT_UTF_8.is(HTML_UTF_8));
- assertFalse(PLAIN_TEXT_UTF_8.withParameter("charset", "UTF-16").is(PLAIN_TEXT_UTF_8));
- assertFalse(PLAIN_TEXT_UTF_8.is(PLAIN_TEXT_UTF_8.withParameter("charset", "UTF-16")));
- }
-
- public void testParse_empty() {
- try {
- MediaType.parse("");
- fail();
- } catch (IllegalArgumentException expected) {}
- }
-
- public void testParse_badInput() {
- try {
- MediaType.parse("/");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("te<t/plain");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/pl@in");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain;");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain; ");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain; a");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain; a=");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain; a=@");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain; a=\"@");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain; a=1;");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain; a=1; ");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain; a=1; b");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain; a=1; b=");
- fail();
- } catch (IllegalArgumentException expected) {}
- try {
- MediaType.parse("text/plain; a=\u2025");
- fail();
- } catch (IllegalArgumentException expected) {}
- }
-
- public void testGetCharset() {
- assertEquals(Optional.absent(), MediaType.parse("text/plain").charset());
- assertEquals(Optional.of(UTF_8),
- MediaType.parse("text/plain; charset=utf-8").charset());
- }
-
- @GwtIncompatible("Non-UTF-8 Charset") public void testGetCharset_utf16() {
- assertEquals(Optional.of(UTF_16),
- MediaType.parse("text/plain; charset=utf-16").charset());
- }
-
- public void testGetCharset_tooMany() {
- MediaType mediaType = MediaType.parse("text/plain; charset=utf-8; charset=utf-16");
- try {
- mediaType.charset();
- fail();
- } catch (IllegalStateException expected) {}
- }
-
- public void testGetCharset_illegalCharset() {
- MediaType mediaType = MediaType.parse(
- "text/plain; charset=\"!@#$%^&*()\"");
- try {
- mediaType.charset();
- fail();
- } catch (IllegalCharsetNameException expected) {}
- }
-
- public void testGetCharset_unsupportedCharset() {
- MediaType mediaType = MediaType.parse(
- "text/plain; charset=utf-wtf");
- try {
- mediaType.charset();
- fail();
- } catch (UnsupportedCharsetException expected) {}
- }
-
- public void testEquals() {
- new EqualsTester()
- .addEqualityGroup(MediaType.create("text", "plain"),
- MediaType.create("TEXT", "PLAIN"),
- MediaType.parse("text/plain"),
- MediaType.parse("TEXT/PLAIN"),
- MediaType.create("text", "plain").withParameter("a", "1").withoutParameters())
- .addEqualityGroup(
- MediaType.create("text", "plain").withCharset(UTF_8),
- MediaType.create("text", "plain").withParameter("CHARSET", "UTF-8"),
- MediaType.create("text", "plain").withParameters(
- ImmutableMultimap.of("charset", "utf-8")),
- MediaType.parse("text/plain;charset=utf-8"),
- MediaType.parse("text/plain; charset=utf-8"),
- MediaType.parse("text/plain; charset=utf-8"),
- MediaType.parse("text/plain; \tcharset=utf-8"),
- MediaType.parse("text/plain; \r\n\tcharset=utf-8"),
- MediaType.parse("text/plain; CHARSET=utf-8"),
- MediaType.parse("text/plain; charset=\"utf-8\""),
- MediaType.parse("text/plain; charset=\"\\u\\tf-\\8\""),
- MediaType.parse("text/plain; charset=UTF-8"))
- .addEqualityGroup(MediaType.parse("text/plain; charset=utf-8; charset=utf-8"))
- .addEqualityGroup(MediaType.create("text", "plain").withParameter("a", "value"),
- MediaType.create("text", "plain").withParameter("A", "value"))
- .addEqualityGroup(MediaType.create("text", "plain").withParameter("a", "VALUE"),
- MediaType.create("text", "plain").withParameter("A", "VALUE"))
- .addEqualityGroup(
- MediaType.create("text", "plain")
- .withParameters(ImmutableListMultimap.of("a", "1", "a", "2")),
- MediaType.create("text", "plain")
- .withParameters(ImmutableListMultimap.of("a", "2", "a", "1")))
- .addEqualityGroup(MediaType.create("text", "csv"))
- .addEqualityGroup(MediaType.create("application", "atom+xml"))
- .testEquals();
- }
-
- @GwtIncompatible("Non-UTF-8 Charset") public void testEquals_nonUtf8Charsets() {
- new EqualsTester()
- .addEqualityGroup(MediaType.create("text", "plain"))
- .addEqualityGroup(MediaType.create("text", "plain").withCharset(UTF_8))
- .addEqualityGroup(MediaType.create("text", "plain").withCharset(UTF_16))
- .testEquals();
- }
-
- @GwtIncompatible("com.google.common.testing.NullPointerTester")
- public void testNullPointer() {
- NullPointerTester tester = new NullPointerTester();
- tester.testAllPublicConstructors(MediaType.class);
- tester.testAllPublicStaticMethods(MediaType.class);
- tester.testAllPublicInstanceMethods(MediaType.parse("text/plain"));
- }
-
- public void testToString() {
- assertEquals("text/plain", MediaType.create("text", "plain").toString());
- assertEquals("text/plain; something=\"cr@zy\"; something-else=\"crazy with spaces\"",
- MediaType.create("text", "plain")
- .withParameter("something", "cr@zy")
- .withParameter("something-else", "crazy with spaces")
- .toString());
- }
-}
diff --git a/guava-tests/test/com/google/common/net/PackageSanityTests.java b/guava-tests/test/com/google/common/net/PackageSanityTests.java
deleted file mode 100644
index 3d18ad6..0000000
--- a/guava-tests/test/com/google/common/net/PackageSanityTests.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2012 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.net;
-
-import com.google.common.testing.AbstractPackageSanityTests;
-
-/**
- * Basic sanity tests for the entire package.
- *
- * @author Ben Yu
- */
-
-public class PackageSanityTests extends AbstractPackageSanityTests {
- public PackageSanityTests() {
- setDefault(InternetDomainName.class, InternetDomainName.from("google.com"));
- }
-}
diff --git a/guava-tests/test/com/google/common/net/TestPlatform.java b/guava-tests/test/com/google/common/net/TestPlatform.java
deleted file mode 100644
index 39301d5..0000000
--- a/guava-tests/test/com/google/common/net/TestPlatform.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.net;
-
-import com.google.common.annotations.GwtCompatible;
-
-/**
- * @author Hayward Chan
- */
-@GwtCompatible(emulated = true)
-class TestPlatform {
-}