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 89a7e3e..bd8087b 100644
--- a/src/main/java/rife/bld/extension/propertyfile/Entry.java
+++ b/src/main/java/rife/bld/extension/propertyfile/Entry.java
@@ -30,16 +30,6 @@ 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.
*
@@ -51,6 +41,24 @@ 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}.
*
@@ -64,20 +72,12 @@ public class Entry extends EntryBase {
}
/**
- * Creates a new {@link Entry entry}.
+ * Sets the new {@link java.util.Properties property} value.
*
- * @param modify the modification function
+ * @param s The new value
*/
- public Entry modify(BiFunction modify) {
- setModify(modify);
- return this;
- }
-
- /**
- * Sets the {@link Entry entry} up for deletion.
- */
- public Entry delete() {
- setDelete(true);
+ public Entry set(Object s) {
+ setNewValue(s);
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 ba9edc7..1cadf1c 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 String key;
+ private IntFunction calc;
private Object defaultValue;
- private Object newValue;
- private String modifyValue = "";
private boolean isDelete;
+ private String key;
+ private BiFunction modify;
+ private String modifyValue = "";
+ private Object newValue;
private String pattern = "";
private EntryDate.Units unit = EntryDate.Units.DAY;
- private IntFunction calc;
- private BiFunction modify;
/**
* Creates a new {@link EntryBase entry}.
@@ -46,60 +46,6 @@ public class EntryBase {
this.key = key;
}
- /**
- * Returns the value to be used in the {@link #modify} function.
- */
- protected String getModifyValue() {
- return modifyValue;
- }
-
- /**
- * Sets the modify value.
- *
- * @param value the modify value.
- */
- protected void setModifyValue(String value) {
- this.modifyValue = value;
- }
-
- /**
- * Returns the modify function.
- */
- protected BiFunction getModify() {
- return modify;
- }
-
- /**
- * Sets the modify function.
- */
- 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.
*/
@@ -114,6 +60,22 @@ public class EntryBase {
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}.
*/
@@ -131,19 +93,49 @@ public class EntryBase {
}
/**
- * Returns the default value.
+ * Returns the modify function.
*/
- protected Object getDefaultValue() {
- return defaultValue;
+ protected BiFunction getModify() {
+ return modify;
}
/**
- * Sets the initial value to set the {@link java.util.Properties property} to, if not already defined.
- *
- * @param defaultValue the default value
+ * Sets the modify function.
*/
- protected void setDefaultValue(Object defaultValue) {
- this.defaultValue = defaultValue;
+ protected void setModify(BiFunction modify) {
+ this.modify = modify;
+ }
+
+ /**
+ * Returns the value to be used in the {@link #modify} function.
+ */
+ protected String getModifyValue() {
+ return modifyValue;
+ }
+
+ /**
+ * Sets the modify value.
+ *
+ * @param value the modify value.
+ */
+ protected void setModifyValue(String value) {
+ this.modifyValue = value;
+ }
+
+ /**
+ * Returns the new value to set the {@link java.util.Properties property)} to.
+ */
+ 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;
}
/**
@@ -179,6 +171,20 @@ 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}.
*
@@ -191,18 +197,12 @@ public class EntryBase {
}
/**
- * Returns the new value to set the {@link java.util.Properties property)} to.
- */
- public Object getNewValue() {
- return newValue;
- }
-
- /**
- * Sets a new value for {@link java.util.Properties property}.
+ * Sets the modify function.
*
- * @param newValue the new value
+ * @param value the value to perform a modification with
*/
- public void setNewValue(Object newValue) {
- this.newValue = newValue;
+ protected void setModify(String value, BiFunction modify) {
+ this.modifyValue = value;
+ this.modify = modify;
}
}
diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryDate.java b/src/main/java/rife/bld/extension/propertyfile/EntryDate.java
index 3522f47..51e6630 100644
--- a/src/main/java/rife/bld/extension/propertyfile/EntryDate.java
+++ b/src/main/java/rife/bld/extension/propertyfile/EntryDate.java
@@ -37,6 +37,43 @@ 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}
*
@@ -107,35 +144,6 @@ 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}.
*
@@ -146,14 +154,6 @@ 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 f2001ef..9dd619b 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 {
}
/**
- * Sets the new {@link java.util.Properties property} value to an integer.
+ * Creates a new {@link EntryInt entry}.
*
- * @param i The integer to set the value to
+ * @param calc the calculation function.
*/
- public EntryInt set(int i) {
- setNewValue(i);
+ public EntryInt calc(IntFunction calc) {
+ setCalc(calc);
return this;
}
@@ -55,16 +55,6 @@ 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.
*/
@@ -72,4 +62,14 @@ 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 77cc22b..9364be2 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.Project;
+import rife.bld.BaseProject;
import rife.bld.operations.AbstractOperation;
import java.io.File;
@@ -32,13 +32,20 @@ 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;
- public PropertyFileOperation(Project project) {
- this.project = 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;
}
/**
@@ -53,50 +60,6 @@ public class PropertyFileOperation extends AbstractOperation 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();
+ @SuppressWarnings("PMD.SignatureDeclareThrowsException")
+ void parseDateSub() throws Exception {
+ var entryDate = newEntryDate();
+ 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
+ @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 parseStringPrepend() {
- 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() {
+ 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 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);
@@ -137,92 +218,22 @@ class PropertyFileUtilsTest {
}
@Test
- 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");
+ void processStringTest() {
+ var entry = newEntry();
+ PropertyFileUtils.processString(p, entry);
- 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);
+ 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()));
}
@Test
+ @SuppressWarnings("PMD.SignatureDeclareThrowsException")
void savePropertiesTest() throws Exception {
var p = new Properties();
var test = "test";
@@ -240,4 +251,25 @@ 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