package net.zerobuilder.modules.generics;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;
import org.junit.Test;

import java.util.List;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;
import static net.zerobuilder.compiler.generate.ZeroUtil.downcase;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class GenericsImplTest {

  @Test
  public void invoke3() {
    List<TypeSpec> typeSpecs = Stream.of("Source", "Key", "DefaultValue")
        .map(this::typeSpec)
        .collect(toList());
    CodeBlock block = GenericsImpl.invoke(typeSpecs);
    assertThat(block, is(CodeBlock.builder().add("keyImpl.source, key, defaultValue").build()));
  }

  @Test
  public void invoke4() {
    List<TypeSpec> typeSpecs = Stream.of("Foo", "Source", "Key", "DefaultValue")
        .map(this::typeSpec)
        .collect(toList());
    CodeBlock block = GenericsImpl.invoke(typeSpecs);
    assertThat(block, is(CodeBlock.builder().add("keyImpl.sourceImpl.foo, keyImpl.source, key, defaultValue").build()));
  }

  private TypeSpec typeSpec(String parameter) {
    return TypeSpec.classBuilder(parameter)
        .addMethod(MethodSpec.methodBuilder(downcase(parameter))
            .addParameter(ClassName.get(String.class), downcase(parameter))
            .build())
        .build();
  }
}
@@ -509,16 +509,594 @@
 Test %7B%0A%0A
+  @Test%0A  public void invoke1() %7B%0A    List%3CTypeSpec%3E typeSpecs = Stream.of(%22DefaultValue%22)%0A        .map(this::typeSpec)%0A        .collect(toList());%0A    CodeBlock block = GenericsImpl.invoke(typeSpecs);%0A    assertThat(block, is(CodeBlock.builder().add(%22defaultValue%22).build()));%0A  %7D%0A%0A  @Test%0A  public void invoke2() %7B%0A    List%3CTypeSpec%3E typeSpecs = Stream.of(%22Key%22, %22DefaultValue%22)%0A        .map(this::typeSpec)%0A        .collect(toList());%0A    CodeBlock block = GenericsImpl.invoke(typeSpecs);%0A    assertThat(block, is(CodeBlock.builder().add(%22key, defaultValue%22).build()));%0A  %7D%0A%0A
   @Test%0A

add tests