SUB = Calc::sub;
-
- private Calc() {
- // no-op
- }
-
/**
* Adds {@code 1} to the value.
*
diff --git a/src/main/java/rife/bld/extension/propertyfile/Entry.java b/src/main/java/rife/bld/extension/propertyfile/Entry.java
index bd8087b..89a7e3e 100644
--- a/src/main/java/rife/bld/extension/propertyfile/Entry.java
+++ b/src/main/java/rife/bld/extension/propertyfile/Entry.java
@@ -30,6 +30,16 @@ public class Entry extends EntryBase {
super(key);
}
+ /**
+ * Sets the new {@link java.util.Properties property} value.
+ *
+ * @param s The new value
+ */
+ public Entry set(Object s) {
+ setNewValue(s);
+ return this;
+ }
+
/**
* Sets the initial value to set the {@link java.util.Properties property} to, if not already defined.
*
@@ -41,24 +51,6 @@ public class Entry extends EntryBase {
return this;
}
- /**
- * Sets the {@link Entry entry} up for deletion.
- */
- public Entry delete() {
- setDelete(true);
- return this;
- }
-
- /**
- * Creates a new {@link Entry entry}.
- *
- * @param modify the modification function
- */
- public Entry modify(BiFunction modify) {
- setModify(modify);
- return this;
- }
-
/**
* Creates a new {@link Entry entry}.
*
@@ -72,12 +64,20 @@ public class Entry extends EntryBase {
}
/**
- * Sets the new {@link java.util.Properties property} value.
+ * Creates a new {@link Entry entry}.
*
- * @param s The new value
+ * @param modify the modification function
*/
- public Entry set(Object s) {
- setNewValue(s);
+ public Entry modify(BiFunction modify) {
+ setModify(modify);
+ return this;
+ }
+
+ /**
+ * Sets the {@link Entry entry} up for deletion.
+ */
+ public Entry delete() {
+ setDelete(true);
return this;
}
}
diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryBase.java b/src/main/java/rife/bld/extension/propertyfile/EntryBase.java
index 1cadf1c..ba9edc7 100644
--- a/src/main/java/rife/bld/extension/propertyfile/EntryBase.java
+++ b/src/main/java/rife/bld/extension/propertyfile/EntryBase.java
@@ -27,15 +27,15 @@ import java.util.function.IntFunction;
* @since 1.0
*/
public class EntryBase {
- private IntFunction calc;
- private Object defaultValue;
- private boolean isDelete;
private String key;
- private BiFunction modify;
- private String modifyValue = "";
+ private Object defaultValue;
private Object newValue;
+ private String modifyValue = "";
+ private boolean isDelete;
private String pattern = "";
private EntryDate.Units unit = EntryDate.Units.DAY;
+ private IntFunction calc;
+ private BiFunction modify;
/**
* Creates a new {@link EntryBase entry}.
@@ -46,66 +46,6 @@ public class EntryBase {
this.key = key;
}
- /**
- * Returns the calculation function.
- */
- protected IntFunction getCalc() {
- return calc;
- }
-
- /**
- * Sets the calculation function.
- */
- protected void setCalc(IntFunction calc) {
- this.calc = calc;
- }
-
- /**
- * Returns the default value.
- */
- protected Object getDefaultValue() {
- return defaultValue;
- }
-
- /**
- * Sets the initial value to set the {@link java.util.Properties property} to, if not already defined.
- *
- * @param defaultValue the default value
- */
- protected void setDefaultValue(Object defaultValue) {
- this.defaultValue = defaultValue;
- }
-
- /**
- * Returns the key of the {@link java.util.Properties property}.
- */
- protected String getKey() {
- return key;
- }
-
- /**
- * Sets the key of the {@link java.util.Properties property}.
- *
- * @param key the {@link java.util.Properties property} key
- */
- protected void setKey(String key) {
- this.key = key;
- }
-
- /**
- * Returns the modify function.
- */
- protected BiFunction getModify() {
- return modify;
- }
-
- /**
- * Sets the modify function.
- */
- protected void setModify(BiFunction modify) {
- this.modify = modify;
- }
-
/**
* Returns the value to be used in the {@link #modify} function.
*/
@@ -123,19 +63,87 @@ public class EntryBase {
}
/**
- * Returns the new value to set the {@link java.util.Properties property)} to.
+ * Returns the modify function.
*/
- public Object getNewValue() {
- return newValue;
+ protected BiFunction getModify() {
+ return modify;
}
/**
- * Sets a new value for {@link java.util.Properties property}.
- *
- * @param newValue the new value
+ * Sets the modify function.
*/
- public void setNewValue(Object newValue) {
- this.newValue = newValue;
+ protected void setModify(BiFunction modify) {
+ this.modify = modify;
+ }
+
+ /**
+ * Sets the modify function.
+ *
+ * @param value the value to perform a modification with
+ */
+ protected void setModify(String value, BiFunction modify) {
+ this.modifyValue = value;
+ this.modify = modify;
+ }
+
+ /**
+ * Returns {@code true} if the {@link java.util.Properties property} is to be deleted.
+ */
+ protected boolean isDelete() {
+ return isDelete;
+ }
+
+ /**
+ * Sets whether the {@link java.util.Properties property} should be deleted.
+ */
+ protected void setDelete(boolean delete) {
+ isDelete = delete;
+ }
+
+ /**
+ * Returns the calculation function.
+ */
+ protected IntFunction getCalc() {
+ return calc;
+ }
+
+ /**
+ * Sets the calculation function.
+ */
+ protected void setCalc(IntFunction calc) {
+ this.calc = calc;
+ }
+
+ /**
+ * Returns the key of the {@link java.util.Properties property}.
+ */
+ protected String getKey() {
+ return key;
+ }
+
+ /**
+ * Sets the key of the {@link java.util.Properties property}.
+ *
+ * @param key the {@link java.util.Properties property} key
+ */
+ protected void setKey(String key) {
+ this.key = key;
+ }
+
+ /**
+ * Returns the default value.
+ */
+ protected Object getDefaultValue() {
+ return defaultValue;
+ }
+
+ /**
+ * Sets the initial value to set the {@link java.util.Properties property} to, if not already defined.
+ *
+ * @param defaultValue the default value
+ */
+ protected void setDefaultValue(Object defaultValue) {
+ this.defaultValue = defaultValue;
}
/**
@@ -171,20 +179,6 @@ public class EntryBase {
this.unit = unit;
}
- /**
- * Returns {@code true} if the {@link java.util.Properties property} is to be deleted.
- */
- protected boolean isDelete() {
- return isDelete;
- }
-
- /**
- * Sets whether the {@link java.util.Properties property} should be deleted.
- */
- protected void setDelete(boolean delete) {
- isDelete = delete;
- }
-
/**
* Sets the key of the {@link java.util.Properties property}.
*
@@ -197,12 +191,18 @@ public class EntryBase {
}
/**
- * Sets the modify function.
- *
- * @param value the value to perform a modification with
+ * Returns the new value to set the {@link java.util.Properties property)} to.
*/
- protected void setModify(String value, BiFunction modify) {
- this.modifyValue = value;
- this.modify = modify;
+ public Object getNewValue() {
+ return newValue;
+ }
+
+ /**
+ * Sets a new value for {@link java.util.Properties property}.
+ *
+ * @param newValue the new value
+ */
+ public void setNewValue(Object newValue) {
+ this.newValue = newValue;
}
}
diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryDate.java b/src/main/java/rife/bld/extension/propertyfile/EntryDate.java
index 51e6630..3522f47 100644
--- a/src/main/java/rife/bld/extension/propertyfile/EntryDate.java
+++ b/src/main/java/rife/bld/extension/propertyfile/EntryDate.java
@@ -37,43 +37,6 @@ public class EntryDate extends EntryBase {
super(key);
}
- /**
- * Creates a new {@link EntryDate entry}.
- *
- * @param calc the calculation function
- */
- public EntryDate calc(IntFunction calc) {
- setCalc(calc);
- return this;
- }
-
- /**
- * Sets the {@link EntryDate entry} up for deletion.
- */
- public EntryDate delete() {
- setDelete(true);
- return this;
- }
-
- /**
- * Sets the new {@link java.util.Properties property} value to now.
- */
- public EntryDate now() {
- setNewValue("now");
- return this;
- }
-
- /**
- * Sets the pattern for {@link EntryInt} and {@link EntryDate} to{@link java.text.DecimalFormat DecimalFormat} and
- * {@link java.time.format.DateTimeFormatter DateTimeFormatter} respectively.
- *
- * @param pattern the pattern
- */
- public EntryDate pattern(String pattern) {
- setPattern(pattern);
- return this;
- }
-
/**
* Sets the new {@link java.util.Properties property} value to an {@link Instant}
*
@@ -144,6 +107,35 @@ public class EntryDate extends EntryBase {
return this;
}
+ /**
+ * Sets the new {@link java.util.Properties property} value to now.
+ */
+ public EntryDate now() {
+ setNewValue("now");
+ return this;
+ }
+
+ /**
+ * Creates a new {@link EntryDate entry}.
+ *
+ * @param calc the calculation function
+ */
+ public EntryDate calc(IntFunction calc) {
+ setCalc(calc);
+ return this;
+ }
+
+ /**
+ * Sets the pattern for {@link EntryInt} and {@link EntryDate} to{@link java.text.DecimalFormat DecimalFormat} and
+ * {@link java.time.format.DateTimeFormatter DateTimeFormatter} respectively.
+ *
+ * @param pattern the pattern
+ */
+ public EntryDate pattern(String pattern) {
+ setPattern(pattern);
+ return this;
+ }
+
/**
* Sets the {@link Units unit} value to apply to calculations for {@link EntryDate}.
*
@@ -154,6 +146,14 @@ public class EntryDate extends EntryBase {
return this;
}
+ /**
+ * Sets the {@link EntryDate entry} up for deletion.
+ */
+ public EntryDate delete() {
+ setDelete(true);
+ return this;
+ }
+
/**
* The units available for {@link EntryDate} calculations.
*
diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryInt.java b/src/main/java/rife/bld/extension/propertyfile/EntryInt.java
index 9dd619b..f2001ef 100644
--- a/src/main/java/rife/bld/extension/propertyfile/EntryInt.java
+++ b/src/main/java/rife/bld/extension/propertyfile/EntryInt.java
@@ -35,12 +35,12 @@ public class EntryInt extends EntryBase {
}
/**
- * Creates a new {@link EntryInt entry}.
+ * Sets the new {@link java.util.Properties property} value to an integer.
*
- * @param calc the calculation function.
+ * @param i The integer to set the value to
*/
- public EntryInt calc(IntFunction calc) {
- setCalc(calc);
+ public EntryInt set(int i) {
+ setNewValue(i);
return this;
}
@@ -55,6 +55,16 @@ public class EntryInt extends EntryBase {
return this;
}
+ /**
+ * Creates a new {@link EntryInt entry}.
+ *
+ * @param calc the calculation function.
+ */
+ public EntryInt calc(IntFunction calc) {
+ setCalc(calc);
+ return this;
+ }
+
/**
* Sets the {@link EntryInt entry} up for deletion.
*/
@@ -62,14 +72,4 @@ public class EntryInt extends EntryBase {
setDelete(true);
return this;
}
-
- /**
- * Sets the new {@link java.util.Properties property} value to an integer.
- *
- * @param i The integer to set the value to
- */
- public EntryInt set(int i) {
- setNewValue(i);
- return this;
- }
}
diff --git a/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java b/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java
index 9364be2..77cc22b 100644
--- a/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java
+++ b/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java
@@ -16,7 +16,7 @@
package rife.bld.extension.propertyfile;
-import rife.bld.BaseProject;
+import rife.bld.Project;
import rife.bld.operations.AbstractOperation;
import java.io.File;
@@ -32,20 +32,13 @@ import java.util.Properties;
*/
public class PropertyFileOperation extends AbstractOperation {
private final List entries = new ArrayList<>();
+ private final Project project;
+ private File file;
private String comment = "";
private boolean failOnWarning;
- private File file;
- private BaseProject project;
- /**
- * Sets the comment to be inserted at the top of the {@link java.util.Properties} file.
- *
- * @param comment the header comment
- */
- @SuppressWarnings("unused")
- public PropertyFileOperation comment(String comment) {
- this.comment = comment;
- return this;
+ public PropertyFileOperation(Project project) {
+ this.project = project;
}
/**
@@ -60,6 +53,50 @@ public class PropertyFileOperation extends AbstractOperation v - 2);
- PropertyFileUtils.processDate(t, p, entryDate.now(), true);
- assertThat(p.getProperty(entryDate.getKey())).as("processDate(now-2)").isEqualTo(String.valueOf(dayOfYear - 2));
-
- entryDate.setCalc(SUB);
- PropertyFileUtils.processDate(t, p, entryDate.set(new Date()), true);
- assertThat(p.getProperty(entryDate.getKey())).as("processDate(date-1)").isEqualTo(String.valueOf(dayOfYear - 1));
-
- entryDate.setCalc(v -> v - 2);
- PropertyFileUtils.processDate(t, p, entryDate.set(Calendar.getInstance()), true);
- assertThat(p.getProperty(entryDate.getKey())).as("processDate(cal-2)").isEqualTo(String.valueOf(dayOfYear - 2));
-
- entryDate.setCalc(v -> v - 3);
- PropertyFileUtils.processDate(t, p, entryDate.set(LocalDate.now()),
- true);
- assertThat(p.getProperty(entryDate.getKey())).as("processDate(LocalDate-3)").isEqualTo(String.valueOf(dayOfYear - 3));
+ void testWarn() {
+ assertThatCode(() -> PropertyFileUtils.warn("command", "message", new IOException(t), true))
+ .hasMessage(t).isInstanceOf(IOException.class);
+ assertThatCode(() -> PropertyFileUtils.warn("command", t, new Exception(t), false))
+ .as("failOnWarning = false").doesNotThrowAnyException();
}
@Test
- @SuppressWarnings("PMD.SignatureDeclareThrowsException")
- void parseIntSubTest() throws Exception {
- var entryInt = newEntryInt();
- entryInt.calc(SUB);
- entryInt.setPattern("0000");
- PropertyFileUtils.processInt(t, p, entryInt.defaultValue("0017"), true);
- assertThat(p.getProperty(entryInt.getKey())).as("sub(0017)").isEqualTo("0016");
-
- PropertyFileUtils.processInt(t, p, entryInt.set(16).calc(v -> v - 3), true);
- assertThat(p.getProperty(entryInt.getKey())).as("sub(16)-3").isEqualTo("0013");
- }
-
- @Test
- @SuppressWarnings("PMD.AvoidDuplicateLiterals")
void parseStringAppend() {
- var entry = newEntry();
- PropertyFileUtils.processString(p, entry.set(1));
PropertyFileUtils.processString(p, entry.modify("-foo", String::concat));
assertThat(p.getProperty(entry.getKey())).as(String.format("processString(%s, %s)", entry.getKey(),
entry.getNewValue())).isEqualTo("1-foo");
}
- @Test
- void parseStringCap() {
- var entry = newEntry();
- PropertyFileUtils.processString(p, entry.set(t).modify("", (v, s) -> v.toUpperCase(Localization.getLocale())));
- assertThat(p.getProperty(entry.getKey())).as("capitalize").isEqualTo(t.toUpperCase(Localization.getLocale()));
-
- }
-
- @Test
- void parseStringCat() {
- var entry = newEntry();
- entry.set(t).setModify("-foo", String::concat);
- PropertyFileUtils.processString(p, entry);
- assertThat(p.getProperty(entry.getKey())).as("replace").isEqualTo(t + "-foo");
- }
-
@Test
void parseStringPrepend() {
- var entry = newEntry();
- PropertyFileUtils.processString(p, entry.set(1));
PropertyFileUtils.processString(p, entry.modify("foo-", (v, s) -> s + v));
assertThat(p.getProperty(entry.getKey())).as(String.format("processString(%s, %s)", entry.getKey(), entry.getNewValue()))
.isEqualTo("foo-1");
}
+ @Test
+ void parseStringCap() {
+ PropertyFileUtils.processString(p, entry.set(t).modify("", (v, s) -> v.toUpperCase(Localization.getLocale())));
+ assertThat(p.getProperty(entry.getKey())).as("capitalize").isEqualTo(t.toUpperCase(Localization.getLocale()));
+
+ }
+
@Test
void parseStringReplace() {
- var entry = newEntry();
entry.set(t).setModify("T", (v, s) -> v.replace("t", s));
PropertyFileUtils.processString(p, entry);
assertThat(p.getProperty(entry.getKey())).as("replace(t -> T)").isEqualTo("TesT");
}
+ @Test
+ void parseStringCat() {
+ entry.set(t).setModify("-foo", String::concat);
+ PropertyFileUtils.processString(p, entry);
+ assertThat(p.getProperty(entry.getKey())).as("replace").isEqualTo(t + "-foo");
+ }
+
@Test
void parseStringSub() {
- var entry = newEntry();
PropertyFileUtils.processString(p, entry.set(t).modify((v, s) -> v.substring(1)));
assertThat(p.getProperty(entry.getKey())).as("substring(1)").isEqualTo(t.substring(1));
}
@Test
- @SuppressWarnings("PMD.SignatureDeclareThrowsException")
- void parseTimeTest() throws Exception {
- var entry = new EntryDate("time").pattern("m");
- var time = LocalTime.now();
-
- entry.setCalc(ADD);
- PropertyFileUtils.processDate(t, p, entry.set(time).unit(EntryDate.Units.MINUTE), true);
- assertThat(p.getProperty(entry.getKey())).as("processDate(now+1)")
- .isEqualTo(String.valueOf(time.plusMinutes(1).getMinute()));
-
- entry.setCalc(SUB);
- PropertyFileUtils.processDate(t, p, entry.set(time).unit(EntryDate.Units.HOUR).pattern("H"), true);
- assertThat(p.getProperty(entry.getKey())).as("processDate(now+1)")
- .isEqualTo(String.valueOf(time.minusHours(1).getHour()));
- }
-
- @Test
- @SuppressWarnings("PMD.SignatureDeclareThrowsException")
- void processDateAddTest() throws Exception {
- var entryDate = newEntryDate();
- entryDate.setCalc(ADD);
- PropertyFileUtils.processDate(t, p, entryDate.now(), true);
- assertThat(p.getProperty(entryDate.getKey())).as("processDate(now+1)").isEqualTo(String.valueOf(dayOfYear + 1));
-
- PropertyFileUtils.processDate(t, p, entryDate.now().calc(v -> v + 3), true);
- assertThat(p.getProperty(entryDate.getKey())).as("processDate(now+3)").isEqualTo(String.valueOf(dayOfYear + 3));
-
- entryDate.setCalc(ADD);
- PropertyFileUtils.processDate(t, p, entryDate.set(ZonedDateTime.now()), true);
- assertThat(p.getProperty(entryDate.getKey())).as("processDate(ZonedDateTime+1)")
- .isEqualTo(String.valueOf(dayOfYear + 1));
-
- PropertyFileUtils.processDate(t, p, entryDate.set(Instant.now()).calc(v -> v + 2), true);
- assertThat(p.getProperty(entryDate.getKey())).as("processDate(Instant+2)").isEqualTo(String.valueOf(dayOfYear + 2));
-
- entryDate.setCalc(v -> v + 3);
- PropertyFileUtils.processDate(t, p, entryDate.set(LocalDateTime.now()), true);
- assertThat(p.getProperty(entryDate.getKey())).as("processDate(LocalDteTime+2)").isEqualTo(String.valueOf(dayOfYear + 3));
- }
-
- @Test
- @SuppressWarnings("PMD.SignatureDeclareThrowsException")
void processIntAddTest() throws Exception {
- var entryInt = newEntryInt();
entryInt.calc(ADD);
entryInt.setDefaultValue("-1");
PropertyFileUtils.processInt(t, p, entryInt, true);
@@ -218,22 +137,92 @@ class PropertyFileUtilsTest {
}
@Test
- void processStringTest() {
- var entry = newEntry();
- PropertyFileUtils.processString(p, entry);
+ void parseIntSubTest() throws Exception {
+ entryInt.calc(SUB);
+ entryInt.setPattern("0000");
+ PropertyFileUtils.processInt(t, p, entryInt.defaultValue("0017"), true);
+ assertThat(p.getProperty(entryInt.getKey())).as("sub(0017)").isEqualTo("0016");
- assertThat(entry.getNewValue()).as(String.format("processString(%s, %s)", entry.getKey(), entry.getNewValue()))
- .isEqualTo(p.getProperty(entry.getKey()));
-
- entry.setKey("version.minor");
-
- PropertyFileUtils.processString(p, entry.set(0));
- assertThat(entry.getNewValue().toString()).as(String.format("processString(%s, %s)", entry.getKey(), entry.getNewValue()))
- .isEqualTo(p.getProperty(entry.getKey()));
+ PropertyFileUtils.processInt(t, p, entryInt.set(16).calc(v -> v - 3), true);
+ assertThat(p.getProperty(entryInt.getKey())).as("sub(16)-3").isEqualTo("0013");
+ }
+
+ @Test
+ void processDateAddTest() throws Exception {
+ entryDate.setCalc(ADD);
+ PropertyFileUtils.processDate(t, p, entryDate.now(), true);
+ assertThat(p.getProperty(entryDate.getKey())).as("processDate(now+1)").isEqualTo(String.valueOf(dayOfYear + 1));
+
+ PropertyFileUtils.processDate(t, p, entryDate.now().calc(v -> v + 3), true);
+ assertThat(p.getProperty(entryDate.getKey())).as("processDate(now+3)").isEqualTo(String.valueOf(dayOfYear + 3));
+
+ entryDate.setCalc(ADD);
+ PropertyFileUtils.processDate(t, p, entryDate.set(ZonedDateTime.now()), true);
+ assertThat(p.getProperty(entryDate.getKey())).as("processDate(ZonedDateTime+1)")
+ .isEqualTo(String.valueOf(dayOfYear + 1));
+
+ PropertyFileUtils.processDate(t, p, entryDate.set(Instant.now()).calc(v -> v + 2), true);
+ assertThat(p.getProperty(entryDate.getKey())).as("processDate(Instant+2)").isEqualTo(String.valueOf(dayOfYear + 2));
+
+ entryDate.setCalc(v -> v + 3);
+ PropertyFileUtils.processDate(t, p, entryDate.set(LocalDateTime.now()), true);
+ assertThat(p.getProperty(entryDate.getKey())).as("processDate(LocalDteTime+2)").isEqualTo(String.valueOf(dayOfYear + 3));
+ }
+
+ @Test
+ void parseDateSub() throws Exception {
+ entryDate.setCalc(SUB);
+ PropertyFileUtils.processDate(t, p, entryDate.now(), true);
+ assertThat(p.getProperty(entryDate.getKey())).as("processDate(now-3)").isEqualTo(String.valueOf(dayOfYear - 1));
+
+ entryDate.setCalc(v -> v - 2);
+ PropertyFileUtils.processDate(t, p, entryDate.now(), true);
+ assertThat(p.getProperty(entryDate.getKey())).as("processDate(now-2)").isEqualTo(String.valueOf(dayOfYear - 2));
+
+ entryDate.setCalc(SUB);
+ PropertyFileUtils.processDate(t, p, entryDate.set(new Date()), true);
+ assertThat(p.getProperty(entryDate.getKey())).as("processDate(date-1)").isEqualTo(String.valueOf(dayOfYear - 1));
+
+ entryDate.setCalc(v -> v - 2);
+ PropertyFileUtils.processDate(t, p, entryDate.set(Calendar.getInstance()), true);
+ assertThat(p.getProperty(entryDate.getKey())).as("processDate(cal-2)").isEqualTo(String.valueOf(dayOfYear - 2));
+
+ entryDate.setCalc(v -> v - 3);
+ PropertyFileUtils.processDate(t, p, entryDate.set(LocalDate.now()),
+ true);
+ assertThat(p.getProperty(entryDate.getKey())).as("processDate(LocalDate-3)").isEqualTo(String.valueOf(dayOfYear - 3));
+ }
+
+ @Test
+ void parseTimeTest() throws Exception {
+ var entry = new EntryDate("time").pattern("m");
+ var time = LocalTime.now();
+
+ entry.setCalc(ADD);
+ PropertyFileUtils.processDate(t, p, entry.set(time).unit(EntryDate.Units.MINUTE), true);
+ assertThat(p.getProperty(entry.getKey())).as("processDate(now+1)")
+ .isEqualTo(String.valueOf(time.plusMinutes(1).getMinute()));
+
+ entry.setCalc(SUB);
+ PropertyFileUtils.processDate(t, p, entry.set(time).unit(EntryDate.Units.HOUR).pattern("H"), true);
+ assertThat(p.getProperty(entry.getKey())).as("processDate(now+1)")
+ .isEqualTo(String.valueOf(time.minusHours(1).getHour()));
+ }
+
+ @Test
+ void testCurrentValue() {
+ var value = "value";
+ var defaultValue = "default";
+ var newValue = "new";
+
+ assertThat(PropertyFileUtils.currentValue(value, defaultValue, newValue)).as("all").isEqualTo(newValue);
+ assertThat(PropertyFileUtils.currentValue(value, null, null)).as("value").isEqualTo(value);
+ assertThat(PropertyFileUtils.currentValue(value, defaultValue, null)).as("value not default").isEqualTo(value);
+ assertThat(PropertyFileUtils.currentValue(null, defaultValue, null)).as("default").isEqualTo(defaultValue);
+ assertThat(PropertyFileUtils.currentValue(null, null, newValue)).as("new").isEqualTo(newValue);
}
@Test
- @SuppressWarnings("PMD.SignatureDeclareThrowsException")
void savePropertiesTest() throws Exception {
var p = new Properties();
var test = "test";
@@ -251,25 +240,4 @@ class PropertyFileUtilsTest {
tmp.deleteOnExit();
}
-
- @Test
- void testCurrentValue() {
- var value = "value";
- var defaultValue = "default";
- var newValue = "new";
-
- assertThat(PropertyFileUtils.currentValue(value, defaultValue, newValue)).as("all").isEqualTo(newValue);
- assertThat(PropertyFileUtils.currentValue(value, null, null)).as("value").isEqualTo(value);
- assertThat(PropertyFileUtils.currentValue(value, defaultValue, null)).as("value not default").isEqualTo(value);
- assertThat(PropertyFileUtils.currentValue(null, defaultValue, null)).as("default").isEqualTo(defaultValue);
- assertThat(PropertyFileUtils.currentValue(null, null, newValue)).as("new").isEqualTo(newValue);
- }
-
- @Test
- void testWarn() {
- assertThatCode(() -> PropertyFileUtils.warn("command", "message", new IOException(t), true))
- .hasMessage(t).isInstanceOf(IOException.class);
- assertThatCode(() -> PropertyFileUtils.warn("command", t, new Exception(t), false))
- .as("failOnWarning = false").doesNotThrowAnyException();
- }
}
\ No newline at end of file