/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.generic;

import net.ranides.assira.junit.NewAssert;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class ValueUtilsTest {
	
	public ValueUtilsTest() {
	}

	@Test
	public void testIsTrue() {
		assertTrue(ValueUtils.isTrue(true));
		assertTrue(ValueUtils.isTrue(Boolean.TRUE));
		assertFalse(ValueUtils.isTrue(false));
		assertFalse(ValueUtils.isTrue(Boolean.FALSE));
		
		assertFalse(ValueUtils.isTrue("true"));
		assertFalse(ValueUtils.isTrue(77));
		assertFalse(ValueUtils.isTrue(null));
	}
	
	@Test
	public void testIsFalse() {
		assertTrue(ValueUtils.isFalse(false));
		assertTrue(ValueUtils.isFalse(Boolean.FALSE));
		assertFalse(ValueUtils.isFalse(true));
		assertFalse(ValueUtils.isFalse(Boolean.TRUE));
		
		assertFalse(ValueUtils.isFalse("false"));
		assertFalse(ValueUtils.isFalse(77));
		assertFalse(ValueUtils.isFalse(null));
	}
	
	@Test
	public void testOr() {
		assertEquals("a", ValueUtils.or(null, null, "a"));
		assertEquals("", ValueUtils.or(null, "", "a"));
		assertNull( ValueUtils.or(null, null, null));
	}
	
	@Test
	public void testORF() {
		String[] array1 = null;
		String[] array2 = new String[]{"A", "B"};
		
		assertEquals("A", ValueUtils.eval("!", () -> array2[0] ));
		assertEquals("!", ValueUtils.eval("!", () -> null ));
		assertEquals("!", ValueUtils.eval("!", () -> array1[0] ));

		NewAssert.assertThrows(ArrayIndexOutOfBoundsException.class, ()->{
			ValueUtils.eval("!", () -> array2[4]);
		});
	}
	
}
