More test cases: Round one

This tests the following classes more:

1: InternalLoggerFactoryTest
	Tests InternalLoggerFactory.getInstance(Class)

2: UniqueName
	Paired with #543, this achieves 100% code coverage with tests

Signed-off-by: Cruz Julian Bishop <cruzjbishop@gmail.com>
This commit is contained in:
Cruz Julian Bishop 2012-08-21 09:32:00 +10:00
parent b25996d024
commit 6e3b9ed634
2 changed files with 52 additions and 2 deletions

View File

@ -54,6 +54,20 @@ public class InternalLoggerFactoryTest {
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() {
expect(mock.isTraceEnabled()).andReturn(true);

View File

@ -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,29 @@ 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.compareTo(otherName), 0);
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);
}
}