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

org.evosuite.junit.rules.Stubbing Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2010-2018 Gordon Fraser, Andrea Arcuri and EvoSuite
 * contributors
 *
 * This file is part of EvoSuite.
 *
 * EvoSuite is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3.0 of the License, or
 * (at your option) any later version.
 *
 * EvoSuite is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with EvoSuite. If not, see .
 */
package org.evosuite.junit.rules;

import java.io.PrintStream;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import javax.swing.DebugGraphics;

public class Stubbing extends BaseRule {

	private Map propertiesToSet = new HashMap();
	
	private Set propertiesToClear = new LinkedHashSet();
	
	private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone();
	
	private PrintStream systemOut = null;
	
	private PrintStream systemErr = null;
	
	private PrintStream logStream = null;
	  
	public Stubbing() {
		org.evosuite.Properties.REPLACE_CALLS = true;
		initProperties();
	}
	
	public void initProperties() {
		
	}
	
	public void setProperty(String key, String value) {
		propertiesToSet.put(key, value);
	}
	
	public void clearProperty(String key) {
		propertiesToClear.add(key);
	}
	
	@Override
	protected void before() {
		org.evosuite.runtime.Runtime.getInstance().resetRuntime();
	    systemErr = System.err; 
	    systemOut = System.out; 
	    logStream = DebugGraphics.logStream(); 
		for(String key : propertiesToSet.keySet()) {
		    java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); 
		    java.lang.System.setProperty(key, propertiesToSet.get(key));
		}
		for(String key : propertiesToClear){
			java.lang.System.clearProperty(key);
		}

	}

	@Override
	protected void after() {
	    System.setErr(systemErr); 
	    System.setOut(systemOut); 
	    DebugGraphics.setLogStream(logStream);
	    java.lang.System.setProperties((java.util.Properties) defaultProperties.clone());
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy