package com.datastax.driver.mapping;

import java.util.Collection;

import com.google.common.collect.Lists;
import org.testng.annotations.Test;

import static org.assertj.core.api.Assertions.assertThat;

import com.datastax.driver.core.CCMBridge;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.mapping.annotations.Accessor;
import com.datastax.driver.mapping.annotations.Query;

public class MapperAccessorTest extends CCMBridge.PerClassSingleNodeCluster {

    @Override protected Collection<String> getTableDefinitions() {
        return Lists.newArrayList("CREATE TABLE foo (i int primary key)");
    }

    @Test(groups = "short")
    public void should_implement_toString() {
        SystemAccessor accessor = new MappingManager(session)
            .createAccessor(SystemAccessor.class);

        assertThat(accessor.toString())
            .isEqualTo("SystemAccessor implementation generated by the Cassandra driver mapper");
    }

    @Test(groups = "short")
    public void should_implement_equals_and_hashCode() {
        SystemAccessor accessor = new MappingManager(session)
            .createAccessor(SystemAccessor.class);

        assertThat(accessor).isNotEqualTo(new Object());
        assertThat(accessor.hashCode()).isEqualTo(System.identityHashCode(accessor));
    }

    @Accessor
    public interface SystemAccessor {
        @Query("select release_version from system.local")
        ResultSet getCassandraVersion();
    }
}

@@ -314,36 +314,127 @@
 ver.
-mapping.annotations.Accessor
+core.Row;%0Aimport com.datastax.driver.mapping.annotations.Accessor;%0Aimport com.datastax.driver.mapping.annotations.Param
 ;%0Aim
@@ -578,16 +578,20 @@
 Override
+%0A   
  protect
@@ -689,17 +689,17 @@
 LE foo (
-i
+k
  int pri
@@ -706,16 +706,24 @@
 mary key
+, v text
 )%22);%0A   
@@ -1417,152 +1417,693 @@
    @
-Accessor%0A    public interface SystemAccessor %7B%0A        @Query(%22select release_version from system.local%22)%0A        ResultSet getCassandraVersion(
+Test(groups = %22short%22)%0A    public void should_allow_null_parameter_in_accessor() %7B%0A        FooAccessor accessor = new MappingManager(session)%0A            .createAccessor(FooAccessor.class);%0A%0A        accessor.insert(1, null);%0A        Row row = session.execute(%22select * from foo where k = 1%22).one();%0A%0A        assertThat(row.getString(%22v%22)).isNull();%0A    %7D%0A%0A    @Accessor%0A    public interface SystemAccessor %7B%0A        @Query(%22select release_version from system.local%22)%0A        ResultSet getCassandraVersion();%0A    %7D%0A%0A    @Accessor%0A    public interface FooAccessor %7B%0A        @Query(%22insert into foo (k, v) values (:k, :v)%22)%0A        ResultSet insert(@Param(%22k%22) int k, @Param(%22v%22) String v
 );%0A 

Add test for null param in accessor method (JAVA-575).