Adds some more test cases

This adds test cases to test against:

	1: DefaultAttributeMap / DefaultAttribute (100%)
	2: NetworkConstants (61.9%, functionally 100%)
	3: StringUtil (50%, functionally 100%)

Signed-off-by: Cruz Julian Bishop <cruzjbishop@gmail.com>
This commit is contained in:
Cruz Julian Bishop 2012-08-21 10:20:21 +10:00
parent b3a9ee1d71
commit 11d9334dee
3 changed files with 145 additions and 0 deletions

View File

@ -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<String> key = new AttributeKey<String>("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<Integer> key = new AttributeKey<Integer>("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());
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}