<commit_before>package org.adligo.i.log;

import java.net.URL;

import junit.framework.TestCase;

import org.adligo.i.log.client.LogPlatform;
import org.adligo.i.log.mocks.MockLogPlatform;
import org.adligo.i.util.client.I_SystemOutput;
import org.adligo.i.util.mocks.MockPropertyFactory;
import org.adligo.j2se.util.J2SEPlatform;
import org.mortbay.log.Log;

public class LogPlatformTests extends TestCase implements I_SystemOutput {
	private Throwable lastExceptionPrint = null;
	private boolean log = true;
	
	public void testInit() throws Exception {
		Exception ex = null;
		try {
			LogPlatform.init();
		} catch (Exception x) {
			ex = x;
		}
		assertNotNull(ex);
		assertEquals("Please initalize your platform BEFORE the LogPlatform, " +
				"for instance J2SEPlatform.init(), GWTPlatform.init(), J2MEPlatform.init. ", 
				ex.getMessage());
		
		J2SEPlatform.init();
		MockLogPlatform.unInit();
		LogPlatform.init();
		
		
		ex = null;
		try {
			LogPlatform.init();
		} catch (Exception x) {
			ex = x;
		}
		assertNotNull(ex);
		assertEquals("LogPlatform has already been initialized.", 
				ex.getMessage());
		
		
		MockLogPlatform.unInit();
		lastExceptionPrint  = null;
		URL url = LogPlatform.class.getResource("/adligo_log_log4j_factory.properties");
		String fileName = url.getFile();
		
		
		
		LogPlatform.init("adligo_log_log4j_factory.properties");
		String expected = "Error reading property file '/adligo_log_log4j_factory.properties'  file system name '" + fileName +"' file content; " +
		"\nMapWrapper{defaultlog=DEBUG, log_factory=org.adligo.i.log.log4j.Log4jFactory}";
		assertNotNull(lastExceptionPrint);
		if (log) {
			System.out.println("exception is; \n'" + lastExceptionPrint .getMessage() + "'");
			System.out.println("expected exception is; \n'" +  expected + "'");
		}
		assertEquals(expected, 
				lastExceptionPrint .getMessage());
		
		assertNotNull(lastExceptionPrint.getCause());
		assertEquals("log_factory is null, because your code needs to call " +
				"LogPlatform.addLogFactoryClass(String name, I_LogFactory p) " +
				"with a valid instance of your logFactory org.adligo.i.log.log4j.Log4jFactory!", 
				lastExceptionPrint.getCause().getMessage());
	}

	@Override
	protected void setUp() throws Exception {
		// TODO Auto-generated method stub
		super.setUp();
		J2SEPlatform.init();
		MockLogPlatform.setOutput(this);
		MockPropertyFactory.uninit();
	}

	@Override
	protected void tearDown() throws Exception {
		// TODO Auto-generated method stub
		super.tearDown();
		J2SEPlatform.init();
	}

	@Override
	public void err(String p) {
		assertTrue("Shouldn't have printing here " + p, false);
	}

	@Override
	public void exception(Throwable x) {<commit_msg>uptades to console printing when things go ary<commit_after>package org.adligo.i.log;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.adligo.i.log.client.LogPlatform;
import org.adligo.i.log.mocks.MockLogPlatform;
import org.adligo.i.util.client.I_SystemOutput;
import org.adligo.i.util.mocks.MockPropertyFactory;
import org.adligo.j2se.util.J2SEPlatform;
import org.mortbay.log.Log;

public class LogPlatformTests extends TestCase implements I_SystemOutput {
	private Throwable lastExceptionPrint = null;
	private List<String> prints = new ArrayList<String>();
	private boolean log = true;
	
	public void testInit() throws Exception {
		Exception ex = null;
		try {
			LogPlatform.init();
		} catch (Exception x) {
			ex = x;
		}
		assertNotNull(ex);
		assertEquals("Please initalize your platform BEFORE the LogPlatform, " +
				"for instance J2SEPlatform.init(), GWTPlatform.init(), J2MEPlatform.init. ", 
				ex.getMessage());
		
		J2SEPlatform.init();
		MockLogPlatform.unInit();
		LogPlatform.init();
		
		
		ex = null;
		try {
			LogPlatform.init();
		} catch (Exception x) {
			ex = x;
		}
		assertNotNull(ex);
		assertEquals("LogPlatform has already been initialized.", 
				ex.getMessage());
		
		
		MockLogPlatform.unInit();
		lastExceptionPrint  = null;
		String dotFile = new File(".").getAbsolutePath();
		String fileName = dotFile.substring(0, dotFile.length() - 2) + File.separator +
			"no_file.properties";
		
		LogPlatform.init("/no_file.properties");
		assertNull(lastExceptionPrint);
		assertEquals(2, prints.size());
		assertEquals("error reading file '/no_file.properties' " +
				"system file 'null' using defaults;", prints.get(0));
		assertEquals("using defaults {gwt_loggers=simple, defaultlog=INFO}", prints.get(1));
		
		URL url = LogPlatform.class.getResource("/adligo_log_log4j_factory.properties");
		fileName = url.getFile();
		MockLogPlatform.unInit();
		prints.clear();
		lastExceptionPrint = null;
		LogPlatform.init("/adligo_log_log4j_factory.properties");
		assertNotNull(lastExceptionPrint);
		assertEquals("log_factory is null, because your code needs to call " +
				"LogPlatform.addLogFactoryClass(String name, I_LogFactory p) " +
				"with a valid instance of your logFactory org.adligo.i.log.log4j.Log4jFactory!", 
				lastExceptionPrint.getMessage());
	}

	@Override
	protected void setUp() throws Exception {
		// TODO Auto-generated method stub
		super.setUp();
		J2SEPlatform.init();
		MockLogPlatform.setOutput(this);
		MockPropertyFactory.uninit();
	}

	@Override
	protected void tearDown() throws Exception {
		// TODO Auto-generated method stub
		super.tearDown();
		J2SEPlatform.init();
	}

	@Override
	public void err(String p) {
		prints.add(p);
	}

	@Override
	public void exception(Throwable x) {
{'fraction_non_alphanumeric': 0.12223222322232223, 'fraction_numerical': 0.0054005400540054005, 'mean_word_length': 4.399416909620991, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3214265', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1756, 'n_words': 389}