Bug 527069 - Unable to open selected external editor from project

Added a test to ensure the correct behavior of the editor when using
external editors retrieved from the OS.

Change-Id: I1441de832aac34f9d723de880cd7517d9bf0dbd1
Signed-off-by: Patrik Suzzi <psuzzi@gmail.com>
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java
index b6c3933..2960f9c 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation 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
@@ -8,10 +8,12 @@
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *     Lars Vogel <Lars.Vogel@gmail.com> - Bug 442043
+ *     Patrik Suzzi <psuzzi@gmail.com> - Bug 527069
  *******************************************************************************/
 package org.eclipse.ui.tests.api;
 
 import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertThat;
 
 import org.eclipse.core.internal.content.ContentTypeManager;
 import org.eclipse.core.resources.IFile;
@@ -36,6 +38,7 @@
 import org.eclipse.ui.tests.harness.util.ArrayUtil;
 import org.eclipse.ui.tests.harness.util.CallHistory;
 import org.eclipse.ui.tests.harness.util.FileUtil;
+import org.hamcrest.Matchers;
 import org.junit.FixMethodOrder;
 import org.junit.runners.MethodSorters;
 
@@ -112,6 +115,21 @@
 		assertNull(editor);
 	}
 
+	/** Ensures that OS external editors can be found using {@link IEditorRegistry#findEditor(String)} */
+	public void testFindExternalEditor() {
+		IEditorDescriptor[] sortedEditorsFromOS = ((EditorRegistry) fReg).getSortedEditorsFromOS();
+		assertThat("The OS should have at least one external editor", sortedEditorsFromOS.length,
+				Matchers.greaterThan(1));
+		// cycle through external editors
+		for (IEditorDescriptor ied : sortedEditorsFromOS) {
+			EditorDescriptor ed = (EditorDescriptor) ied;
+			// find external editor from registry
+			EditorDescriptor found = (EditorDescriptor) fReg.findEditor(ed.getId());
+			assertNotNull("Found editor must not be null", found);
+			assertEquals("External editor should be found using find(id)", ed.getProgram(), found.getProgram());
+		}
+	}
+
 	/**
 	 * getDefaultEditor()
 	 */