diff --git a/services_app/src/androidTest/java/org/opendatakit/properties/DefaultPropertiesTest.java b/services_app/src/androidTest/java/org/opendatakit/properties/DefaultPropertiesTest.java index b785bf884..6616256d5 100644 --- a/services_app/src/androidTest/java/org/opendatakit/properties/DefaultPropertiesTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/properties/DefaultPropertiesTest.java @@ -6,12 +6,19 @@ import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.opendatakit.services.utilities.UserState; import org.opendatakit.utilities.StaticStateManipulator; import static com.google.common.truth.Truth.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.HashMap; +import java.util.Map; + public class DefaultPropertiesTest { public final String APP_NAME = "DefaultPropTest"; @@ -97,6 +104,69 @@ public void verifyLastSyncInfoProperty() { assertThat(lastSyncInfo).isNull(); } + @Test + public void verifyDefaultPropertyValue() { + PropertiesSingleton props = getProps(getContext()); + // Example of checking a default property value + String defaultValue = props.getProperty("non_existing_key"); + assertThat(defaultValue).isNull(); + } + + @Test + public void verifyServerUrlPropertyFormat() { + PropertiesSingleton props = getProps(getContext()); + String serverUrl = props.getProperty(CommonToolProperties.KEY_SYNC_SERVER_URL); + assertThat(serverUrl).matches("https?://.*"); // Basic URL pattern check + } + + @Test + public void verifyUsernamePropertyLength() { + PropertiesSingleton props = getProps(getContext()); + String username = props.getProperty(CommonToolProperties.KEY_USERNAME); + + assertThat(username).isNotNull(); + assertThat(username.length()).isAtMost(50); // Example length constraint + } + + @Test + public void verifyMissingKeyReturnsNull() { + PropertiesSingleton props = getProps(getContext()); + String missingKey = props.getProperty("missing_key"); + assertThat(missingKey).isNull(); + } + + @Ignore // need to verify how properties is set internally + @Test + public void verifyPropertiesReset() { + PropertiesSingleton props = getProps(getContext()); + + // Define properties to set + Map properties = new HashMap<>(); + properties.put(CommonToolProperties.KEY_USERNAME, "testUser"); + + // Set properties + props.setProperties(properties); + + // Ensure the property is set correctly + assertEquals("testUser", props.getProperty(CommonToolProperties.KEY_USERNAME)); + + // Reset properties by clearing them explicitly + clearAllProperties(props); + + // Retrieve properties after reset + String username = props.getProperty(CommonToolProperties.KEY_USERNAME); + + // Verify properties have been reset + assertNull("Username property should be null after reset", username); + } + + private void clearAllProperties(PropertiesSingleton props) { + // Clear all properties by setting an empty map + props.setProperties(new HashMap<>()); + System.out.println("All properties cleared."); + } + + @After public void clearProperties() { StaticStateManipulator.get().reset();