Skip to content

Commit

Permalink
java 11: module-info.java, pom.xml,
Browse files Browse the repository at this point in the history
 tests monkey-patched
  • Loading branch information
lure0xaos committed Jan 15, 2021
1 parent 0726c56 commit 06e2ce5
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 122 deletions.
342 changes: 226 additions & 116 deletions pom.xml

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/main/java/gargoyle/ct/messages/impl/CTMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CTMessages implements MessageProviderEx {
private final LocaleProvider localeProvider;
private final MessageProvider parent;
private ResourceBundle messages;
private String baseName;

public CTMessages(@NotNull String baseName) {
this(new CTFixedLocaleProvider(), null, baseName);
Expand All @@ -33,8 +34,9 @@ public CTMessages(LocaleProvider localeProvider, MessageProvider parent, @NotNul
}

private void load(@NotNull String baseName) {
this.baseName = baseName;
try {
messages = ResourceBundle.getBundle(baseName, localeProvider.getLocale(), UTF8Control.getControl());
messages = ResourceBundle.getBundle(baseName, localeProvider.getLocale());
} catch (MissingResourceException ex) {
if (parent == null) {
throw new MissingResourceException(MessageFormat.format(MSG_NO_BUNDLE, baseName),
Expand All @@ -47,7 +49,7 @@ private void load(@NotNull String baseName) {
}

private void reload() {
load(messages.getBaseBundleName());
load(baseName);
}

public CTMessages(MessageProvider parent, @NotNull String baseName) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module coffee.time {
requires java.desktop;
requires java.logging;
requires java.prefs;
requires org.jetbrains.annotations;
}
2 changes: 1 addition & 1 deletion src/test/java/gargoyle/ct/CTConfigTimeConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class CTConfigTimeConverterTest {

@BeforeEach
public void setUp() {
converter = new CTConfigConverter();
}

@AfterEach
Expand All @@ -31,6 +30,7 @@ public void tearDown() {

@Test
public void testConvert() {
converter = new CTConfigConverter();
CTConfig config = new CTConfig(TimeUnit.MINUTES, WHOLE_1H, BLOCK_10M, WARN_3M);
assertAll(
() -> assertEquals(config, converter.parse(converter.format(TimeUnit.MINUTES, config)), "conversion failed"),
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/gargoyle/ct/CTConfigsTimeConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class CTConfigsTimeConverterTest {

@BeforeEach
public void setUp() {
converter = new CTConfigsConverter();
}

@AfterEach
Expand All @@ -29,6 +28,7 @@ public void tearDown() {

@Test
public void testConvert() {
converter = new CTConfigsConverter();
CTConfigs config = new CTConfigs(new CTStandardConfigs().getConfigs());
assertAll(
() -> assertEquals(config, converter.parse(converter.format(TimeUnit.MINUTES, config)), "conversion failed"),
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/gargoyle/ct/CTSerializationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class CTSerializationTest {

@BeforeEach
public void setUp() {
configsConverter = new CTConfigsConverter();
}

@Test
Expand All @@ -39,20 +38,23 @@ public void testConfigsSerialization() throws IOException {

@Test
public void testLoadH() {
configsConverter = new CTConfigsConverter();
CTConfigs parsed = configsConverter.parse("60H/10H/3H\n30H/5H/3H\n120H/20H/3H\n"); //NON-NLS
assertNotNull(parsed, "not parsed");
assertNotNull(parsed.getConfig("3600/600"), "wrong parsing (with hours)");
}

@Test
public void testLoadM() {
configsConverter = new CTConfigsConverter();
CTConfigs parsed = configsConverter.parse("60M/10M/3M\n30M/5M/3M\n120M/20M/3M\n"); //NON-NLS
assertNotNull(parsed);
assertNotNull(parsed.getConfig("60/10"), "wrong parsing (with minutes)");
}

@Test
public void testLoadS() {
configsConverter = new CTConfigsConverter();
CTConfigs parsed = configsConverter.parse("3600S/600S/3S\n1800S/300S/3S\n120S/20S/3S\n"); //NON-NLS
assertNotNull(parsed);
assertNotNull(parsed.getConfig("60/10"), "wrong parsing (with seconds)");
Expand Down
9 changes: 8 additions & 1 deletion src/test/java/gargoyle/ct/CTTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class CTTaskTest {

@BeforeEach
public void setUp() {
task = new CTTask();
}

@AfterEach
Expand All @@ -39,6 +38,7 @@ public void tearDown() {

@Test
public void testBlockedFalse() {
task = new CTTask();
long current = CTTimeUtil.make(10, 45, 10);
assertFalse(task.isBlocked(current), "should not block");
task.setConfig(new CTConfig(TimeUnit.MINUTES, WHOLE_1H, BLOCK_10M, WARN_3M));
Expand All @@ -51,6 +51,7 @@ public void testBlockedFalse() {

@Test
public void testBlockedTrue() {
task = new CTTask();
task.setConfig(new CTConfig(TimeUnit.MINUTES, WHOLE_1H, BLOCK_10M, WARN_3M));
long current = CTTimeUtil.make(10, 55, 10);
long started = CTTimeUtil.downTo(current, CTTimeUtil.toMillis(TimeUnit.HOURS, 1));
Expand All @@ -62,6 +63,7 @@ public void testBlockedTrue() {

@Test
public void testSleepingFalse() {
task = new CTTask();
long current = CTTimeUtil.make(10, 51, 10);
assertFalse(task.isWarn(current), "no warnings here");
task.setConfig(new CTConfig(TimeUnit.MINUTES, WHOLE_1H, BLOCK_10M, WARN_3M));
Expand All @@ -74,6 +76,7 @@ public void testSleepingFalse() {

@Test
public void testSleepingTrue() {
task = new CTTask();
task.setConfig(new CTConfig(TimeUnit.MINUTES, WHOLE_1H, BLOCK_10M, WARN_3M));
long current = CTTimeUtil.make(10, 30, 10);
long started = CTTimeUtil.downTo(current, CTTimeUtil.toMillis(TimeUnit.HOURS, 1));
Expand All @@ -85,6 +88,7 @@ public void testSleepingTrue() {

@Test
public void testStarted() {
task = new CTTask();
long started = CTTimeUtil.make();
task.setStarted(started);
actual = task.getStarted();
Expand All @@ -93,6 +97,7 @@ public void testStarted() {

@Test
public void testStartedUnits() {
task = new CTTask();
long started = CTTimeUtil.make();
TimeUnit unit = TimeUnit.SECONDS;
task.setStarted(unit, started);
Expand All @@ -102,6 +107,7 @@ public void testStartedUnits() {

@Test
public void testWarnFalse() {
task = new CTTask();
task.setConfig(new CTConfig(TimeUnit.MINUTES, WHOLE_1H, BLOCK_10M, WARN_3M));
long current = CTTimeUtil.make(10, 45, 10);
long started = CTTimeUtil.downTo(current, CTTimeUtil.toMillis(TimeUnit.HOURS, 1));
Expand All @@ -113,6 +119,7 @@ public void testWarnFalse() {

@Test
public void testWarnTrue() {
task = new CTTask();
task.setConfig(new CTConfig(TimeUnit.MINUTES, WHOLE_1H, BLOCK_10M, WARN_3M));
long current = CTTimeUtil.make(10, 49, 10);
long started = CTTimeUtil.downTo(current, CTTimeUtil.toMillis(TimeUnit.HOURS, 1));
Expand Down
1 change: 1 addition & 0 deletions src/test/java/gargoyle/ct/CTTimeHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void tearDown() {

@Test
public void testFakeTime() {
helper = new CTTimeHelperImpl();
long fakeTime = CTTimeUtil.currentTimeMillis();
helper.setFakeTime(fakeTime);
assertEquals(fakeTime, helper.getFakeTime(), "wrong fake time");
Expand Down

0 comments on commit 06e2ce5

Please sign in to comment.