<commit_before>package nz.ac.auckland.integration.testing.predicate;

import org.apache.camel.Exchange;
import org.apache.camel.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A class for ensuring an exception received is as expected based on the class and message
 *
 * @author <NAME> <<EMAIL>>
 */
public class ExceptionPredicate implements Predicate {

    private static final Logger logger = LoggerFactory.getLogger(ExceptionPredicate.class);
    private Class<? extends Exception> expectedExceptionClass;
    private String message;

    /**
     * A constructor that simply expects a subclass of java.lang.Exception
     */
    public ExceptionPredicate() {
        this.expectedExceptionClass = Exception.class;
    }

    /**
     * @param expectedExceptionClass The class of exception we expect to validate against
     */
    public ExceptionPredicate(Class<? extends Exception> expectedExceptionClass) {
        this.expectedExceptionClass = expectedExceptionClass;
    }

    /**
     * @param expectedExceptionClass The class of exception we expect to validate against
     * @param message                The message this instance should be returning
     */
    public ExceptionPredicate(Class<? extends Exception> expectedExceptionClass, String message) {
        this(expectedExceptionClass);
        this.message = message;
    }

    public boolean matches(Exchange exchange) {
        Throwable t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);

        if (t == null) {
            logger.warn("An exception was expected to be received");
            return false;
        }

        logger.debug("An execution exception was encountered on endpoint {}", exchange.getFromEndpoint().getEndpointUri(), t);
        boolean matches = t.getClass().equals(expectedExceptionClass) || message == null || message.equals(t.getMessage());
        if (!matches)
            logger.warn("The exception did not match the expected exception from endpoint {}", exchange.getFromEndpoint().getEndpointUri());

        return matches;
    }

    @Override
    public String toString() {
        return "ExceptionPredicate: Class:" + expectedExceptionClass.toString() +
                (message != null ? ",Message:" + message : "");
    }
}<commit_msg>fixed case where no exception class match and no message provided<commit_after>package nz.ac.auckland.integration.testing.predicate;

import org.apache.camel.Exchange;
import org.apache.camel.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A class for ensuring an exception received is as expected based on the class and message
 *
 * @author <NAME> <<EMAIL>>
 */
public class ExceptionPredicate implements Predicate {

    private static final Logger logger = LoggerFactory.getLogger(ExceptionPredicate.class);
    private Class<? extends Exception> expectedExceptionClass;
    private String message;

    /**
     * A constructor that simply expects a subclass of java.lang.Exception
     */
    public ExceptionPredicate() {
        this.expectedExceptionClass = Exception.class;
    }

    /**
     * @param expectedExceptionClass The class of exception we expect to validate against
     */
    public ExceptionPredicate(Class<? extends Exception> expectedExceptionClass) {
        this.expectedExceptionClass = expectedExceptionClass;
    }

    /**
     * @param expectedExceptionClass The class of exception we expect to validate against
     * @param message                The message this instance should be returning
     */
    public ExceptionPredicate(Class<? extends Exception> expectedExceptionClass, String message) {
        this(expectedExceptionClass);
        this.message = message;
    }

    public boolean matches(Exchange exchange) {
        Throwable t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);

        if (t == null) {
            logger.warn("An exception was expected to be received on endpoint {}", exchange.getFromEndpoint().getEndpointUri());
            return false;
        }

        logger.debug("An execution exception was encountered on endpoint {}", exchange.getFromEndpoint().getEndpointUri(), t);
        boolean matches = t.getClass().equals(expectedExceptionClass) && (message == null || message.equals(t.getMessage()));
        if (!matches)
            logger.warn("The exception did not match the expected exception from endpoint {}", exchange.getFromEndpoint().getEndpointUri());

        return matches;
    }

    @Override
    public String toString() {
        return "ExceptionPredicate: Class:" + expectedExceptionClass.toString() +
                (message != null ? ",Message:" + message : "");
    }
}
{'fraction_non_alphanumeric': 0.09347181008902077, 'fraction_numerical': 0.000847816871555744, 'mean_word_length': 3.2628726287262872, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '5015800', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1113, 'n_words': 355}