package com.capgemini.framework.common;

import org.testng.annotations.Test;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

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

public class DateHelperTest {
  private static final String PATTERN_YEAR_DASH_MONTH = "^[\\d]{4}-[\\d]{2}$"; // 4 digits, followed by a dash ('-'), followed by two difits, end of String.
  private static final String DATE_USER_INPUT = "08-12-2014";
  private static final String EXPECTED_DATE_OUTPUT_US = "08-Dec-2014";
  private static final String DATE_USER_INPUT_EMPTY = "";
  private static final String EXPECTED_DATE_TODAY = "[\\d]{2}-[\\d]{2}-[\\d]{4}"; //25-01-2016

  @Test
  public void testMakeTeamcenterCalendar() {
    assertThat(TeamcenterDateFormatter.makeTeamcenterCalendar(DATE_USER_INPUT)).isNotNull();
    assertThat(TeamcenterDateFormatter.makeTeamcenterCalendar(DATE_USER_INPUT_EMPTY)).isNotNull();
  }

  @Test
  public void testMakeDateFormatForRequest() {
    assertThat(TeamcenterDateFormatter.translateDateFormatForRequest(DATE_USER_INPUT)).isEqualTo(EXPECTED_DATE_OUTPUT_US);
    assertThat(TeamcenterDateFormatter.translateDateFormatForRequest(DATE_USER_INPUT_EMPTY)).isEqualTo(getCurrentDate());
  }

  @Test
  public void testGetMonthPeriod() {
    assertThat(DateHelper.getMonthPeriod()).matches(PATTERN_YEAR_DASH_MONTH);
  }

  @Test
  public void testGetDate() {
    assertThat(DateHelper.getDate()).matches(EXPECTED_DATE_TODAY);
  }

  private String getCurrentDate() {
    return new SimpleDateFormat("dd-MMM-yyyy", Locale.US).format(Calendar.getInstance().getTime());
  }
}
