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

import org.junit.Test;

import java.security.NoSuchAlgorithmException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

//@RunWith(RobolectricTestRunner.class)
public class StringUtilTest {

  @Test
  public void isFull() {
    assertTrue(StringUtil.isFull("a"));
    assertTrue(StringUtil.isFull("b"));
    assertFalse(StringUtil.isFull(""));
    assertFalse(StringUtil.isFull(null));
  }

  @Test
  public void isValidEmail() {
    assertFalse(StringUtil.isValidEmail(null));
    assertFalse(StringUtil.isValidEmail(""));
    assertFalse(StringUtil.isValidEmail("a"));
    assertFalse(StringUtil.isValidEmail("a@a"));
    assertFalse(StringUtil.isValidEmail("@a.com"));
    assertFalse(StringUtil.isValidEmail("a@.com"));
    assertTrue(StringUtil.isValidEmail("a@com.com.com"));
    assertTrue(StringUtil.isValidEmail("a@a.com"));
  }

  @Test
  public void isValidPassword() {
    assertFalse(StringUtil.isValidPassword("")); // 공백
    assertFalse(StringUtil.isValidPassword(null)); // null
    assertFalse(StringUtil.isValidPassword("werT12349")); // 특수 문자 없음
    assertFalse(StringUtil.isValidPassword("12345678asdf@")); // 대문자 없음
    assertFalse(StringUtil.isValidPassword("QRXCV#$1234")); // 소문자 없음
    assertFalse(StringUtil.isValidPassword("ZCVSwer@#%")); // 숫자 없음
    assertTrue(StringUtil.isValidPassword("q12`346&*ZXC")); // correct
    assertTrue(StringUtil.isValidPassword("q12`-=~!@#$%^&*()_+C")); // correct
  }

  @Test
  public void convertToMD5() {
    try {
      assertEquals("1bc29b36f623ba82aaf6724fd3b16718", StringUtil.convertToMD5("md5"));
      assertEquals("c617ea9609ec341360765f6d29b5814e", StringUtil.convertToMD5("9238"));
      assertEquals("7cf64379eb6f29a4d25c4b6a2df713e4", StringUtil.convertToMD5("2456"));
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }

  }

  @Test
  public void convertToSHA256() {
    try {
      assertEquals("b3abe5d8c69b38733ad57ea75e83bcae42bbbbac75e3a5445862ed2f8a2cd677", StringUtil.convertToSHA256("SHA256"));
      assertEquals("b1d705bf58a21fff38bfff26ec5e7d368a15694cf506d0c5a852a3629169fdd0", StringUtil.convertToSHA256("9238"));
      assertEquals("c0d427f8b875401198831f31edb981bf951a3b77f5ec5f336ad84a50ed831ac9", StringUtil.convertToSHA256("2456"));
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }
  }

  @Test
  public void removeProtocol() {
    assertEquals("192.168.0.10", StringUtil.removeProtocol("http://192.168.0.10"));
    assertEquals("192.168.0.10", StringUtil.removeProtocol("https://192.168.0.10"));
    assertEquals("google.com/afasf.sdfksdfa", StringUtil.removeProtocol("https://google.com/afasf.sdfksdfa"));
    assertEquals("google.com/afasf.sdfksdfa", StringUtil.removeProtocol("http://google.com/afasf.sdfksdfa"));
  }
}