All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.contrib.java.lang.system.internal.RestoreSpecificSystemProperties Maven / Gradle / Ivy

package org.junit.contrib.java.lang.system.internal;

import static java.lang.System.*;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class RestoreSpecificSystemProperties {
	private final List properties = new ArrayList();
	private final List originalValues = new ArrayList();

	public void add(String property) {
		properties.add(property);
		originalValues.add(getProperty(property));
	}

	public void restore() {
		Iterator itOriginalValues = originalValues.iterator();
		for (String property : properties)
			restore(property, itOriginalValues.next());
	}

	private void restore(String property, String originalValue) {
		if (originalValue == null)
			clearProperty(property);
		else
			setProperty(property, originalValue);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy