package com.alexrnl.commons.gui.swing;

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

import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JMenu;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

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

import com.alexrnl.commons.translation.Translator;

/**
 * Test suite for the {@link SwingUtils} class.
 * @author Alex
 */
public class SwingUtilsTest {
	/** Translator to use */
	private Translator translator;
	
	/**
	 * Set up test attributes.
	 * @throws URISyntaxException
	 *         if there is a problem with the path of the translation file.
	 */
	@Before
	public void setUp () throws URISyntaxException {
		translator = new Translator(Paths.get(getClass().getResource("/locale.xml").toURI()));
	}
	
	/**
	 * Test method for {@link com.alexrnl.commons.gui.swing.SwingUtils#setLookAndFeel(java.lang.String)}.
	 */
	@Test
	public void testSetLookAndFeel () {
		assertFalse(SwingUtils.setLookAndFeel(null));
		assertFalse(SwingUtils.setLookAndFeel(""));
		for (final LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
			assertTrue(SwingUtils.setLookAndFeel(laf.getName()));
			Logger.getLogger(SwingUtils.class.getName()).setLevel(Level.FINE);
		}
		UIManager.installLookAndFeel(new LookAndFeelInfo("LDR", "com.alexrnl.commons.gui.swing.ldr"));
		assertFalse(SwingUtils.setLookAndFeel("LDR"));
	}
	
	/**
	 * Test method for {@link com.alexrnl.commons.gui.swing.SwingUtils#getMenu(com.alexrnl.commons.translation.Translator, String)}.
	 */
	@Test
	public void testGetMenu () {
		final JMenu open = SwingUtils.getMenu(translator, "commons.menu.file.open");
		assertEquals("Open a file", open.getText());
		assertEquals('O', open.getMnemonic());

		final JMenu close = SwingUtils.getMenu(translator, "commons.menu.file.close");
		assertEquals("Close a file", close.getText());
		assertEquals('\0', close.getMnemonic());

		final JMenu quit = SwingUtils.getMenu(translator, "commons.menu.file.quit");
		assertEquals("Quit the application", quit.getText());
		assertEquals('\0', quit.getMnemonic());
	}
}

@@ -164,16 +164,53 @@
 ertTrue;
+%0Aimport static org.junit.Assert.fail;
 %0A%0Aimport
@@ -1599,32 +1599,324 @@
 R%22));%0A%09%7D%0A%09%0A%09/**%0A
+%09 * Test method for %7B@link com.alexrnl.commons.gui.swing.SwingUtils#getMenuItem(Translator, com.alexrnl.commons.translation.GUIElement, java.awt.event.ActionListener)%7D.%0A%09 */%0A%09@Test%0A%09public void testGetMenuItem () %7B%0A%09%09fail(%22Implement test method%22);%0A%09%09// TODO implements test method%0A%09%7D%0A%09%09%0A%09/**%0A
 %09 * Test method 

Add method for testing getMenuItem