-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f214000
commit 9f8e00c
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
logic/src/test/java/org/itsallcode/whiterabbit/logic/ConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.itsallcode.whiterabbit.logic; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.time.Duration; | ||
import java.util.Locale; | ||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class ConfigTest | ||
{ | ||
Config config = new TestingConfig(); | ||
|
||
@Test | ||
void getProjectFile() | ||
{ | ||
assertThat(config.getProjectFile()).isEqualTo(Paths.get("data/projects.json")); | ||
} | ||
|
||
@Test | ||
void getLogPath() | ||
{ | ||
assertThat(config.getLogPath()).isEqualTo(Paths.get("data/logs")); | ||
} | ||
|
||
@Test | ||
void getUiStatePath() | ||
{ | ||
assertThat(config.getUiStatePath()).isEqualTo(Paths.get("data/ui-state.json")); | ||
} | ||
|
||
private static class TestingConfig implements Config | ||
{ | ||
|
||
@Override | ||
public Path getDataDir() | ||
{ | ||
return Paths.get("data"); | ||
} | ||
|
||
@Override | ||
public Locale getLocale() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public Optional<Duration> getCurrentHoursPerDay() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean allowMultipleInstances() | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean writeLogFile() | ||
{ | ||
return false; | ||
} | ||
|
||
@Override | ||
public Path getConfigFile() | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
.../test/java/org/itsallcode/whiterabbit/logic/service/scheduling/SchedulingServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.itsallcode.whiterabbit.logic.service.scheduling; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.itsallcode.whiterabbit.logic.service.ClockService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class SchedulingServiceTest | ||
{ | ||
private static final Instant NOW = Instant.parse("2007-12-03T10:15:30.00Z"); | ||
|
||
@Mock | ||
private ClockService clockServiceMock; | ||
@Mock | ||
private ScheduledExecutorService executorServiceMock; | ||
@Mock | ||
private Runnable runnableMock; | ||
@Mock | ||
private Trigger triggerMock; | ||
private SchedulingService service; | ||
|
||
@BeforeEach | ||
void setUp() | ||
{ | ||
service = new SchedulingService(clockServiceMock, executorServiceMock); | ||
} | ||
|
||
@Test | ||
void scheduleWithDelay() | ||
{ | ||
service.schedule(Duration.ofMillis(150), runnableMock); | ||
verify(executorServiceMock).schedule(any(DelegatingErrorHandlingRunnable.class), eq(150L), | ||
eq(TimeUnit.MILLISECONDS)); | ||
} | ||
|
||
@Test | ||
void scheduleWithTrigger() | ||
{ | ||
when(clockServiceMock.instant()).thenReturn(NOW); | ||
final Instant nextExecution = NOW.plusMillis(100); | ||
when(triggerMock.nextExecutionTime(any(), any())).thenReturn(nextExecution); | ||
service.schedule(triggerMock, runnableMock); | ||
verify(executorServiceMock).schedule(any(ReschedulingRunnable.class), eq(100L), eq(TimeUnit.MILLISECONDS)); | ||
} | ||
} |