Merge pull request #544 from CruzBishop/testcases-1
More test cases (Round one)
This commit is contained in:
commit
e2cafa9ec1
@ -53,6 +53,20 @@ public class InternalLoggerFactoryTest {
|
||||
public void shouldReturnWrappedLogger() {
|
||||
assertNotSame(mock, InternalLoggerFactory.getInstance("mock"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetInstance() {
|
||||
InternalLoggerFactory.setDefaultFactory(oldLoggerFactory);
|
||||
|
||||
String helloWorld = "Hello, world!";
|
||||
|
||||
InternalLogger one = InternalLoggerFactory.getInstance("helloWorld");
|
||||
InternalLogger two = InternalLoggerFactory.getInstance(helloWorld.getClass());
|
||||
|
||||
assertNotNull(one);
|
||||
assertNotNull(two);
|
||||
assertNotSame(one, two);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsTraceEnabled() {
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
37
common/src/test/java/io/netty/util/NetworkConstantsTest.java
Normal file
37
common/src/test/java/io/netty/util/NetworkConstantsTest.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
@ -17,8 +17,10 @@ package io.netty.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -45,6 +47,21 @@ public class UniqueNameTest {
|
||||
this.names = new ConcurrentHashMap<String, Boolean>();
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testCannnotProvideNullMap() {
|
||||
UniqueName nullName = new UniqueName(null, "Nothing");
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testCannotProvideNullName() {
|
||||
UniqueName nullName = new UniqueName(this.names, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgsCanBePassed() {
|
||||
UniqueName nullName = new UniqueName(this.names, "Argh, matey!", 2, 5, new Object());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisteringName() {
|
||||
registerName("Abcedrian");
|
||||
@ -78,10 +95,28 @@ public class UniqueNameTest {
|
||||
nameList.add(currentName);
|
||||
for (UniqueName otherName : nameList) {
|
||||
if (!currentName.name().equals(otherName.name())) {
|
||||
assertNotSame(currentName.id(), otherName.name());
|
||||
assertNotSame(currentName, otherName);
|
||||
assertNotSame(currentName.hashCode(), otherName.hashCode());
|
||||
assertFalse(currentName.equals(otherName));
|
||||
assertNotSame(currentName.toString(), otherName.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareNames() {
|
||||
UniqueName one = registerName("One");
|
||||
UniqueName two = registerName("Two");
|
||||
|
||||
ConcurrentHashMap<String, Boolean> mapTwo = new ConcurrentHashMap<String, Boolean>();
|
||||
|
||||
UniqueName three = new UniqueName(mapTwo, "One");
|
||||
|
||||
assertSame(one.compareTo(one), 0);
|
||||
assertSame(one.compareTo(two), -5);
|
||||
assertSame(one.compareTo(three), -1);
|
||||
assertSame(three.compareTo(one), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user