blob: 7fc6a9cc3902cae58d2972f4b5a0f22578cdd1fc (
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
41
42
43
44
|
// 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;
/**
* Created with IntelliJ IDEA.
* User: balder
* Date: 26.04.13
* Time: 12:01
* To change this template use File | Settings | File Templates.
*/
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());
}
}
|