1 package com.atlassian.plugin.instrumentation;
2
3 import com.atlassian.instrumentation.operations.OpTimer;
4 import org.junit.Test;
5
6 import java.util.Optional;
7
8 import static com.atlassian.plugin.test.Matchers.notPresent;
9 import static com.atlassian.plugin.test.Matchers.presentWithValue;
10 import static org.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.core.Is.is;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.verify;
14
15 public class TestTimer {
16
17 @Test
18 public void endsOnClose() {
19 final OpTimer opTimer = mock(OpTimer.class);
20
21 try (Timer timer = new Timer(Optional.of(opTimer))) {
22 assertThat(timer.getOpTimer(), presentWithValue(is(opTimer)));
23 }
24
25 verify(opTimer).end();
26 }
27
28 @Test
29 public void closesWithEmpty() {
30 try (Timer timer = new Timer(Optional.empty())) {
31 assertThat(timer.getOpTimer(), notPresent());
32 }
33 }
34 }