/*******************************************************************************
 * Copyright (c) 2016 Red Hat Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat Inc. - initial API and implementation
 *******************************************************************************/
package org.jboss.tools.vscode.java.internal.handlers;

import static org.jboss.tools.vscode.java.internal.JsonMessageHelper.getParams;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.eclipse.core.resources.IProject;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.TextDocumentPositionParams;
import org.jboss.tools.vscode.java.internal.managers.AbstractProjectsManagerBasedTest;
import org.junit.Before;
import org.junit.Test;

/**
 * @author Fred Bricon
 */
public class HoverHandlerTest extends AbstractProjectsManagerBasedTest {

	private static String HOVER_TEMPLATE =
			"{\n" +
					"    \"id\": \"1\",\n" +
					"    \"method\": \"textDocument/hover\",\n" +
					"    \"params\": {\n" +
					"        \"textDocument\": {\n" +
					"            \"uri\": \"${file}\"\n" +
					"        },\n" +
					"        \"position\": {\n" +
					"            \"line\": ${line},\n" +
					"            \"character\": ${char}\n" +
					"        }\n" +
					"    },\n" +
					"    \"jsonrpc\": \"2.0\"\n" +
					"}";

	private HoverHandler handler;

	private IProject project;

	@Before
	public void setup() throws Exception {
		handler = new HoverHandler();
		project = importProject("eclipse/hello");
	}

	@Test
	public void testHover() throws Exception {
		//given
		//Hovers on the System.out
		String payload = createHoverRequest("src/java/Foo.java", 5, 10);
		TextDocumentPositionParams position = getParams(payload);

		//when
		Hover hover = handler.hover(position).get();

		//then
		assertNotNull(hover);
		assertEquals(1, hover.getContents().size());
		assertTrue(hover.getContents().get(0).startsWith("The \"standard\" output stream"));
	}

	String createHoverRequest(String file, int line, int kar) {
		String fileURI = project.getFile(file).getRawLocationURI().toString();
		return HOVER_TEMPLATE.replace("${file}", fileURI)
				.replace("${line}", String.valueOf(line))
				.replace("${char}", String.valueOf(kar));
	}
}

@@ -793,16 +793,66 @@
 tTrue;%0A%0A
+import java.net.URI;%0Aimport java.nio.file.Paths;%0A%0A
 import o
@@ -968,24 +968,85 @@
 tionParams;%0A
+import org.jboss.tools.vscode.java.internal.WorkspaceHelper;%0A
 import org.j
@@ -1864,79 +1864,119 @@
 %7B%0A%09%09
-handler = new HoverHandler();%0A%09%09project = importProject(%22eclipse/hello%22
+importProjects(%22eclipse/hello%22);%0A%09%09project = WorkspaceHelper.getProject(%22hello%22);%0A%09%09handler = new HoverHandler(
 );%0A%09
@@ -2429,128 +2429,804 @@
 %7D%0A%0A%09
-String createHoverRequest(String file, int line, int kar) %7B%0A%09%09String fileURI = project.getFile(file).getRawLocationURI()
+@Test%0A%09public void testHoverStandalone() throws Exception %7B%0A%09%09//given%0A%09%09//Hovers on the System.out%0A%09%09URI standalone = Paths.get(%22projects%22,%22maven%22,%22salut%22,%22src%22,%22main%22,%22java%22,%22java%22,%22Foo.java%22).toUri();%0A%09%09String payload = createHoverRequest(standalone, 7, 11);%0A%09%09TextDocumentPositionParams position = getParams(payload);%0A%0A%09%09//when%0A%09%09Hover hover = handler.hover(position).get();%0A%0A%09%09//then%0A%09%09assertNotNull(hover);%0A%09%09assertEquals(1, hover.getContents().size());%0A%09%09assertTrue(hover.getContents().get(0).startsWith(%22The %5C%22standard%5C%22 output stream%22));%0A%09%7D%0A%0A%09String createHoverRequest(String file, int line, int kar) %7B%0A%09%09URI uri = project.getFile(file).getRawLocationURI();%0A%09%09return createHoverRequest(uri, line, kar);%0A%09%7D%0A%0A%09String createHoverRequest(URI file, int line, int kar) %7B%0A%09%09String fileURI = file
 .toS

Add hover test in case of standalone file