<commit_before>package net.sf.clirr.core.internal.checks;

import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;

import net.sf.clirr.core.internal.ApiDiffDispatcher;
import net.sf.clirr.core.internal.checks.ExpectedDiff;
import net.sf.clirr.core.ApiDifference;
import net.sf.clirr.core.MessageTranslator;
import junit.framework.TestCase;

class TestDiffListener implements ApiDiffDispatcher
{
        private MessageTranslator translator = new MessageTranslator();

        private Set diffs = new HashSet();

        public void fireDiff(ApiDifference difference)
        {
            diffs.add(difference);
        }

        public void checkExpected(ExpectedDiff[] expectedDiffs)
        {
            for (int i=0; i<expectedDiffs.length; ++i)
            {
                ExpectedDiff expected = expectedDiffs[i];

                // now see if the expected diff is in fact in the set of
                // diffs that occurred during the test comparison
                boolean found = false;
                for(Iterator j = diffs.iterator(); j.hasNext() && !found;)
                {
                    ApiDifference actual = (ApiDifference) j.next();
                    found = expected.matches(actual);
                }

                if (!found)
                {
                    TestCase.fail("expected diff " + expected + " was not generated: " + diffs);
                }
            }

            for (Iterator it = diffs.iterator(); it.hasNext();) {
                ApiDifference actual = (ApiDifference) it.next();

                // see if the generated diff is in fact in the expected set
                boolean found = false;
                for(int i=0; i<expectedDiffs.length && !found; ++i)
                {
                    found = expectedDiffs[i].matches(actual);
                }

                if (!found)
                {
                    TestCase.fail("unexpected diff " + actual);
                }
            }
        }
}<commit_msg>The ApiDifference.toString() method no longer reports a human-readable message, because a resource bundle must be selected to generate one. So here we can't rely on toString() to generate a nice error message on test case failure. Instead we build one using the default translation.<commit_after>package net.sf.clirr.core.internal.checks;

import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;

import net.sf.clirr.core.internal.ApiDiffDispatcher;
import net.sf.clirr.core.internal.checks.ExpectedDiff;
import net.sf.clirr.core.ApiDifference;
import net.sf.clirr.core.MessageTranslator;
import junit.framework.TestCase;

class TestDiffListener implements ApiDiffDispatcher
{
        private MessageTranslator translator = new MessageTranslator();

        private Set diffs = new HashSet();

        public void fireDiff(ApiDifference difference)
        {
            diffs.add(difference);
        }

        public void checkExpected(ExpectedDiff[] expectedDiffs)
        {
            for (int i=0; i<expectedDiffs.length; ++i)
            {
                ExpectedDiff expected = expectedDiffs[i];

                // now see if the expected diff is in fact in the set of
                // diffs that occurred during the test comparison
                boolean found = false;
                for(Iterator j = diffs.iterator(); j.hasNext() && !found;)
                {
                    ApiDifference actual = (ApiDifference) j.next();
                    found = expected.matches(actual);
                }

                if (!found)
                {
                    // build a useful failure message
                    MessageTranslator translator = new MessageTranslator();

                    StringBuffer buf = new StringBuffer();
                    buf.append("Expected diff " + expected + " was not generated.");
                    buf.append(" Actual diffs generated were: ");
                    for(Iterator diffIter = diffs.iterator(); diffIter.hasNext();)
                    {
                        ApiDifference diff = (ApiDifference) diffIter.next();

                        buf.append(diff.toString(translator));
                        if (diffIter.hasNext())
                        {
                            buf.append(", ");
                        }
                    }

                    TestCase.fail(buf.toString());
                }
            }

            for (Iterator it = diffs.iterator(); it.hasNext();) {
                ApiDifference actual = (ApiDifference) it.next();

                // see if the generated diff is in fact in the expected set
                boolean found = false;
                for(int i=0; i<expectedDiffs.length && !found; ++i)
                {
                    found = expectedDiffs[i].matches(actual);
                }

                if (!found)
                {
                    TestCase.fail("unexpected diff " + actual);
                }
            }
        }
}
{'fraction_non_alphanumeric': 0.09125399361022364, 'fraction_numerical': 0.0007987220447284345, 'mean_word_length': 1.5634595701125895, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '4824703', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1198, 'n_words': 329}