<commit_before>package org.vaadin.teemu.clara;

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

import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Date;

import org.junit.Before;
import org.junit.Test;
import org.vaadin.teemu.clara.binder.Binder;
import org.vaadin.teemu.clara.binder.BinderException;
import org.vaadin.teemu.clara.binder.annotation.DataSource;
import org.vaadin.teemu.clara.binder.annotation.EventHandler;
import org.vaadin.teemu.clara.inflater.LayoutInflater;

import com.vaadin.data.Property;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.DateField;

public class BinderTest {

    private LayoutInflater inflater;

    @Before
    public void setUp() {
        inflater = new LayoutInflater();
    }

    private InputStream getXml(String fileName) {
        return getClass().getClassLoader().getResourceAsStream(fileName);
    }

    @Test
    public void bind_clickListener_clickListenerInvoked() {
        Button button = (Button) inflater.inflate(getXml("single-button.xml"));

        ControllerWithClickHandler controller = new ControllerWithClickHandler();
        Binder binder = new Binder();
        binder.bind(button, controller);

        simulateButtonClick(button);

        // check that the handler was called
        assertTrue("Annotated handler method was not called.",
                controller.clickCalled);
    }

    @Test
    public void bind_dataSource_dataSourceAttached() {
        DateField view = (DateField) inflater
                .inflate(getXml("single-datefield.xml"));

        Binder binder = new Binder();
        binder.bind(view, new ControllerWithDataSource());

        Date value = (Date) view.getValue();
        assertEquals(1337337477578L, value.getTime());
    }

    @Test(expected = BinderException.class)
    public void bind_nonExistingId_exceptionThrown() {
        Button button = (Button) inflater.inflate(getXml("single-button.xml"));

        Binder binder = new Binder();
        binder.bind(button, new ControllerWithMissingIdBinding());
    }

    @Test(expected = BinderException.class)
    public void bind_nonEventParameter_exceptionThrown() {
        Button button = (Button) inflater.inflate(getXml("single-button.xml"));

        Binder binder = new Binder();
        binder.bind(button, new ControllerWithNonEventHandler());
    }

    private void simulateButtonClick(Button button) {
        Method fireClick;
        try {
            fireClick = Button.class.getDeclaredMethod("fireClick");
            fireClick.setAccessible(true);
            fireClick.invoke(button);
        } catch (Exception e) {
            throw new RuntimeException("Couldn't simulate button click.", e);
        }
    }

    public static class ControllerWithMissingIdBinding {

        @EventHandler("non-existing-id")
        public void handleButtonClick(ClickEvent event) {
            // NOP
        }

    }

    public static class ControllerWithDataSource {

        @DataSource("my-datefield")
        public Property getDataSource() {
            Date date = new Date(1337337477578L);
            return new com.vaadin.data.util.ObjectProperty<Date>(date);
        }

    }

    public static class ControllerWithClickHandler {

        boolean clickCalled;

        @EventHandler("my-button")
        public void handleButtonClick(ClickEvent event) {
            clickCalled = true;
        }

    }

    public static class ControllerWithNonEventHandler {

        @EventHandler("my-button")
        public void handleButtonClick(String nonEvent) {
            // NOP
        }

    }

}<commit_msg>Removed failing test for a feature that was removed. <commit_after>package org.vaadin.teemu.clara;

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

import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Date;

import org.junit.Before;
import org.junit.Test;
import org.vaadin.teemu.clara.binder.Binder;
import org.vaadin.teemu.clara.binder.BinderException;
import org.vaadin.teemu.clara.binder.annotation.DataSource;
import org.vaadin.teemu.clara.binder.annotation.EventHandler;
import org.vaadin.teemu.clara.inflater.LayoutInflater;

import com.vaadin.data.Property;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.DateField;

public class BinderTest {

    private LayoutInflater inflater;

    @Before
    public void setUp() {
        inflater = new LayoutInflater();
    }

    private InputStream getXml(String fileName) {
        return getClass().getClassLoader().getResourceAsStream(fileName);
    }

    @Test
    public void bind_clickListener_clickListenerInvoked() {
        Button button = (Button) inflater.inflate(getXml("single-button.xml"));

        ControllerWithClickHandler controller = new ControllerWithClickHandler();
        Binder binder = new Binder();
        binder.bind(button, controller);

        simulateButtonClick(button);

        // check that the handler was called
        assertTrue("Annotated handler method was not called.",
                controller.clickCalled);
    }

    @Test
    public void bind_dataSource_dataSourceAttached() {
        DateField view = (DateField) inflater
                .inflate(getXml("single-datefield.xml"));

        Binder binder = new Binder();
        binder.bind(view, new ControllerWithDataSource());

        Date value = (Date) view.getValue();
        assertEquals(1337337477578L, value.getTime());
    }

    @Test(expected = BinderException.class)
    public void bind_nonExistingId_exceptionThrown() {
        Button button = (Button) inflater.inflate(getXml("single-button.xml"));

        Binder binder = new Binder();
        binder.bind(button, new ControllerWithMissingIdBinding());
    }

    private void simulateButtonClick(Button button) {
        Method fireClick;
        try {
            fireClick = Button.class.getDeclaredMethod("fireClick");
            fireClick.setAccessible(true);
            fireClick.invoke(button);
        } catch (Exception e) {
            throw new RuntimeException("Couldn't simulate button click.", e);
        }
    }

    public static class ControllerWithMissingIdBinding {

        @EventHandler("non-existing-id")
        public void handleButtonClick(ClickEvent event) {
            // NOP
        }

    }

    public static class ControllerWithDataSource {

        @DataSource("my-datefield")
        public Property getDataSource() {
            Date date = new Date(1337337477578L);
            return new com.vaadin.data.util.ObjectProperty<Date>(date);
        }

    }

    public static class ControllerWithClickHandler {

        boolean clickCalled;

        @EventHandler("my-button")
        public void handleButtonClick(ClickEvent event) {
            clickCalled = true;
        }

    }

}
{'fraction_non_alphanumeric': 0.09759608464085216, 'fraction_numerical': 0.0074852454296818775, 'mean_word_length': 2.898989898989899, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, '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': '4624649', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1888, 'n_words': 403}