<commit_before>package org.seleniumhq.selenium;

import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.InOrder;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.seleniumhq.selenium.fluent.FluentBase;
import org.seleniumhq.selenium.fluent.FluentWebDriverImpl;
import org.seleniumhq.selenium.fluent.OngoingFluentWebDriver;

import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

/**
 * Unit test for simple App.
 */
public class FluentWebDriverTest {

    static final By ID_A = By.id("idA");
    static final By ID_B = By.id("idB");
    private StringBuilder sb = new StringBuilder();
    private WebDriver wd = new WebDriverJournal(sb);
    private FluentWebDriverImpl fwd = new FluentWebDriverImpl(wd);

    private static final WebElement bogusElem = mock(WebElement.class);

    static {
        when(bogusElem.getTagName()).thenReturn("bogus");
    }

    @Test
    public void testBasicWithMockito() {
        WebDriver wd = mock(WebDriver.class);
        WebElement we = mock(WebElement.class);
        WebElement we2 = mock(WebElement.class);

        FluentWebDriverImpl fwd = new FluentWebDriverImpl(wd);

        when(wd.findElement(ID_A)).thenReturn(we);
        when(we.findElement(ID_B)).thenReturn(we2);
        when(we.getTagName()).thenReturn("div");
        when(we2.getTagName()).thenReturn("div");

        FluentBase fb = fwd.div(ID_A).div(ID_B);

        assertThat(fb, notNullValue());

        InOrder io = inOrder(we, wd, we2);
        io.verify(wd).findElement(ID_A);
        io.verify(we).getTagName();
        io.verify(we).findElement(ID_B);
        io.verify(we2).getTagName();
        verifyNoMoreInteractions(wd, we, we2);
    }

    @Test
    public void someSimpleCasesInvolvingIDs() {

        FluentBase fb = fwd.div(ID_A).div(ID_B).span().click();

        assertThat(fb, notNullValue());
        assertThat(sb.toString(), equalTo(
                "wd0.findElement(By.id: idA) -> we1\n" +<commit_msg>test method renames<commit_after>package org.seleniumhq.selenium;

import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.mockito.InOrder;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.seleniumhq.selenium.fluent.FluentBase;
import org.seleniumhq.selenium.fluent.FluentWebDriverImpl;
import org.seleniumhq.selenium.fluent.OngoingFluentWebDriver;

import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

/**
 * Unit test for simple App.
 */
public class FluentWebDriverTest {

    static final By ID_A = By.id("idA");
    static final By ID_B = By.id("idB");
    private StringBuilder sb = new StringBuilder();
    private WebDriver wd = new WebDriverJournal(sb);
    private FluentWebDriverImpl fwd = new FluentWebDriverImpl(wd);

    private static final WebElement bogusElem = mock(WebElement.class);

    static {
        when(bogusElem.getTagName()).thenReturn("bogus");
    }

    @Test
    public void reference_test_with_mockito() {
        WebDriver wd = mock(WebDriver.class);
        WebElement we = mock(WebElement.class);
        WebElement we2 = mock(WebElement.class);

        FluentWebDriverImpl fwd = new FluentWebDriverImpl(wd);

        when(wd.findElement(ID_A)).thenReturn(we);
        when(we.findElement(ID_B)).thenReturn(we2);
        when(we.getTagName()).thenReturn("div");
        when(we2.getTagName()).thenReturn("div");

        FluentBase fb = fwd.div(ID_A).div(ID_B);

        assertThat(fb, notNullValue());

        InOrder io = inOrder(we, wd, we2);
        io.verify(wd).findElement(ID_A);
        io.verify(we).getTagName();
        io.verify(we).findElement(ID_B);
        io.verify(we2).getTagName();
        verifyNoMoreInteractions(wd, we, we2);
    }

    @Test
    public void example_of_longer_query_using_IDs() {

        FluentBase fb = fwd.div(ID_A).div(ID_B).span().click();

        assertThat(fb, notNullValue());
        assertThat(sb.toString(), equalTo(
                "wd0.findElement(By.id: idA) -> we1\n" +
{'fraction_non_alphanumeric': 0.12050109365679061, 'fraction_numerical': 0.0031815470272419963, 'mean_word_length': 3.804202483285578, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4370434', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1648, 'n_words': 300}