blob: b13e4a7af22600b53af3af81dca62c97c08ab893 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.concurrent;
import org.junit.Test;
import java.util.concurrent.ThreadFactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author baldersheim
*/
public class ThreadFactoryFactoryTest {
static class Runner implements Runnable {
@Override
public void run() {
}
}
@Test
public void requireThatFactoryCreatesCorrectlyNamedThreads() {
Thread thread = ThreadFactoryFactory.getThreadFactory("a").newThread(new Runner());
assertEquals("a-1-thread-1", thread.getName());
thread = ThreadFactoryFactory.getThreadFactory("a").newThread(new Runner());
assertEquals("a-2-thread-1", thread.getName());
thread = ThreadFactoryFactory.getThreadFactory("b").newThread(new Runner());
assertEquals("b-1-thread-1", thread.getName());
ThreadFactory factory = ThreadFactoryFactory.getThreadFactory("a");
thread = factory.newThread(new Runner());
assertEquals("a-3-thread-1", thread.getName());
thread = factory.newThread(new Runner());
assertEquals("a-3-thread-2", thread.getName());
thread = factory.newThread(new Runner());
assertEquals("a-3-thread-3", thread.getName());
}
}
|