package com.enactor.pos;

import static org.testng.Assert.assertEquals;

import java.util.Arrays;
import java.util.List;

import org.testng.annotations.Test;

import com.enactor.core.TestGroups;

/**
 * 
 * @author charith.gunathilaka
 *
 */
@Test(groups = { TestGroups.CONTINUOUS })
public class PosUtilityTest {
	
	private static final String WITHOUT_CURRENCY_SYMBOL = "100.00";
	private static final String WITHOUT_WHITESPACES = "Together";
	private static final String WITH_POUND_SIGN = "£100.00";
	private static final String WITH_SPACE = "1st of January";
	private static final List<String> NEW_LIST = Arrays.asList("one", "two", "three");
	
	
	public void testRemoveCurrencySymbol() throws Exception {
		//Remove only $ and £ currency symbols
		assertEquals(PosUtility.removeCurrency("100.00"), WITHOUT_CURRENCY_SYMBOL);
		assertEquals(PosUtility.removeCurrency("$100.00"), WITHOUT_CURRENCY_SYMBOL);
		assertEquals(PosUtility.removeCurrency("100.00$"), WITHOUT_CURRENCY_SYMBOL);
		assertEquals(PosUtility.removeCurrency("£100.00"), WITHOUT_CURRENCY_SYMBOL);
		assertEquals(PosUtility.removeCurrency("100.00£"), WITHOUT_CURRENCY_SYMBOL);		
	}
	
	public void testRremoveWhitespaces() throws Exception {
		//Remove HTML whitespace codes
		assertEquals(PosUtility.removeWhitespaces("To&#160;gether"), WITHOUT_WHITESPACES);
		assertEquals(PosUtility.removeWhitespaces("To&nbsp;gether"), WITHOUT_WHITESPACES);
		assertEquals(PosUtility.removeWhitespaces("Together"), WITHOUT_WHITESPACES);	
	}
	
	public void testReplaceSpecialCharacters() throws Exception {
		//replace HTML special characters
		assertEquals(PosUtility.replaceSpecialCharacters("&#163;100.00"), WITH_POUND_SIGN);
		assertEquals(PosUtility.replaceSpecialCharacters("1st&#160;of&#160;January"), WITH_SPACE);
	}
	
	public void testSplitString() throws Exception {
		//Split string by given delimiter
		assertEquals(PosUtility.splitString("one,two,three", ","), NEW_LIST);
		assertEquals(PosUtility.splitString("one-two-three", "-"), NEW_LIST);
	}

}
