blob: b2c644ce68f8a8504e386de4f1086664cf913c65 (
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
45
46
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.jdisc;
import com.yahoo.container.jdisc.metric.MetricConsumerProvider;
import com.yahoo.jdisc.application.ContainerThread;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.concurrent.ThreadFactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
*/
public class ContainerThreadFactoryTest {
@Test
public void requireThatMetricConsumerProviderCanNotBeNull() {
try {
new ContainerThreadFactory(null);
fail();
} catch (NullPointerException e) {
}
}
@Test
public void requireThatThreadsCreatedAreJDiscContainerThreads() {
assertEquals(ContainerThread.class,
new ContainerThreadFactory(Mockito.mock(MetricConsumerProvider.class))
.newThread(Mockito.mock(Runnable.class))
.getClass());
}
@Test
public void requireThatThreadFactoryCallsProvider() {
MetricConsumerProvider provider = Mockito.mock(MetricConsumerProvider.class);
ThreadFactory factory = new ContainerThreadFactory(provider);
factory.newThread(Mockito.mock(Runnable.class));
Mockito.verify(provider, Mockito.times(1)).newInstance();
factory.newThread(Mockito.mock(Runnable.class));
Mockito.verify(provider, Mockito.times(2)).newInstance();
}
}
|