<commit_before>package uk.ac.ebi.atlas.model.experiment;

import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import uk.ac.ebi.atlas.model.DescribesDataColumns;
import uk.ac.ebi.atlas.model.experiment.Experiment;
import uk.ac.ebi.atlas.trader.ExperimentTrader;

import javax.annotation.Nullable;
import javax.inject.Inject;

import java.util.List;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:applicationContext.xml", "/dispatcher-servlet.xml"})
public class ExperimentGroupingsForHeatmapIT {

    @Inject
    ExperimentTrader experimentTrader;

    @Test
    public void testSomeGoodExperiments() throws Exception {

        outputInFineFormatForExperiment("E-MTAB-513");
        outputInFineFormatForExperiment("E-MTAB-2706");
        outputInFineFormatForExperiment("E-GEOD-54705");
        outputInFineFormatForExperiment("E-MTAB-4260");

    }

    /*
    For differential experiments, a few groupings repeat and we might need something else for them.

     */

    public void outputInFineFormatForExperiment(String accession){
        Experiment<DescribesDataColumns> experiment = experimentTrader.getPublicExperiment(accession);

        List<String> allDescriptorIds = FluentIterable.from(experiment.getDataColumnDescriptors()).transform(
                new Function<DescribesDataColumns, String>() {
                    @Nullable
                    @Override
                    public String apply(@Nullable DescribesDataColumns describesDataColumns) {
                        return describesDataColumns.getId();
                    }
                }).toList();

        JsonArray result = experiment.groupingsForHeatmap();

        assertThat(result.size(), greaterThan(0));

        for(JsonElement element: result){
            assertTrue(element.getAsJsonObject().has("name"));
            assertTrue(element.getAsJsonObject().has("selected"));
            assertThat(element.getAsJsonObject().get("groupings").getAsJsonArray().size(), greaterThan(0));
            for(JsonElement grouping: element.getAsJsonObject().get("groupings").getAsJsonArray()){
                assertThat(grouping.getAsJsonArray().size(), is(2));
                assertThat(grouping.getAsJsonArray().get(1).getAsJsonArray().size(), greaterThan(0));
                for(JsonElement groupingValue : grouping.getAsJsonArray().get(1).getAsJsonArray()){
                    assertTrue(allDescriptorIds.contains(groupingValue.getAsString()));
                }
            }
        }
    }
}<commit_msg>Migrate Guava functional thing to Java<commit_after>package uk.ac.ebi.atlas.model.experiment;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import uk.ac.ebi.atlas.model.DescribesDataColumns;
import uk.ac.ebi.atlas.trader.ExperimentTrader;

import javax.inject.Inject;

import java.util.List;
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:applicationContext.xml", "/dispatcher-servlet.xml"})
public class ExperimentGroupingsForHeatmapIT {

    @Inject
    ExperimentTrader experimentTrader;

    @Test
    public void testSomeGoodExperiments() throws Exception {

        outputInFineFormatForExperiment("E-MTAB-513");
        outputInFineFormatForExperiment("E-MTAB-2706");
        outputInFineFormatForExperiment("E-GEOD-54705");
        outputInFineFormatForExperiment("E-MTAB-4260");

    }

    /*
    For differential experiments, a few groupings repeat and we might need something else for them.
     */

    public void outputInFineFormatForExperiment(String accession){
        Experiment<DescribesDataColumns> experiment = experimentTrader.getPublicExperiment(accession);

        List<String> allDescriptorIds = experiment.getDataColumnDescriptors().stream()
                .map(DescribesDataColumns::getId)
                .collect(Collectors.toList());

        JsonArray result = experiment.groupingsForHeatmap();

        assertThat(result.size(), greaterThan(0));

        for(JsonElement element: result){
            assertTrue(element.getAsJsonObject().has("name"));
            assertTrue(element.getAsJsonObject().has("selected"));
            assertThat(element.getAsJsonObject().get("groupings").getAsJsonArray().size(), greaterThan(0));
            for(JsonElement grouping: element.getAsJsonObject().get("groupings").getAsJsonArray()){
                assertThat(grouping.getAsJsonArray().size(), is(2));
                assertThat(grouping.getAsJsonArray().get(1).getAsJsonArray().size(), greaterThan(0));
                for(JsonElement groupingValue : grouping.getAsJsonArray().get(1).getAsJsonArray()){
                    assertTrue(allDescriptorIds.contains(groupingValue.getAsString()));
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.11076115485564304, 'fraction_numerical': 0.008748906386701663, 'mean_word_length': 3.716171617161716, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3440895', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1552, 'n_words': 234}