<commit_before>package ut.fi.ambientia.abtesting.model.experiments;

import fi.ambientia.abtesting.action.experiments.feature_battles.AlreadyDecidedBattles;
import fi.ambientia.abtesting.action.experiments.feature_battles.ChooseExperiment;
import fi.ambientia.abtesting.model.experiments.Experiment;
import fi.ambientia.abtesting.model.feature_battles.FeatureBattleIdentifier;
import fi.ambientia.abtesting.model.feature_battles.FeatureBattleRepository;
import fi.ambientia.abtesting.model.experiments.GoodOldWay;
import fi.ambientia.abtesting.model.feature_battles.FeatureBattleResult;
import fi.ambientia.abtesting.model.user.UserIdentifier;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import ut.fi.ambientia.abtesting.model.TestData;

import java.util.Arrays;
import java.util.Optional;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class AlreadyDecidedBattlesShould {

    private static final String USERKEY = "USERKEY";
    private static final UserIdentifier USER_IDENTIFIER = new UserIdentifier(USERKEY);
    private static final FeatureBattleIdentifier EXPERIMENT_IDENTIFIER = new FeatureBattleIdentifier("EXPERIMENT");
    private AlreadyDecidedBattles alreadyDecidedBattles;
    private FeatureBattleRepository featureBattleRepository;

    @Before
    public void setUp() throws Exception {
        featureBattleRepository = mock(FeatureBattleRepository.class);
        alreadyDecidedBattles = new AlreadyDecidedBattles( featureBattleRepository );
    }

    @Test
    public void get_list_of_all_feature_battles_for_given_experiment() throws Exception {
        GoodOldWay goodOldWay = TestData.getGoodOld();
        when(featureBattleRepository.featureBattleResultsFor( EXPERIMENT_IDENTIFIER )).
                thenReturn(
                        Arrays.asList(createTestFeatureBattleResult(goodOldWay)
                        ) );

        Optional<Experiment> optional = alreadyDecidedBattles.experimentOf( EXPERIMENT_IDENTIFIER ).targetedFor(ChooseExperiment.forUser( USER_IDENTIFIER ));

        assertThat(optional.get(), equalTo( goodOldWay ));
    }

    // FIXME AkS: commented out test

    @Ignore
    @Test
    public void apply_the_predicate_for_test_results() throws Exception {
        fail("not yet implemented");
    }


//    @Test
//    public void see_if_user_has_already_decided_to_take_either() throws Exception {
//        GoodOldWay goodOldWay = new GoodOldWay();
//        when(featureBattleRepository.votesFor( FEATURE_BATTLE_IDENTIFIER )).
//                thenReturn(
//                        Arrays.asList(createTestFeatureBattleResultWhereUserWantsOldWay(goodOldWay)
//                        ) );
//
//        Optional<Experiment> optional = alreadyDecidedBattles.forExperiment( FEATURE_BATTLE_IDENTIFIER ).targetedFor( USER_IDENTIFIER );
//
//        assertThat(optional.get(), equalTo( goodOldWay ));
//
//
//    }

    private FeatureBattleResult createTestFeatureBattleResultWhereUserWantsOldWay(GoodOldWay goodOldWay) {
        return null;
    }

    private FeatureBattleResult createTestFeatureBattleResult(GoodOldWay goodOldWay) {
        return new FeatureBattleResult( USER_IDENTIFIER, goodOldWay );
    }
}<commit_msg>Adding a test<commit_after>package ut.fi.ambientia.abtesting.model.experiments;

import fi.ambientia.abtesting.action.experiments.feature_battles.AlreadyDecidedBattles;
import fi.ambientia.abtesting.action.experiments.feature_battles.ChooseExperiment;
import fi.ambientia.abtesting.model.experiments.Experiment;
import fi.ambientia.abtesting.model.feature_battles.FeatureBattleIdentifier;
import fi.ambientia.abtesting.model.feature_battles.FeatureBattleRepository;
import fi.ambientia.abtesting.model.experiments.GoodOldWay;
import fi.ambientia.abtesting.model.feature_battles.FeatureBattleResult;
import fi.ambientia.abtesting.model.user.UserIdentifier;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import ut.fi.ambientia.abtesting.model.TestData;

import java.util.Arrays;
import java.util.Optional;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class AlreadyDecidedBattlesShould {

    private static final String USERKEY = "USERKEY";
    private static final UserIdentifier USER_IDENTIFIER = new UserIdentifier(USERKEY);
    private static final FeatureBattleIdentifier EXPERIMENT_IDENTIFIER = new FeatureBattleIdentifier("EXPERIMENT");
    private AlreadyDecidedBattles alreadyDecidedBattles;
    private FeatureBattleRepository featureBattleRepository;
    private final GoodOldWay goodOldWay = TestData.getGoodOld();

    @Before
    public void setUp() throws Exception {
        featureBattleRepository = mock(FeatureBattleRepository.class);
        alreadyDecidedBattles = new AlreadyDecidedBattles( featureBattleRepository );
        when(featureBattleRepository.featureBattleResultsFor( EXPERIMENT_IDENTIFIER )).
                thenReturn(
                        Arrays.asList(createTestFeatureBattleResult(goodOldWay)
                        ) );
    }

    @Test
    public void get_list_of_all_feature_battles_for_given_experiment() throws Exception {

        Optional<Experiment> optional = alreadyDecidedBattles.experimentOf( EXPERIMENT_IDENTIFIER ).targetedFor(ChooseExperiment.forUser( USER_IDENTIFIER ));

        assertThat(optional.get(), equalTo( goodOldWay ));
    }

    @Test
    public void not_receive_any_if_filter_is_set_to_return_false() throws Exception {
        Optional<Experiment> optional = alreadyDecidedBattles.experimentOf( EXPERIMENT_IDENTIFIER ).targetedFor( (any) -> false );
        optional.ifPresent( experiment -> fail("Should not have any, should be empty optional"));
    }

    private FeatureBattleResult createTestFeatureBattleResult(GoodOldWay goodOldWay) {
        return new FeatureBattleResult( USER_IDENTIFIER, goodOldWay );
    }
}
{'fraction_non_alphanumeric': 0.07978285902286561, 'fraction_numerical': 0.0, 'mean_word_length': 4.433422698838249, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5016790', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1740, 'n_words': 299}