<commit_before>package org.rapidoid.test;

/*
 * #%L
 * rapidoid-test-commons
 * %%
 * Copyright (C) 2014 - 2015 <NAME>
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Random;
import java.util.concurrent.CountDownLatch;

import org.mockito.Mockito;
import org.mockito.stubbing.OngoingStubbing;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

public abstract class TestCommons {

	protected static final Random RND = new Random();

	private boolean hasError = false;

	@BeforeMethod(alwaysRun = true)
	public void init() {
		hasError = false;

		try {
			Class<?> clazz = Class.forName("org.rapidoid.util.IOC");
			try {
				Method reset = clazz.getMethod("reset");
				try {
					reset.invoke(null);
				} catch (Exception e) {
					throw new RuntimeException("Cannot find method: UTILS.reset", e);
				}
			} catch (NoSuchMethodException e) {
				throw new RuntimeException("Cannot find method: UTILS.reset");
			} catch (SecurityException e) {
				throw new RuntimeException("Cannot access method: UTILS.reset");
			}

		} catch (ClassNotFoundException e) {
		}
	}

	@AfterMethod(alwaysRun = true)
	public void checkForErrors() {
		if (hasError) {
			Assert.fail("Assertion error(s) occured, probably were caught or were thrown on non-main thread!");
		}
	}

	protected void registerError(AssertionError e) {
		hasError = true;
	}

	protected void fail(String msg) {
		try {
			Assert.fail(msg);
		} catch (AssertionError e) {
			registerError(e);
			throw e;
		}
	}

	protected void isNull(Object value) {
		try {<commit_msg>Code clean-up and minor improvements in the test commons.<commit_after>package org.rapidoid.test;

/*
 * #%L
 * rapidoid-test-commons
 * %%
 * Copyright (C) 2014 - 2015 <NAME>
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.io.File;
import java.net.URL;
import java.util.Random;
import java.util.concurrent.CountDownLatch;

import org.mockito.Mockito;
import org.mockito.stubbing.OngoingStubbing;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

public abstract class TestCommons {

	protected static final Random RND = new Random();

	private volatile boolean hasError = false;

	@BeforeMethod(alwaysRun = true)
	public void init() {
		hasError = false;
	}

	@AfterMethod(alwaysRun = true)
	public void checkForErrors() {
		if (hasError) {
			Assert.fail("Assertion error(s) occured, probably were caught or were thrown on non-main thread!");
		}
	}

	protected void registerError(AssertionError e) {
		hasError = true;
	}

	protected void fail(String msg) {
		try {
			Assert.fail(msg);
		} catch (AssertionError e) {
			registerError(e);
			throw e;
		}
	}

	protected void isNull(Object value) {
		try {
{'fraction_non_alphanumeric': 0.10290371879775853, 'fraction_numerical': 0.006113092205807438, 'mean_word_length': 3.848148148148148, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '17650', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1175, 'n_words': 392}