package io.github.yurloc.autostring;

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

import java.util.ArrayList;
import java.util.List;

import io.github.yurloc.autostring.accessibility.Accessibility;
import org.junit.Before;
import org.junit.Test;

public class FieldAccessibilityTest {

    private CharSequence[] pairs;

    @Before
    public void setUp() {
        List<String> list = new ArrayList<>();
        String[] modifiers = new String[]{"no modifier", "static", "final", "volatile", "transient"};
        String[] accessLevels = new String[]{"Pvt", "Pkg", "Ptd", "Pub"};
        for (String modifier : modifiers) {
            for (String access : accessLevels) {
                String fieldName = modifier.charAt(0) + access;
                list.add(fieldName + "=" + fieldName + ";");
            }
        }
        pairs = new CharSequence[list.size()];
        pairs = list.toArray(pairs);
        assertThat(pairs).hasSize(modifiers.length * accessLevels.length);
    }

    @Test
    public void testFieldAccessModifiers() {
        Accessibility dummy = new Accessibility();
        assertThat(dummy.toString())
                .contains(pairs)
                .doesNotContain("?");
        System.out.println(dummy);
    }
}

@@ -86,24 +86,91 @@
 ssertThat;%0A%0A
+import java.lang.reflect.Field;%0Aimport java.lang.reflect.Modifier;%0A
 import java.
@@ -1319,11 +1319,840 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Demonstrates that field accessibility is not affected by calling%0A     * %7B@link AutoStringBuilder#build(java.lang.Object)%7D.%0A     * More info on %3Ca href=%22http://stackoverflow.com/a/10638983/1691152%22%3EStack Overflow%3C/a%3E.%0A     *%0A     * @throws NoSuchFieldException shouldn't happen%0A     * @throws IllegalArgumentException shouldn't happen%0A     * @throws IllegalAccessException this one is expected%0A     */%0A    @Test(expected = IllegalAccessException.class)%0A    public void testAccesibilityAfterToString() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException %7B%0A        Accessibility dummy = new Accessibility();%0A        dummy.toString();%0A        Field nPvt = dummy.getClass().getDeclaredField(%22nPvt%22);%0A        assertThat(Modifier.isPrivate(nPvt.getModifiers()));%0A        nPvt.get(dummy);%0A    %7D
 %0A%7D%0A

Test demonstrating that accessibility modification is not persistent