package com.approximatrix.draco.application.preferences;

import static org.junit.Assert.*;

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

import com.google.gson.Gson;

public class UIPreferencesTest {

	private UIPreferences prefs = null;
	private static final int SHOULD_BE_MAX_SIZE = 256;
	
	@Before
	public void setUp() throws Exception {
		prefs = new UIPreferences();
	}

	@After
	public void tearDown() throws Exception {
		prefs = null;
	}

	@Test
	public void testSetIconSize() {
		prefs.setIconSize(SHOULD_BE_MAX_SIZE+100);
		assertEquals(SHOULD_BE_MAX_SIZE,prefs.getIconSize());
		
		prefs.setIconSize(-200);
		assertTrue(prefs.getIconSize()>0);
	}
	
	@Test
	public void testSetLookAndFeel() {
		prefs.setLookAndFeel("TestClass");
		
		assertEquals("TestClass", prefs.getLookAndFeel());
	}
	
	@Test
	public void testJSONable() {
		Gson gson = new Gson();
		
		prefs.setIconSize(52);
		String prefs_string = gson.toJson(prefs);
		
		assertNotNull(prefs_string);
		
		prefs = gson.fromJson(prefs_string, UIPreferences.class);
		assertEquals(52,prefs.getIconSize());
	}

	@Test
	public void testTag() {
		assertEquals("ui",UIPreferences.TAG);
	}
	
}
