<commit_before>package cucumber.api.testng;

import static org.testng.Reporter.getCurrentTestResult;
import static org.testng.Reporter.log;

import cucumber.api.Result;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestRunFinished;
import cucumber.api.event.TestStepFinished;
import cucumber.api.formatter.Formatter;
import cucumber.api.formatter.NiceAppendable;
import cucumber.runtime.Utils;
import org.testng.ITestResult;

class TestNGReporter implements Formatter {
    private final NiceAppendable out;
    private final EventHandler<TestStepFinished> testStepFinishedHandler = new EventHandler<TestStepFinished>() {
        @Override
        public void receive(TestStepFinished event) {
            if (!event.testStep.isHook()) {
                result(event.testStep.getStepText(), event.result);
            }
        }
    };
    private EventHandler<TestRunFinished> runFinishHandler = new EventHandler<TestRunFinished>() {

        @Override
        public void receive(TestRunFinished event) {
            out.close();
        }
    };


    TestNGReporter(Appendable appendable) {
        out = new NiceAppendable(appendable);
    }

    @Override
    public void setEventPublisher(EventPublisher publisher) {
        publisher.registerHandlerFor(TestStepFinished.class, testStepFinishedHandler);
        publisher.registerHandlerFor(TestRunFinished.class, runFinishHandler);
    }

    void uri(String uri) {
        // TODO: find an appropriate keyword
        String keyword = "Feature File";
        logDiv(keyword, uri, "featureFile");
    }

    private void result(String stepText, Result result) {
        logResult(stepText, result);
        ITestResult tr = getCurrentTestResult();

        switch (result.getStatus()) {
            case PASSED:
                // do nothing
                break;
            case FAILED:
            case AMBIGUOUS:
                tr.setThrowable(result.getError());
                tr.setStatus(ITestResult.FAILURE);
                break;
            case SKIPPED:
                tr.setThrowable(result.getError());
                tr.setStatus(ITestResult.SKIP);
            case UNDEFINED:
            case PENDING:
                tr.setThrowable(result.getError());
                tr.setStatus(ITestResult.FAILURE);
                break;
            default:
                throw new IllegalStateException("Unexpected result status: " + result.getStatus());
        }
    }

    private void logResult(String stepText, Result result) {
        String timing = computeTiming(result);

        String format = "%s (%s%s)";
        String message = String.format(format, stepText, result.getStatus(), timing);

        logDiv(message, "result");
    }

    private String computeTiming(Result result) {
        String timing = "";

        if (result.getDuration() != null) {<commit_msg>[TestNG] Fix fallthrough in TestNGReporter<commit_after>package cucumber.api.testng;

import static org.testng.Reporter.getCurrentTestResult;
import static org.testng.Reporter.log;

import cucumber.api.Result;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventPublisher;
import cucumber.api.event.TestRunFinished;
import cucumber.api.event.TestStepFinished;
import cucumber.api.formatter.Formatter;
import cucumber.api.formatter.NiceAppendable;
import cucumber.runtime.Utils;
import org.testng.ITestResult;

class TestNGReporter implements Formatter {
    private final NiceAppendable out;
    private final EventHandler<TestStepFinished> testStepFinishedHandler = new EventHandler<TestStepFinished>() {
        @Override
        public void receive(TestStepFinished event) {
            if (!event.testStep.isHook()) {
                result(event.testStep.getStepText(), event.result);
            }
        }
    };
    private EventHandler<TestRunFinished> runFinishHandler = new EventHandler<TestRunFinished>() {

        @Override
        public void receive(TestRunFinished event) {
            out.close();
        }
    };


    TestNGReporter(Appendable appendable) {
        out = new NiceAppendable(appendable);
    }

    @Override
    public void setEventPublisher(EventPublisher publisher) {
        publisher.registerHandlerFor(TestStepFinished.class, testStepFinishedHandler);
        publisher.registerHandlerFor(TestRunFinished.class, runFinishHandler);
    }

    void uri(String uri) {
        // TODO: find an appropriate keyword
        String keyword = "Feature File";
        logDiv(keyword, uri, "featureFile");
    }

    private void result(String stepText, Result result) {
        logResult(stepText, result);
        ITestResult tr = getCurrentTestResult();

        switch (result.getStatus()) {
            case PASSED:
                // do nothing
                break;
            case FAILED:
            case AMBIGUOUS:
                tr.setThrowable(result.getError());
                tr.setStatus(ITestResult.FAILURE);
                break;
            case SKIPPED:
                tr.setThrowable(result.getError());
                tr.setStatus(ITestResult.SKIP);
                break;
            case UNDEFINED:
            case PENDING:
                tr.setThrowable(result.getError());
                tr.setStatus(ITestResult.FAILURE);
                break;
            default:
                throw new IllegalStateException("Unexpected result status: " + result.getStatus());
        }
    }

    private void logResult(String stepText, Result result) {
        String timing = computeTiming(result);

        String format = "%s (%s%s)";
        String message = String.format(format, stepText, result.getStatus(), timing);

        logDiv(message, "result");
    }

    private String computeTiming(Result result) {
        String timing = "";

        if (result.getDuration() != null) {
{'fraction_non_alphanumeric': 0.09290081521739131, 'fraction_numerical': 0.0, 'mean_word_length': 2.480496453900709, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7057879', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1547, 'n_words': 329}