<commit_before>package com.vaadin.tests.components.listselect;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

import com.vaadin.testbench.elements.ListSelectElement;
import com.vaadin.tests.tb3.SingleBrowserTestPhantomJS2;

public class ListSelectTest extends SingleBrowserTestPhantomJS2 {
    @Before
    public void setUp() throws Exception {
        openTestURL();
    }

    @Test
    public void initialLoad_containsCorrectItems() {
        assertItems(20);
    }

    @Test
    public void initialItems_reduceItemCount_containsCorrectItems() {
        selectMenuPath("Component", "Data source", "Items", "5");
        assertItems(5);
    }

    @Test
    public void initialItems_increaseItemCount_containsCorrectItems() {
        selectMenuPath("Component", "Data source", "Items", "100");
        assertItems(100);
    }

    @Test
    public void clickToSelect() {
        selectMenuPath("Component", "Listeners", "Selection listener");

        selectItem("Item 4");
        Assert.assertEquals("1. Selected: [Item 4]", getLogRow(0));

        selectItem("Item 2");
        Assert.assertEquals("3. Selected: [Item 2]", getLogRow(0));

        addItemsToSelection("Item 4");
        Assert.assertEquals("4. Selected: [Item 2, Item 4]", getLogRow(0));

        addItemsToSelection("Item 10", "Item 0", "Item 9"); // will cause 3
                                                            // events

        Assert.assertEquals(
                "7. Selected: [Item 2, Item 4, Item 10, Item 0, Item 9]",
                getLogRow(0));

        removeItemsFromSelection("Item 0", "Item 2", "Item 9"); // will cause 3
                                                                // events
        Assert.assertEquals("10. Selected: [Item 4, Item 10]", getLogRow(0));
    }

    @Test
    public void disabled_clickToSelect() {
        selectMenuPath("Component", "State", "Enabled");

        List<WebElement> select = getListSelect()
                .findElements(By.tagName("select"));
        Assert.assertEquals(1, select.size());
        Assert.assertNotNull(select.get(0).getAttribute("disabled"));

        selectMenuPath("Component", "Listeners", "Selection listener");

        String lastLogRow = getLogRow(0);

        selectItem("Item 4");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();

        addItemsToSelection("Item 2");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();

        removeItemsFromSelection("Item 4");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();
    }

    @Test
    public void readOnly_clickToSelect() {
        selectMenuPath("Component", "Listeners", "Selection listener");
        selectMenuPath("Component", "State", "Readonly");

        List<WebElement> select = getListSelect()
                .findElements(By.tagName("select"));
        Assert.assertEquals(1, select.size());
        Assert.assertNotNull(select.get(0).getAttribute("disabled"));

        String lastLogRow = getLogRow(0);

        selectItem("Item 4");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();

        addItemsToSelection("Item 2");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();

        removeItemsFromSelection("Item 4");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();
    }

    @Test
    public void clickToSelect_reenable() {
        selectMenuPath("Component", "State", "Enabled");
        selectMenuPath("Component", "Listeners", "Selection listener");

        selectItem("Item 4");
        assertNothingSelected();

        selectMenuPath("Component", "State", "Enabled");

        selectItem("Item 5");
        Assert.assertEquals("3. Selected: [Item 5]", getLogRow(0));

        selectItem("Item 1");
        Assert.assertEquals("5. Selected: [Item 1]", getLogRow(0));

        addItemsToSelection("Item 2");
        Assert.assertEquals("6. Selected: [Item 1, Item 2]", getLogRow(0));

        removeItemsFromSelection("Item 1");
        Assert.assertEquals("7. Selected: [Item 2]", getLogRow(0));
    }

    @Test
    public void clickToSelect_notReadOnly() {
        selectMenuPath("Component", "State", "Readonly");
        selectMenuPath("Component", "Listeners", "Selection listener");

        selectItem("Item 4");
        assertNothingSelected();

        selectMenuPath("Component", "State", "Readonly");

        selectItem("Item 5");
        Assert.assertEquals("3. Selected: [Item 5]", getLogRow(0));

        selectItem("Item 1");
        Assert.assertEquals("5. Selected: [Item 1]", getLogRow(0));

        addItemsToSelection("Item 2");
        Assert.assertEquals("6. Selected: [Item 1, Item 2]", getLogRow(0));

        removeItemsFromSelection("Item 1");
        Assert.assertEquals("7. Selected: [Item 2]", getLogRow(0));
    }

    @Test
    public void itemCaptionProvider() {
        selectMenuPath("Component", "Item Generator",
                "Use Item Caption Generator");
        assertItems(20, " Caption");
    }<commit_msg>Fix itemCaptionProvider test case in ListSelectTest<commit_after>package com.vaadin.tests.components.listselect;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

import com.vaadin.testbench.elements.ListSelectElement;
import com.vaadin.tests.tb3.SingleBrowserTestPhantomJS2;

public class ListSelectTest extends SingleBrowserTestPhantomJS2 {
    @Before
    public void setUp() throws Exception {
        openTestURL();
    }

    @Test
    public void initialLoad_containsCorrectItems() {
        assertItems(20);
    }

    @Test
    public void initialItems_reduceItemCount_containsCorrectItems() {
        selectMenuPath("Component", "Data source", "Items", "5");
        assertItems(5);
    }

    @Test
    public void initialItems_increaseItemCount_containsCorrectItems() {
        selectMenuPath("Component", "Data source", "Items", "100");
        assertItems(100);
    }

    @Test
    public void clickToSelect() {
        selectMenuPath("Component", "Listeners", "Selection listener");

        selectItem("Item 4");
        Assert.assertEquals("1. Selected: [Item 4]", getLogRow(0));

        selectItem("Item 2");
        Assert.assertEquals("3. Selected: [Item 2]", getLogRow(0));

        addItemsToSelection("Item 4");
        Assert.assertEquals("4. Selected: [Item 2, Item 4]", getLogRow(0));

        addItemsToSelection("Item 10", "Item 0", "Item 9"); // will cause 3
                                                            // events

        Assert.assertEquals(
                "7. Selected: [Item 2, Item 4, Item 10, Item 0, Item 9]",
                getLogRow(0));

        removeItemsFromSelection("Item 0", "Item 2", "Item 9"); // will cause 3
                                                                // events
        Assert.assertEquals("10. Selected: [Item 4, Item 10]", getLogRow(0));
    }

    @Test
    public void disabled_clickToSelect() {
        selectMenuPath("Component", "State", "Enabled");

        List<WebElement> select = getListSelect()
                .findElements(By.tagName("select"));
        Assert.assertEquals(1, select.size());
        Assert.assertNotNull(select.get(0).getAttribute("disabled"));

        selectMenuPath("Component", "Listeners", "Selection listener");

        String lastLogRow = getLogRow(0);

        selectItem("Item 4");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();

        addItemsToSelection("Item 2");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();

        removeItemsFromSelection("Item 4");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();
    }

    @Test
    public void readOnly_clickToSelect() {
        selectMenuPath("Component", "Listeners", "Selection listener");
        selectMenuPath("Component", "State", "Readonly");

        List<WebElement> select = getListSelect()
                .findElements(By.tagName("select"));
        Assert.assertEquals(1, select.size());
        Assert.assertNotNull(select.get(0).getAttribute("disabled"));

        String lastLogRow = getLogRow(0);

        selectItem("Item 4");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();

        addItemsToSelection("Item 2");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();

        removeItemsFromSelection("Item 4");
        Assert.assertEquals(lastLogRow, getLogRow(0));
        assertNothingSelected();
    }

    @Test
    public void clickToSelect_reenable() {
        selectMenuPath("Component", "State", "Enabled");
        selectMenuPath("Component", "Listeners", "Selection listener");

        selectItem("Item 4");
        assertNothingSelected();

        selectMenuPath("Component", "State", "Enabled");

        selectItem("Item 5");
        Assert.assertEquals("3. Selected: [Item 5]", getLogRow(0));

        selectItem("Item 1");
        Assert.assertEquals("5. Selected: [Item 1]", getLogRow(0));

        addItemsToSelection("Item 2");
        Assert.assertEquals("6. Selected: [Item 1, Item 2]", getLogRow(0));

        removeItemsFromSelection("Item 1");
        Assert.assertEquals("7. Selected: [Item 2]", getLogRow(0));
    }

    @Test
    public void clickToSelect_notReadOnly() {
        selectMenuPath("Component", "State", "Readonly");
        selectMenuPath("Component", "Listeners", "Selection listener");

        selectItem("Item 4");
        assertNothingSelected();

        selectMenuPath("Component", "State", "Readonly");

        selectItem("Item 5");
        Assert.assertEquals("3. Selected: [Item 5]", getLogRow(0));

        selectItem("Item 1");
        Assert.assertEquals("5. Selected: [Item 1]", getLogRow(0));

        addItemsToSelection("Item 2");
        Assert.assertEquals("6. Selected: [Item 1, Item 2]", getLogRow(0));

        removeItemsFromSelection("Item 1");
        Assert.assertEquals("7. Selected: [Item 2]", getLogRow(0));
    }

    @Test
    public void itemCaptionProvider() {
        selectMenuPath("Component", "Item Generator", "Item Caption Generator",
                "Custom Caption Generator");
        assertItems(20, " Caption");
    }
{'fraction_non_alphanumeric': 0.13356782106782106, 'fraction_numerical': 0.01893939393939394, 'mean_word_length': 2.8963457484188333, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1568836', 'n_tokens_mistral': 3160, 'n_tokens_neox': 2926, 'n_words': 651}