<commit_before>package de.akquinet.jbosscc.needle.mock;

import java.lang.reflect.Modifier;

import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A Mockito specific {@link MockProvider} implementation. For more details, see
 * the Mockito documentation.
 *
 */
public class MockitoProvider implements MockProvider {
	private static final Logger LOG = LoggerFactory.getLogger(MockitoProvider.class);

	/**
	 * {@inheritDoc} Skipping creation, if the type is final or primitive.
	 *
	 * @return the mock object or null, if the type is final or primitive.
	 */
	@Override
	public <T> T createMockComponent(Class<T> type) {
		if (Modifier.isFinal(type.getModifiers()) || type.isPrimitive()) {
			LOG.warn("Skipping creation of a mock : {} as it is final or primitive type.", type.getSimpleName());
			return null;
		}

		return Mockito.mock(type);
	}

}<commit_msg>MockitoProvider is now also a SpayProvider<commit_after>package de.akquinet.jbosscc.needle.mock;

import java.lang.annotation.Annotation;
import java.lang.reflect.Modifier;

import org.mockito.Mockito;
import org.mockito.Spy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A Mockito specific {@link MockProvider} implementation. For more details, see
 * the Mockito documentation.
 */
public class MockitoProvider implements MockProvider, SpyProvider {

    private static final Logger LOG = LoggerFactory.getLogger(MockitoProvider.class);

    /**
     * {@inheritDoc} Skipping creation, if the type is final or primitive.
     * 
     * @return the mock object or null, if the type is final or primitive.
     */
    @Override
    public <T> T createMockComponent(final Class<T> type) {
        if (isFinalOrPrimitive(type)) {
            LOG.warn("Skipping creation of a mock : {} as it is final or primitive type.", type.getSimpleName());
            return null;
        }

        return Mockito.mock(type);
    }

    /**
     * {@inheritDoc} Skipping creation, if the type is final or primitive.
     * 
     * @return the mock object or null, if the type is final or primitive.
     */
    @Override
    public <T> T createSpyComponent(final T instance) {
        if (instance == null) {
            throw new IllegalArgumentException("instance must not be null!");
        }
        if (isFinalOrPrimitive(instance.getClass())) {
            LOG.warn("Skipping creation of a spy : {} as it is final or primitive type.", instance.getClass().getSimpleName());
            return null;
        }
        return Mockito.spy(instance);
    }

    /**
     * @param type
     * @return <code>true</code> if type is final or primitive, <code>false</code> else.
     */
    private boolean isFinalOrPrimitive(final Class<?> type) {
        return Modifier.isFinal(type.getModifiers()) || type.isPrimitive();
    }

    @Override
    public Class<? extends Annotation> getSpyAnnotation() {
        return Spy.class;
    }
}
{'fraction_non_alphanumeric': 0.10805300713557595, 'fraction_numerical': 0.0013591573224600749, 'mean_word_length': 3.15819209039548, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '7391955', 'n_tokens_mistral': 857, 'n_tokens_neox': 844, 'n_words': 263}