package com.avg.zaap.crashlibrary.provider.app;

import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Field;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;

/**
 * A test class for {@link ClassFieldHelper}.
 *
 * Created by marek.osvald on 5.5.2016.
 */
public class ClassFieldHelperTests {

    private static final int PUBLIC_FIELD_COUNT = 3;

    private static final String PUBLIC_FIELD_NAME_1 = "PUBLIC_1";
    private static final String PUBLIC_FIELD_NAME_2 = "PUBLIC_2";
    private static final String PUBLIC_FIELD_NAME_3 = "PUBLIC_3";

    private IClassFieldHelper mClassFieldHelper;

    @Before
    public void setUp() throws Exception {
        mClassFieldHelper = new ClassFieldHelper();
    }

    @Test
    public void loadFields_nothing_loadsPublicFields() throws Exception {
        // act
        Field[] result = mClassFieldHelper.loadFields(FieldClass.class);

        // assert
        assertThat(result.length, is(PUBLIC_FIELD_COUNT));
        assertThat(result[0].getName(), is(PUBLIC_FIELD_NAME_1));
        assertThat((String) result[0].get(null), is(FieldClass.PUBLIC_1));
        assertThat(result[1].getName(), is(PUBLIC_FIELD_NAME_2));
        assertThat((String) result[1].get(null), is(FieldClass.PUBLIC_2));
        assertThat(result[2].getName(), is(PUBLIC_FIELD_NAME_3));
        assertThat((String) result[2].get(null), is(FieldClass.PUBLIC_3));
    }

}
