From 6e3b9ed634df77933ccc10e545a2b265bdee4cf2 Mon Sep 17 00:00:00 2001 From: Cruz Julian Bishop Date: Tue, 21 Aug 2012 09:32:00 +1000 Subject: [PATCH] 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 --- .../logging/InternalLoggerFactoryTest.java | 14 +++++++ .../java/io/netty/util/UniqueNameTest.java | 40 ++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/common/src/test/java/io/netty/logging/InternalLoggerFactoryTest.java b/common/src/test/java/io/netty/logging/InternalLoggerFactoryTest.java index 0217e8a5a6..5763f2b697 100644 --- a/common/src/test/java/io/netty/logging/InternalLoggerFactoryTest.java +++ b/common/src/test/java/io/netty/logging/InternalLoggerFactoryTest.java @@ -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() { diff --git a/common/src/test/java/io/netty/util/UniqueNameTest.java b/common/src/test/java/io/netty/util/UniqueNameTest.java index ac04603cb6..2890e00171 100644 --- a/common/src/test/java/io/netty/util/UniqueNameTest.java +++ b/common/src/test/java/io/netty/util/UniqueNameTest.java @@ -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(); } + @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 mapTwo = new ConcurrentHashMap(); + + 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); + } }