<commit_before>package au.com.agic.apptesting.utils.impl;

import au.com.agic.apptesting.junit.Testcase;
import au.com.agic.apptesting.junit.Testsuite;
import au.com.agic.apptesting.utils.JUnitReportMerge;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.List;
import java.util.Optional;

import javax.validation.constraints.NotNull;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
 * An implementation of JUnitReportMerge that uses JAXB to merge reports
 */
public class JUnitReportMergeImpl implements JUnitReportMerge {

	private static final Logger LOGGER = LoggerFactory.getLogger(JUnitReportMergeImpl.class);

	@Override
	public Optional<String> mergeReports(@NotNull final List<String> reports) {
		try {
			final JAXBContext jaxbContext = JAXBContext.newInstance(Testsuite.class);
			final Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
			final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

			// output pretty printed
			jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

			// The master test suite
			final Testsuite masterTestSuite = new Testsuite();

			int index = 1;
			for (final String report : reports) {
				final Testsuite testSuite = (Testsuite) jaxbUnmarshaller.unmarshal(new File(report));
				masterTestSuite.setFailures(masterTestSuite.getFailures() + testSuite.getFailures());
				masterTestSuite.setSkipped(masterTestSuite.getSkipped() + testSuite.getSkipped());
				masterTestSuite.setTests(masterTestSuite.getTests() + testSuite.getTests());
				masterTestSuite.setTime(masterTestSuite.getTime() + testSuite.getTime());

				/*
					Bamboo requires that test names be unique, so we prefix each with
					an index.
				 */
				for (final Testcase testCase : testSuite.getTestcase()) {
					testCase.setName(index + ": " + testCase.getName());<commit_msg>Fixing an issue with the merged junit reports and Bamboo jUnit parsing<commit_after>package au.com.agic.apptesting.utils.impl;

import au.com.agic.apptesting.junit.Testcase;
import au.com.agic.apptesting.junit.Testsuite;
import au.com.agic.apptesting.utils.JUnitReportMerge;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.List;
import java.util.Optional;

import javax.validation.constraints.NotNull;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
 * An implementation of JUnitReportMerge that uses JAXB to merge reports
 */
public class JUnitReportMergeImpl implements JUnitReportMerge {

	private static final Logger LOGGER = LoggerFactory.getLogger(JUnitReportMergeImpl.class);

	@Override
	public Optional<String> mergeReports(@NotNull final List<String> reports) {
		try {
			final JAXBContext jaxbContext = JAXBContext.newInstance(Testsuite.class);
			final Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
			final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

			// output pretty printed
			jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

			// The master test suite
			final Testsuite masterTestSuite = new Testsuite();

			int index = 1;
			for (final String report : reports) {
				final Testsuite testSuite = (Testsuite) jaxbUnmarshaller.unmarshal(new File(report));
				masterTestSuite.setFailures(masterTestSuite.getFailures() + testSuite.getFailures());
				masterTestSuite.setSkipped(masterTestSuite.getSkipped() + testSuite.getSkipped());
				masterTestSuite.setTests(masterTestSuite.getTests() + testSuite.getTests());
				masterTestSuite.setTime(masterTestSuite.getTime() + testSuite.getTime());

				/*
					Bamboo requires that test names be unique, so we prefix each with
					an index.
					https://answers.atlassian.com/questions/192018/bamboo-junit-parser-with-duplicate-testcase-names
				 */
				for (final Testcase testCase : testSuite.getTestcase()) {
					testCase.setName(index + ": " + testCase.getName());
{'fraction_non_alphanumeric': 0.09954751131221719, 'fraction_numerical': 0.0028578232912598238, 'mean_word_length': 5.095791001451379, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '6348090', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1285, 'n_words': 267}