Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance and Improve property management tests #295

Open
wants to merge 3 commits into
base: upgrade-jdk11
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<String, String> 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();
Expand Down