|
| 1 | +package com.github.bordertech.taskmaster.logical; |
| 2 | + |
| 3 | +import org.junit.Assert; |
| 4 | +import org.junit.Test; |
| 5 | + |
| 6 | +/** |
| 7 | + * Unit tests for {@link LogicalThreadPool}. |
| 8 | + */ |
| 9 | +public class LogicalThreadPoolTest { |
| 10 | + |
| 11 | + @Test |
| 12 | + public void testConstructor1() { |
| 13 | + LogicalThreadPool pool = new LogicalThreadPool(); |
| 14 | + Assert.assertEquals("Incorrect pool name for default constructor", "default", pool.getName()); |
| 15 | + Assert.assertEquals("Incorrect max threads for default constructor", 0, pool.getMax()); |
| 16 | + } |
| 17 | + |
| 18 | + @Test |
| 19 | + public void testConstructor2() { |
| 20 | + LogicalThreadPool pool = new LogicalThreadPool("foo", 5); |
| 21 | + Assert.assertEquals("Incorrect name for constructor", "foo", pool.getName()); |
| 22 | + Assert.assertEquals("Incorrect default max threads for constructor", 5, pool.getMax()); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testDefaultShutdown() { |
| 27 | + Assert.assertFalse("Pool should not be shutdown.", new LogicalThreadPool().isShutdown()); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testNameDefault() { |
| 32 | + Assert.assertEquals("Pool name should be default for default constructor", "default", new LogicalThreadPool().getName()); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testNameNull() { |
| 37 | + Assert.assertEquals("Pool name should be default for null in constructor", "default", new LogicalThreadPool(null, 0).getName()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testNameEmpty() { |
| 42 | + Assert.assertEquals("Pool name should be default for empty in constructor", "default", new LogicalThreadPool("", 0).getName()); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testNameValue() { |
| 47 | + Assert.assertEquals("Pool name should be default for value in constructor", "foo", new LogicalThreadPool("foo", 0).getName()); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testMaxDefault() { |
| 52 | + Assert.assertEquals("Pool max should default to zero (no limit).", 0, new LogicalThreadPool().getMax()); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testMaxNegative() { |
| 57 | + Assert.assertEquals("Pool max should be zero for negative constructor value.", 0, new LogicalThreadPool(null, -1).getMax()); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testMaxZero() { |
| 62 | + Assert.assertEquals("Pool max should be zero for zero constructor value.", 0, new LogicalThreadPool(null, 0).getMax()); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void testMaxPositive() { |
| 67 | + Assert.assertEquals("Pool max should be positive value.", 10, new LogicalThreadPool(null, 10).getMax()); |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments