<commit_before>package org.codingmatters.value.objects;

import org.codingmatters.tests.compile.CompiledCode;
import org.codingmatters.value.objects.spec.Spec;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import static org.codingmatters.tests.reflect.ReflectMatchers.*;
import static org.codingmatters.value.objects.spec.Spec.spec;
import static org.codingmatters.value.objects.spec.ValueSpec.valueSpec;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

/**
 * Created by nelt on 9/13/16.
 */
@SuppressWarnings("unchecked")
public class ValueSpecGenerationTest {

    @Rule
    public TemporaryFolder dir = new TemporaryFolder();

    private final Spec spec  = spec()
            .addValue(
                    valueSpec().name("val")
            )
            .addValue(
                    valueSpec().name("val2")
            )
            .build();
    private CompiledCode compiled;

    @Before
    public void setUp() throws Exception {
        new SpecCodeGenerator(this.spec, "org.generated").generateTo(dir.getRoot());
        this.compiled = CompiledCode.compile(this.dir.getRoot());
    }

    @Test
    public void twoValueSpec_twoInterfacesTwoBuilderTwoImpl() throws Exception {
        assertThat(compiled.getClass("org.generated.Val"), is(anInterface()));
        assertThat(compiled.getClass("org.generated.Val$Builder"), is(aClass()));
        assertThat(compiled.getClass("org.generated.ValImpl"), is(aClass()));

        assertThat(compiled.getClass("org.generated.Val2"), is(anInterface()));
        assertThat(compiled.getClass("org.generated.Val2$Builder"), is(aClass()));
        assertThat(compiled.getClass("org.generated.Val2Impl"), is(aClass()));

    }

    @Test
    public void valueInterface() throws Exception {
        assertThat(compiled.getClass("org.generated.Val"), is(anInterface().public_()));
    }

    @Test
    public void valueBuilder() throws Exception {
        assertThat(compiled.getClass("org.generated.Val$Builder"), is(
                aClass().public_().static_()
                    .with(aStaticMethod().named("builder")
                            .public_()
                            .withParameters()
                            .returning(compiled.getClass("org.generated.Val$Builder"))
                    )
                    .with(anInstanceMethod().named("build")
                            .public_()
                            .withParameters()
                            .returning(compiled.getClass("org.generated.Val"))
                    )
        ));
    }

    @Test
    public void valueBuilder_builder_returnsABuilder() throws Exception {
        Object builder = compiled.getClass("org.generated.Val$Builder")
                .getMethod("builder")
                .invoke(null);
<commit_msg>[value-object] test for multiple value in same spec<commit_after>package org.codingmatters.value.objects;

import org.codingmatters.tests.compile.CompiledCode;
import org.codingmatters.value.objects.spec.Spec;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import static org.codingmatters.tests.reflect.ReflectMatchers.*;
import static org.codingmatters.value.objects.spec.Spec.spec;
import static org.codingmatters.value.objects.spec.ValueSpec.valueSpec;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

/**
 * Created by nelt on 9/13/16.
 */
@SuppressWarnings("unchecked")
public class ValueSpecGenerationTest {

    @Rule
    public TemporaryFolder dir = new TemporaryFolder();

    private final Spec spec  = spec()
            .addValue(
                    valueSpec().name("val")
            )
            .addValue(
                    valueSpec().name("val2")
            )
            .build();
    private CompiledCode compiled;

    @Before
    public void setUp() throws Exception {
        new SpecCodeGenerator(this.spec, "org.generated").generateTo(dir.getRoot());
        this.compiled = CompiledCode.compile(this.dir.getRoot());
    }

    @Test
    public void twoValueSpec_twoInterfacesTwoBuilderTwoImpl() throws Exception {
        assertThat(compiled.getClass("org.generated.Val"), is(anInterface()));
        assertThat(compiled.getClass("org.generated.Val$Builder"), is(aClass()));
        assertThat(compiled.getClass("org.generated.ValImpl"), is(aClass()));

        assertThat(compiled.getClass("org.generated.Val2"), is(anInterface()));
        assertThat(compiled.getClass("org.generated.Val2$Builder"), is(aClass()));
        assertThat(compiled.getClass("org.generated.Val2Impl"), is(aClass()));
    }

    @Test
    public void valueInterface() throws Exception {
        assertThat(compiled.getClass("org.generated.Val"), is(anInterface().public_()));
    }

    @Test
    public void valueBuilder() throws Exception {
        assertThat(compiled.getClass("org.generated.Val$Builder"), is(
                aClass().public_().static_()
                    .with(aStaticMethod().named("builder")
                            .public_()
                            .withParameters()
                            .returning(compiled.getClass("org.generated.Val$Builder"))
                    )
                    .with(anInstanceMethod().named("build")
                            .public_()
                            .withParameters()
                            .returning(compiled.getClass("org.generated.Val"))
                    )
        ));
    }

    @Test
    public void valueBuilder_builder_returnsABuilder() throws Exception {
        Object builder = compiled.getClass("org.generated.Val$Builder")
                .getMethod("builder")
                .invoke(null);

{'fraction_non_alphanumeric': 0.12387425658453696, 'fraction_numerical': 0.003058623619371283, 'mean_word_length': 2.491103202846975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1225411', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1546, 'n_words': 257}