SLING-5343 - Meaningful thread names

- additional tests for ExtendedThreadFactory


git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1717440 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java b/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
index ecdc03b..7240d2d 100644
--- a/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
+++ b/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
@@ -2,46 +2,67 @@
 
 import org.apache.sling.commons.threads.ThreadPoolConfig;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import java.util.concurrent.Executors;
 
+import static org.apache.sling.commons.threads.ThreadPoolConfig.ThreadPriority.MAX;
+import static org.apache.sling.commons.threads.ThreadPoolConfig.ThreadPriority.MIN;
+import static org.apache.sling.commons.threads.ThreadPoolConfig.ThreadPriority.NORM;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 public class ExtendedThreadFactoryTest {
 
-    private static final Logger LOG = LoggerFactory.getLogger(ExtendedThreadFactoryTest.class);
-
     @Test
     public void informativeThreadNames() {
-        final ExtendedThreadFactory tf = createExtendedThreadFactory("Test Pool");
+        final ExtendedThreadFactory tf = factory("Test Pool");
         assertEquals("Thread name", "Sling - Test Pool #1", tf.newThread(null).getName());
         assertEquals("Thread name", "Sling - Test Pool #2", tf.newThread(null).getName());
     }
 
     @Test
     public void shouldStripSlingPrefixFromThreadNames() {
-        final Thread thread = getFirstThreadFromNamedPool("Sling Test Pool");
+        final Thread thread = thread("Sling Test Pool");
         assertEquals("Thread name", "Sling - Test Pool #1", thread.getName());
     }
 
     @Test
     public void shouldStripApacheSlingPrefixFromThreadNames() {
-        final Thread thread = getFirstThreadFromNamedPool("Apache Sling Test Pool");
+        final Thread thread = thread("Apache Sling Test Pool");
         assertEquals("Thread name", "Sling - Test Pool #1", thread.getName());
     }
 
-    private Thread getFirstThreadFromNamedPool(final String poolName) {
-        return createExtendedThreadFactory(poolName).newThread(null);
+    @Test
+    public void shouldSetCorrectPriority() {
+        assertEquals("Thread min priority", Thread.MIN_PRIORITY, thread("Pool", MIN, false).getPriority());
+        assertEquals("Thread normnal priority", Thread.NORM_PRIORITY, thread("Pool", NORM, false).getPriority());
+        assertEquals("Thread max priority", Thread.MAX_PRIORITY, thread("Pool", MAX, false).getPriority());
     }
 
-    private ExtendedThreadFactory createExtendedThreadFactory(final String poolName) {
-        return new ExtendedThreadFactory(
-                Executors.defaultThreadFactory(),
-                poolName,
-                ThreadPoolConfig.ThreadPriority.NORM,
-                false
-        );
+    @Test
+    public void shouldSetDaemonStatusCorrectly() {
+        assertFalse("Non-daemon thread", thread("Pool", NORM, false).isDaemon());
+        assertTrue("Daemon thread", thread("Pool", NORM, true).isDaemon());
+    }
+
+    private Thread thread(final String poolName) {
+        return factory(poolName).newThread(null);
+    }
+
+    private Thread thread(final String poolName,
+                          final ThreadPoolConfig.ThreadPriority priority,
+                          final boolean isDaemon) {
+        return factory(poolName, priority, isDaemon).newThread(null);
+    }
+
+    private ExtendedThreadFactory factory(final String poolName) {
+        return factory(poolName, NORM, false);
+    }
+
+    private ExtendedThreadFactory factory(final String poolName,
+                                          final ThreadPoolConfig.ThreadPriority priority,
+                                          final boolean isDaemon) {
+        return new ExtendedThreadFactory(Executors.defaultThreadFactory(), poolName, priority, isDaemon);
     }
 }