// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java
// public interface ComponentGenerator<T> extends Serializable {
// 
//     /**
//      * Called to generate the component for a component cell based
//      * on the passed typed bean.
//      *
//      * @param bean the bean being the source for the current row's data
//      * @return a <b>new</b> instance of the component used to display the data
//      */
//     Component getComponent(T bean);
// }
// 
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java
// public class ComponentGrid<T> extends Grid {
// 
//     private final ComponentGridDecorator<T> componentGridDecorator;
// 
//     public ComponentGrid(Class<T> typeOfRows) {
//         super();
//         setContainerDataSource(new BeanItemContainer<T>(typeOfRows));
//         componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows);
//     }
// 
//     public ComponentGridDecorator<T> getComponentGridDecorator() {
//         return componentGridDecorator;
//     }
// 
//     public FocusPreserveExtension getFocusPreserveExtension() {
//         return componentGridDecorator.getFocusPreserveExtension();
//     }
// 
//     /**
//      * Remove a bean from the grid.
//      *
//      * @return the decorator for method chaining
//      */
//     public ComponentGrid<T> remove(T bean) {
//         componentGridDecorator.remove(bean);
//         return this;
//     }
// 
//     /**
//      * Add a bean to the grid.
//      *
//      * @return the decorator for method chaining
//      */
//     public ComponentGrid<T>  add(T bean) {
//         componentGridDecorator.add(bean);
//         return this;
//     }
// 
//     /**
//      * Add all beans to the decorated grid's container.
//      *
//      * @param beans a collection of beans
//      * @return the grid for method chaining
//      */
//     public ComponentGrid<T> addAll(Collection<T> beans) {
//         componentGridDecorator.addAll(beans);
//         return this;
//     }
// 
//     /**
//      * Add a generated component column to the ComponentGrid.
//      *
//      * @param propertyId the generated column's property-id
//      * @param generator  the component-generator
//      * @return the grid for method chaining
//      */
//     public Grid.Column  addComponentColumn(Object propertyId, ComponentGenerator<T> generator) {
//         return componentGridDecorator.addComponentColumn(propertyId, generator);
//     }
// 
//     /**
//      * Refreshes the grid preserving its current cell focus.
//      */
//     public ComponentGrid<T>  refresh() {
//         componentGridDecorator.refresh();
//         return this;
//     }
// 
//     /**
//      * Remove all items from the underlying {@link BeanItemContainer} and add
//      * the new beans.
//      *
//      * @param beans a collection of beans
//      * @return the grid for method chaining
//      */
//     public ComponentGrid<T>  setRows(Collection<T> beans) {
//         componentGridDecorator.setRows(beans);
//         return this;
//     }
//     /**
//      * Generates component header fields using the passed {@link ComponentHeaderGenerator} and
//      * sets them to the columns.
//      *
//      * @param generator the header generator
//      * @return the grid for method chaining
//      */
//     public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) {
//         componentGridDecorator.generateHeaders(generator);
//         return this;
//     }
// 
//     /**
//      * Generates text header fields using the passed {@link TextHeaderGenerator} and
//      * sets them to the columns.
//      *
//      * @param generator the header generator
//      * @return the grid for method chaining
//      */
//     public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) {
//         componentGridDecorator.generateHeaders(generator);
//         return this;
//     }
// 
//     /**
//      * Generates html header fields using the passed {@link HtmlHeaderGenerator} and
//      * sets them to the columns.
//      *
//      * @param generator the header generator
//      * @return the grid for method chaining
//      */
//     public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) {
//         componentGridDecorator.generateHeaders(generator);
//         return this;
//     }
// }
// 
// Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ExampleBean.java
// public class ExampleBean {
//     String caption;
//     Boolean isSomething;
// 
//     public Boolean getIsSomething() {
//         return isSomething;
//     }
// 
//     public void setIsSomething(Boolean isSomething) {
//         this.isSomething = isSomething;
//     }
// 
//     public String getCaption() {
//         return caption;
//     }
// 
//     public void setCaption(String caption) {
//         this.caption = caption;
//     }
// }


import com.vaadin.ui.Component;
import com.vaadin.v7.ui.Label;
import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator;
import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid;
import de.datenhahn.vaadin.componentrenderer.grid.ExampleBean;
import elemental.json.Json;
import elemental.json.JsonValue;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
package de.datenhahn.vaadin.componentrenderer;



public class ComponentRendererTest {

    @Test
    public void encodeNullComponent() {
        ComponentRenderer renderer = new ComponentRenderer();
        assertThat(renderer.encode(null), equalTo((JsonValue) Json.createNull()));
    }

    @Test(expected = IllegalStateException.class)
    public void encodeComponentWithoutBeingAttached() {
        ComponentRenderer renderer = new ComponentRenderer();
        renderer.encode(new Label("test"));
    }

    /**
     * Issue #18:  Removing a column with ComponentRenderer caused an exception #18
     *
     * https://github.com/datenhahn/componentrenderer/issues/18
     */
    @Test
    public void issue18ExceptionWhenRemovingColumn() {
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGenerator.java
// public interface ComponentGenerator<T> extends Serializable {
// 
//     /**
//      * Called to generate the component for a component cell based
//      * on the passed typed bean.
//      *
//      * @param bean the bean being the source for the current row's data
//      * @return a <b>new</b> instance of the component used to display the data
//      */
//     Component getComponent(T bean);
// }
// 
// Path: componentrenderer/src/main/java/de/datenhahn/vaadin/componentrenderer/grid/ComponentGrid.java
// public class ComponentGrid<T> extends Grid {
// 
//     private final ComponentGridDecorator<T> componentGridDecorator;
// 
//     public ComponentGrid(Class<T> typeOfRows) {
//         super();
//         setContainerDataSource(new BeanItemContainer<T>(typeOfRows));
//         componentGridDecorator = new ComponentGridDecorator<T>(this, typeOfRows);
//     }
// 
//     public ComponentGridDecorator<T> getComponentGridDecorator() {
//         return componentGridDecorator;
//     }
// 
//     public FocusPreserveExtension getFocusPreserveExtension() {
//         return componentGridDecorator.getFocusPreserveExtension();
//     }
// 
//     /**
//      * Remove a bean from the grid.
//      *
//      * @return the decorator for method chaining
//      */
//     public ComponentGrid<T> remove(T bean) {
//         componentGridDecorator.remove(bean);
//         return this;
//     }
// 
//     /**
//      * Add a bean to the grid.
//      *
//      * @return the decorator for method chaining
//      */
//     public ComponentGrid<T>  add(T bean) {
//         componentGridDecorator.add(bean);
//         return this;
//     }
// 
//     /**
//      * Add all beans to the decorated grid's container.
//      *
//      * @param beans a collection of beans
//      * @return the grid for method chaining
//      */
//     public ComponentGrid<T> addAll(Collection<T> beans) {
//         componentGridDecorator.addAll(beans);
//         return this;
//     }
// 
//     /**
//      * Add a generated component column to the ComponentGrid.
//      *
//      * @param propertyId the generated column's property-id
//      * @param generator  the component-generator
//      * @return the grid for method chaining
//      */
//     public Grid.Column  addComponentColumn(Object propertyId, ComponentGenerator<T> generator) {
//         return componentGridDecorator.addComponentColumn(propertyId, generator);
//     }
// 
//     /**
//      * Refreshes the grid preserving its current cell focus.
//      */
//     public ComponentGrid<T>  refresh() {
//         componentGridDecorator.refresh();
//         return this;
//     }
// 
//     /**
//      * Remove all items from the underlying {@link BeanItemContainer} and add
//      * the new beans.
//      *
//      * @param beans a collection of beans
//      * @return the grid for method chaining
//      */
//     public ComponentGrid<T>  setRows(Collection<T> beans) {
//         componentGridDecorator.setRows(beans);
//         return this;
//     }
//     /**
//      * Generates component header fields using the passed {@link ComponentHeaderGenerator} and
//      * sets them to the columns.
//      *
//      * @param generator the header generator
//      * @return the grid for method chaining
//      */
//     public ComponentGrid<T> generateHeaders(ComponentHeaderGenerator generator) {
//         componentGridDecorator.generateHeaders(generator);
//         return this;
//     }
// 
//     /**
//      * Generates text header fields using the passed {@link TextHeaderGenerator} and
//      * sets them to the columns.
//      *
//      * @param generator the header generator
//      * @return the grid for method chaining
//      */
//     public ComponentGrid<T> generateHeaders(TextHeaderGenerator generator) {
//         componentGridDecorator.generateHeaders(generator);
//         return this;
//     }
// 
//     /**
//      * Generates html header fields using the passed {@link HtmlHeaderGenerator} and
//      * sets them to the columns.
//      *
//      * @param generator the header generator
//      * @return the grid for method chaining
//      */
//     public ComponentGrid<T> generateHeaders(HtmlHeaderGenerator generator) {
//         componentGridDecorator.generateHeaders(generator);
//         return this;
//     }
// }
// 
// Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/grid/ExampleBean.java
// public class ExampleBean {
//     String caption;
//     Boolean isSomething;
// 
//     public Boolean getIsSomething() {
//         return isSomething;
//     }
// 
//     public void setIsSomething(Boolean isSomething) {
//         this.isSomething = isSomething;
//     }
// 
//     public String getCaption() {
//         return caption;
//     }
// 
//     public void setCaption(String caption) {
//         this.caption = caption;
//     }
// }


// Path: componentrenderer/src/test/java/de/datenhahn/vaadin/componentrenderer/ComponentRendererTest.java
import com.vaadin.ui.Component;
import com.vaadin.v7.ui.Label;
import de.datenhahn.vaadin.componentrenderer.grid.ComponentGenerator;
import de.datenhahn.vaadin.componentrenderer.grid.ComponentGrid;
import de.datenhahn.vaadin.componentrenderer.grid.ExampleBean;
import elemental.json.Json;
import elemental.json.JsonValue;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;

package de.datenhahn.vaadin.componentrenderer;



public class ComponentRendererTest {

    @Test
    public void encodeNullComponent() {
        ComponentRenderer renderer = new ComponentRenderer();
        assertThat(renderer.encode(null), equalTo((JsonValue) Json.createNull()));
    }

    @Test(expected = IllegalStateException.class)
    public void encodeComponentWithoutBeingAttached() {
        ComponentRenderer renderer = new ComponentRenderer();
        renderer.encode(new Label("test"));
    }

    /**
     * Issue #18:  Removing a column with ComponentRenderer caused an exception #18
     *
     * https://github.com/datenhahn/componentrenderer/issues/18
     */
    @Test
    public void issue18ExceptionWhenRemovingColumn() {
        ComponentGrid<ExampleBean> grid = new ComponentGrid<>(ExampleBean.class);