package kr.co.zumo.app.lifeplus.model;

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

import static junit.framework.Assert.assertEquals;
import static org.powermock.api.mockito.PowerMockito.mock;

public class SuperModelTest {
  BaseSharedPreferences baseSharedPreferences;
  LifeplusPreferences lifeplusPreferences;

  @Before
  public void setup() {
    baseSharedPreferences = mock(BaseSharedPreferences.class);
    lifeplusPreferences = new LifeplusPreferences(baseSharedPreferences);

    SuperModel.getInstance().init(lifeplusPreferences);
  }

  @Test
  public void getPreferences() {
    assertEquals(lifeplusPreferences, SuperModel.getInstance().getPreferences());
  }

  @Test
  public void memberStatus() {
    SuperModel.getInstance().setUserId("dummy");
    SuperModel.getInstance().setToken("__dummy_token__");

    assertEquals(0b00, SuperModel.getInstance().getMemberStatus());
    assertEquals(true, SuperModel.getInstance().isActiveMember());
    assertEquals(false, SuperModel.getInstance().isBlockMember());
    assertEquals(false, SuperModel.getInstance().isRestMember());

    SuperModel.getInstance().addMemberStatus(SuperModel.MEMBER_STATUS_BIT_BLOCK);
    assertEquals(0b01, SuperModel.getInstance().getMemberStatus());
    assertEquals(false, SuperModel.getInstance().isActiveMember());
    assertEquals(true, SuperModel.getInstance().isBlockMember());
    assertEquals(false, SuperModel.getInstance().isRestMember());

    SuperModel.getInstance().addMemberStatus(SuperModel.MEMBER_STATUS_BIT_REST);
    assertEquals(0b11, SuperModel.getInstance().getMemberStatus());
    assertEquals(false, SuperModel.getInstance().isActiveMember());
    assertEquals(true, SuperModel.getInstance().isBlockMember());
    assertEquals(true, SuperModel.getInstance().isRestMember());

    SuperModel.getInstance().deleteMemberStatus(SuperModel.MEMBER_STATUS_BIT_BLOCK);
    assertEquals(0b10, SuperModel.getInstance().getMemberStatus());
    assertEquals(false, SuperModel.getInstance().isActiveMember());
    assertEquals(false, SuperModel.getInstance().isBlockMember());
    assertEquals(true, SuperModel.getInstance().isRestMember());

    SuperModel.getInstance().deleteMemberStatus(SuperModel.MEMBER_STATUS_BIT_REST);
    assertEquals(0b00, SuperModel.getInstance().getMemberStatus());
    assertEquals(true, SuperModel.getInstance().isActiveMember());
    assertEquals(false, SuperModel.getInstance().isBlockMember());
    assertEquals(false, SuperModel.getInstance().isRestMember());
  }
}