Skip to content

Commit 8081fb5

Browse files
authored
Merge pull request #570 from metafacture/495-testDrarft
2 parents 18b6ae0 + 03bc009 commit 8081fb5

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2024 Tobias Bülte, hbz
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.flowcontrol;
18+
19+
import static org.junit.Assert.assertTrue;
20+
21+
import org.metafacture.framework.ObjectReceiver;
22+
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.mockito.Mock;
26+
import org.mockito.MockitoAnnotations;
27+
28+
import java.time.Duration;
29+
import java.time.Instant;
30+
31+
/**
32+
* Tests for class {@link ObjectSleeper}.
33+
*
34+
* @author Tobias Bülte
35+
*
36+
*/
37+
public final class ObjectSleeperTest {
38+
39+
@Mock
40+
private ObjectReceiver<String> receiver;
41+
42+
@Before
43+
public void setup() {
44+
MockitoAnnotations.initMocks(this);
45+
}
46+
47+
@Test
48+
public void shouldTestIfClockedTimeExceedsDuration() {
49+
long sleepTime = 100;
50+
51+
ObjectSleeper<String> objectSleeper = new ObjectSleeper<>();
52+
objectSleeper.setReceiver(receiver);
53+
objectSleeper.setSleepTime(sleepTime);
54+
Instant start = Instant.now();
55+
objectSleeper.process(null);
56+
Instant end = Instant.now();
57+
58+
Duration timeElapsed = Duration.between(start, end);
59+
60+
assertTrue(timeElapsed.toMillis() >= sleepTime);
61+
62+
}
63+
64+
65+
}

0 commit comments

Comments
 (0)