package com.alexrnl.commons.gui.swing;

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

import java.beans.PropertyChangeEvent;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.WindowConstants;

import org.junit.Test;

/**
 * Add test suite for the {@link AbstractFrame} class.
 * @author Alex
 */
public class AbstractFrameTest {
	/**
	 * Private class used for test purposes.
	 * @author Alex
	 */
	private class TestFrame extends AbstractFrame {
		/** Serial version UID */
		private static final long	serialVersionUID	= 1L;

		/**
		 * Constructor #1.<br />
		 * Default constructor.
		 */
		public TestFrame () {
			super("Test");
		}

		/**
		 * Constructor #1.<br />
		 * Default constructor.
		 * @param icon
		 *        the icon to load for decorating the frame.
		 */
		public TestFrame (final Path icon) {
			super("Test", icon);
		}

		@Override
		public void modelPropertyChange (final PropertyChangeEvent evt) {
			// This has been tested in the MVC tests
		}

		@Override
		protected void preInit (final Object... parameters) {
			// TODO Auto-generated method stub
		}

		@Override
		protected void build () {
			// TODO Auto-generated method stub
		}
	}
	
	/**
	 * Test method for the final state of the frame.
	 * @throws URISyntaxException
	 *         if there was an issue with the icon's path.
	 * @throws IOException
	 *         if there was an issue while loading the icon.
	 * @throws InterruptedException
	 *         if the thread was interrupted while waiting for the frame to be drawn.
	 */
	@Test
	public void testFinalState () throws URISyntaxException, IOException, InterruptedException {
		Logger.getLogger(AbstractFrame.class.getName()).setLevel(Level.WARNING);
		final TestFrame frame = new TestFrame();
		assertFalse(frame.isReady());
		assertEquals("Test", frame.getTitle());
		assertFalse(frame.isVisible());
		assertEquals(WindowConstants.HIDE_ON_CLOSE, frame.getDefaultCloseOperation());
		assertNull(frame.getIconImage());
		assertEquals(frame.getMinimumSize(), frame.getSize());
		Logger.getLogger(AbstractFrame.class.getName()).setLevel(Level.FINE);
		final Path iconPath = Paths.get(getClass().getResource("/frameIcon.jpg").toURI());
		final TestFrame frameWithIcon = new TestFrame(iconPath);
		synchronized (frameWithIcon) {
			while (!frameWithIcon.isReady()) {
				frameWithIcon.wait();
			}
		}
		assertTrue(frameWithIcon.isReady());
		assertNotNull(frameWithIcon.getIconImages().get(0));
	}
	
	/**
	 * Test method for {@link com.alexrnl.commons.gui.swing.AbstractFrame#getFrame()}.
	 */
	@Test
	public void testGetFrame () {
		// TODO more test, while the frame is loading
	}
}

@@ -1367,49 +1367,8 @@
 s) %7B
-%0A%09%09%09// TODO Auto-generated method stub%0A%09%09
 %7D%0A%0A%09
@@ -1409,49 +1409,8 @@
 () %7B
-%0A%09%09%09// TODO Auto-generated method stub%0A%09%09
 %7D%0A%09%7D
@@ -2704,166 +2704,429 @@
 hod 
-for %7B@link com.alexrnl.commons.gui.swing.AbstractFrame#getFrame()%7D.%0A%09 */%0A%09@Test%0A%09public void testGetFrame () %7B%0A%09%09// TODO more test, while the 
+while the frame is being rendered.%0A%09 * @throws InterruptedException%0A%09 *         if the thread was interrupted while waiting for the frame to be drawn.%0A%09 */%0A%09@Test%0A%09public void testWaitingForBuild () throws InterruptedException %7B%0A%09%09final TestFrame frame = new TestFrame();%0A%09%09synchronized (frame) %7B%0A%09%09%09while (!frame.isReady()) %7B%0A%09%09%09%09assertFalse(
 frame
- is loading
+.isReady());%0A%09%09%09%09frame.wait();%0A%09%09%09%7D%0A%09%09%7D%0A%09%09assertTrue(frame.isReady());%0A%09%09
 %0A%09%7D%0A

Complete AbstractFrame test case