diff --git a/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java b/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java new file mode 100644 index 0000000000..97422ab645 --- /dev/null +++ b/common/src/test/java/io/netty/util/DefaultAttributeMapTest.java @@ -0,0 +1,80 @@ +/* + * Copyright 2012 The Netty Project + * + * The Netty Project licenses this file to you 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 io.netty.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import org.junit.Before; +import org.junit.Test; + +public class DefaultAttributeMapTest { + + private DefaultAttributeMap map; + + @Before + public void setup() { + this.map = new DefaultAttributeMap(); + } + + @Test + public void testMapExists() { + assertNotNull(this.map); + } + + @Test + public void testGetSetString() { + AttributeKey key = new AttributeKey("Nothing"); + Attribute one = this.map.attr(key); + + assertSame(one, this.map.attr(key)); + + one.setIfAbsent("Whoohoo"); + + assertSame(one.get(), "Whoohoo"); + + one.setIfAbsent("What"); + + assertNotSame(one.get(), "What"); + + one.remove(); + + assertNull(one.get()); + } + + @Test + public void testGetSetInt() { + AttributeKey key = new AttributeKey("Nada"); + Attribute one = this.map.attr(key); + + assertSame(one, this.map.attr(key)); + + one.setIfAbsent(3653); + + assertEquals(one.get(), 3653); + + one.setIfAbsent(1); + + assertNotSame(one.get(), 1); + + one.remove(); + + assertNull(one.get()); + } + +} diff --git a/common/src/test/java/io/netty/util/NetworkConstantsTest.java b/common/src/test/java/io/netty/util/NetworkConstantsTest.java new file mode 100644 index 0000000000..46321d8bb6 --- /dev/null +++ b/common/src/test/java/io/netty/util/NetworkConstantsTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012 The Netty Project + * + * The Netty Project licenses this file to you 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 io.netty.util; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import org.junit.Test; + +public class NetworkConstantsTest { + + @Test + public void testLocalhost() throws UnknownHostException { + assertNotNull(NetworkConstants.LOCALHOST); + assertSame(NetworkConstants.LOCALHOST, InetAddress.getLocalHost()); + } + + @Test + public void testLoopback() throws UnknownHostException { + assertNotNull(NetworkConstants.LOOPBACK_IF); + } + +} diff --git a/common/src/test/java/io/netty/util/internal/StringUtilTest.java b/common/src/test/java/io/netty/util/internal/StringUtilTest.java new file mode 100644 index 0000000000..82afd97d8f --- /dev/null +++ b/common/src/test/java/io/netty/util/internal/StringUtilTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2012 The Netty Project + * + * The Netty Project licenses this file to you 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 io.netty.util.internal; + +import static org.junit.Assert.assertNotNull; +import org.junit.Test; + +public class StringUtilTest { + + @Test + public void ensureNewlineExists() { + assertNotNull(StringUtil.NEWLINE); + } + +}