-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: "default" and "description" columns added to configuration prop…
- Loading branch information
Showing
6 changed files
with
209 additions
and
37 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
app/src/main/java/ch/sbb/polarion/extension/generic/properties/ExtendedProperties.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,59 @@ | ||
package ch.sbb.polarion.extension.generic.properties; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Properties; | ||
|
||
public class ExtendedProperties extends Properties { | ||
|
||
private final HashMap<Object, String> defaultValues = new HashMap<>(); | ||
private final HashMap<Object, String> descriptions = new HashMap<>(); | ||
|
||
public ExtendedProperties() { | ||
super(); | ||
} | ||
|
||
public ExtendedProperties(int size) { | ||
super(size); | ||
} | ||
|
||
@Override | ||
public synchronized Object setProperty(@NotNull String key, @NotNull String value) { | ||
return this.setProperty(key, value, null, null); | ||
} | ||
|
||
public synchronized Object setProperty(@NotNull String key, @NotNull String value, @Nullable String defaultValue, @Nullable String description) { | ||
return this.put(key, value, defaultValue, description); | ||
} | ||
|
||
public synchronized Object put(@NotNull Object key, @NotNull Object value, @Nullable String defaultValue, @Nullable String description) { | ||
defaultValues.put(key, defaultValue); | ||
descriptions.put(key, description); | ||
return super.put(key, value); | ||
} | ||
|
||
public synchronized @Nullable String getDescription(@NotNull Object key) { | ||
return descriptions.get(key); | ||
} | ||
|
||
public synchronized @Nullable String getDefaultValue(@NotNull Object key) { | ||
return defaultValues.get(key); | ||
} | ||
|
||
@Override | ||
public synchronized Object put(@NotNull Object key, @NotNull Object value) { | ||
return this.put(key, value, null, null); | ||
} | ||
|
||
@Override | ||
public synchronized boolean equals(Object o) { | ||
return super.equals(o); | ||
} | ||
|
||
@Override | ||
public synchronized int hashCode() { | ||
return super.hashCode(); | ||
} | ||
} |
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
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
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
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
82 changes: 82 additions & 0 deletions
82
app/src/test/java/ch/sbb/polarion/extension/generic/properties/ExtendedPropertiesTest.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,82 @@ | ||
package ch.sbb.polarion.extension.generic.properties; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ExtendedPropertiesTest { | ||
|
||
private ExtendedProperties props; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
props = new ExtendedProperties(); | ||
} | ||
|
||
@Test | ||
void testSetPropertyWithDescriptionAndDefaultValue() { | ||
props.setProperty("username", "admin", "root", "User for admin tasks"); | ||
|
||
assertEquals("admin", props.getProperty("username")); | ||
assertEquals("User for admin tasks", props.getDescription("username")); | ||
assertEquals("root", props.getDefaultValue("username")); | ||
} | ||
|
||
@Test | ||
void testSetPropertyWithoutDescriptionAndDefaultValue() { | ||
props.setProperty("language", "EN"); | ||
|
||
assertEquals("EN", props.getProperty("language")); | ||
assertNull(props.getDescription("language")); | ||
assertNull(props.getDefaultValue("language")); | ||
} | ||
|
||
@Test | ||
void testOverridePropertyKeepsNewDescriptionAndDefaultValue() { | ||
props.setProperty("timeout", "30", "60", "Timeout in seconds"); | ||
props.setProperty("timeout", "45", "90", "Updated timeout description"); | ||
|
||
assertEquals("45", props.getProperty("timeout")); | ||
assertEquals("Updated timeout description", props.getDescription("timeout")); | ||
assertEquals("90", props.getDefaultValue("timeout")); | ||
} | ||
|
||
@Test | ||
void testNullDescriptionAndDefaultValueHandledProperly() { | ||
props.setProperty("color", "blue", null, null); | ||
|
||
assertEquals("blue", props.getProperty("color")); | ||
assertNull(props.getDescription("color")); | ||
assertNull(props.getDefaultValue("color")); | ||
} | ||
|
||
@Test | ||
void testPutMethodWithDescriptionAndDefaultValue() { | ||
props.put("fontSize", "12", "10", "Size of font in points"); | ||
|
||
assertEquals("12", props.getProperty("fontSize")); | ||
assertEquals("Size of font in points", props.getDescription("fontSize")); | ||
assertEquals("10", props.getDefaultValue("fontSize")); | ||
} | ||
|
||
@Test | ||
void testPutMethodWithoutDescriptionAndDefaultValue() { | ||
props.put("theme", "dark"); | ||
|
||
assertEquals("dark", props.getProperty("theme")); | ||
assertNull(props.getDescription("theme")); | ||
assertNull(props.getDefaultValue("theme")); | ||
} | ||
|
||
@Test | ||
void testOverrideWithNullValues() { | ||
props.setProperty("path", "/home/user", "File path", "/root"); | ||
props.setProperty("path", "/home/new_user", null, null); | ||
|
||
assertEquals("/home/new_user", props.getProperty("path")); | ||
assertNull(props.getDescription("path")); | ||
assertNull(props.getDefaultValue("path")); | ||
} | ||
|
||
} |