<commit_before>package com.ekino.lesaint.dozerannihilation.processor.impl;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.testng.annotations.Test;

import javax.lang.model.element.Modifier;

import static com.ekino.lesaint.dozerannihilation.processor.impl.AbstractFileGenerator.INDENT;
import static com.ekino.lesaint.dozerannihilation.processor.impl.DAWriterTestUtil.LINE_SEPARATOR;
import static com.ekino.lesaint.dozerannihilation.processor.impl.DAWriterTestUtil.daParameter;
import static com.ekino.lesaint.dozerannihilation.processor.impl.DAWriterTestUtil.daType;
import static org.assertj.core.api.Assertions.assertThat;

/**
 * DAMethodWriterTest -
 *
 * TODO compléter les tests unitaires DAMethodWriter
 * <ul>
 *     <li>tester plusieurs arguments</li>
 *     <li>tester arguments avec génériques</li>
 *     <li>tester arguments tableau</li>
 *     <li>tester combinaison modifier + arguments</li>
 *     <li>tester l'objet retourné par end()</li>
 *     <li>tester l'objet retourné par chaque méthode (ie. vérifier le codage de la fluent) ?</li>
 * </ul>
 *
 * @author <NAME>
 */
public class DAMethodWriterTest {
    private static final DAParameter STRING_TOTO_PARAMETER = daParameter("java.lang.String", "toto");

    @Test
    public void empty_method() throws Exception {
        TestWriters testWriters = new TestWriters();
        methodWriter("name", "java.lang.String", testWriters).start().end();

        assertThat(testWriters.getRes())
                .isEqualTo(INDENT + "String name() {" + LINE_SEPARATOR + INDENT + "}" + LINE_SEPARATOR + LINE_SEPARATOR);
    }

    @Test
    public void empty_method_one_parameter() throws Exception {
        TestWriters testWriters = new TestWriters();
        methodWriter("name", "java.lang.String", testWriters)
                .withParams(ImmutableList.of(STRING_TOTO_PARAMETER))
                .start()
                .end();

        assertThat(testWriters.getRes())
                .isEqualTo(INDENT + "String name(String toto) {" + LINE_SEPARATOR + INDENT + "}" + LINE_SEPARATOR + LINE_SEPARATOR);
    }

    @Test
    public void public_static_empty_method() throws Exception {
        TestWriters testWriters = new TestWriters();
        methodWriter("name", "java.lang.String", testWriters)
                .withModifiers(ImmutableSet.of(Modifier.PUBLIC, Modifier.STATIC))
                .start()
                .end();

        assertThat(testWriters.getRes())
                .isEqualTo(INDENT + "public static String name() {" + LINE_SEPARATOR + INDENT + "}" + LINE_SEPARATOR + LINE_SEPARATOR);<commit_msg>added more unit test for DAMethodWriter<commit_after>package com.ekino.lesaint.dozerannihilation.processor.impl;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.testng.annotations.Test;

import javax.lang.model.element.Modifier;
import javax.lang.model.type.TypeKind;

import static com.ekino.lesaint.dozerannihilation.processor.impl.AbstractFileGenerator.INDENT;
import static com.ekino.lesaint.dozerannihilation.processor.impl.DAWriterTestUtil.LINE_SEPARATOR;
import static com.ekino.lesaint.dozerannihilation.processor.impl.DAWriterTestUtil.daParameter;
import static com.ekino.lesaint.dozerannihilation.processor.impl.DAWriterTestUtil.daType;
import static org.assertj.core.api.Assertions.assertThat;

/**
 * DAMethodWriterTest -
 *
 * TODO compléter les tests unitaires DAMethodWriter
 * <ul>
 *     <li>tester l'objet retourné par end()</li>
 *     <li>tester l'objet retourné par chaque méthode (ie. vérifier le codage de la fluent) ?</li>
 * </ul>
 *
 * @author <NAME>
 */
public class DAMethodWriterTest {
    private static final DAParameter STRING_TOTO_PARAMETER = daParameter("java.lang.String", "toto");
    private static final DAParameter STRING_TITI_PARAMETER = daParameter("java.lang.String", "titi");
    private static final DAParameter SUPER_COMPLEXE_PARAMETER = superComplexeParameter("complexeParam");

    /**
     * Un paramètre de type tableau de Function<String, Integer>
     */
    private static DAParameter superComplexeParameter(String name) {
        DAParameter res = new DAParameter();
        res.name = DANameFactory.from(name);
        DAType parameterType = daType("com.google.common.base.Function",
                ImmutableList.of(daType("java.lang.String"), daType("java.lang.Integer")));
        parameterType.kind = TypeKind.ARRAY;
        res.type = parameterType;
        return res;
    }

    @Test
    public void empty_method() throws Exception {
        TestWriters testWriters = new TestWriters();
        methodWriter("name", "java.lang.String", testWriters).start().end();

        assertThat(testWriters.getRes())
                .isEqualTo(INDENT + "String name() {" + LINE_SEPARATOR + INDENT + "}" + LINE_SEPARATOR + LINE_SEPARATOR);
    }

    @Test
    public void public_static_empty_method() throws Exception {
        TestWriters testWriters = new TestWriters();
        methodWriter("name", "java.lang.String", testWriters)
                .withModifiers(ImmutableSet.of(Modifier.PUBLIC, Modifier.STATIC))
                .start()
                .end();

        assertThat(testWriters.getRes())
                .isEqualTo(INDENT + "public static String name() {" + LINE_SEPARATOR + INDENT + "}" + LINE_SEPARATOR + LINE_SEPARATOR);
    }

    @Test
    public void empty_method_one_parameter() throws Exception {
        TestWriters testWriters = new TestWriters();
        methodWriter("name", "java.lang.String", testWriters)
                .withParams(ImmutableList.of(STRING_TOTO_PARAMETER))
                .start()
                .end();

        assertThat(testWriters.getRes())
                .isEqualTo(INDENT + "String name(String toto) {" + LINE_SEPARATOR + INDENT + "}" + LINE_SEPARATOR + LINE_SEPARATOR);
    }

    @Test
    public void empty_method_two_parameters() throws Exception {
        TestWriters testWriters = new TestWriters();
        methodWriter("name", "java.lang.String", testWriters)
                .withParams(ImmutableList.of(STRING_TITI_PARAMETER, SUPER_COMPLEXE_PARAMETER))
                .start()
                .end();

        assertThat(testWriters.getRes())
                .isEqualTo(INDENT + "String name(String titi, Function<String, Integer>[] complexeParam) {" + LINE_SEPARATOR + INDENT + "}" + LINE_SEPARATOR + LINE_SEPARATOR);
    }

    @Test
    public void public_static_empty_method_with_parameter() throws Exception {
        TestWriters testWriters = new TestWriters();
        methodWriter("name", "java.lang.String", testWriters)
                .withModifiers(ImmutableSet.of(Modifier.PUBLIC, Modifier.STATIC))
                .withParams(ImmutableList.of(SUPER_COMPLEXE_PARAMETER))
                .start()
                .end();

        assertThat(testWriters.getRes())
                .isEqualTo(INDENT + "public static String name(Function<String, Integer>[] complexeParam) {" + LINE_SEPARATOR + INDENT + "}" + LINE_SEPARATOR + LINE_SEPARATOR);
    }

    @Test
    public void end_returns_parent_writer() throws Exception {
        TestWriters testWriters = new TestWriters();
        DAWriter parent = new DAWriter() {

        };
        DAMethodWriter<DAWriter> classWriter = new DAMethodWriter<DAWriter>("name", daType("java.lang.String"), testWriters.bw, 1, parent);

        assertThat(classWriter.end()).isSameAs(parent);
{'fraction_non_alphanumeric': 0.11262890049551359, 'fraction_numerical': 0.00013392259274139549, 'mean_word_length': 3.3117782909930717, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, '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': '1572117', 'n_tokens_mistral': 2302, 'n_tokens_neox': 2246, 'n_words': 421}