|
46 | 46 | import org.junit.BeforeClass; |
47 | 47 | import org.junit.Test; |
48 | 48 | import org.scijava.Context; |
| 49 | +import org.scijava.MenuPath; |
49 | 50 | import org.scijava.plugin.Plugin; |
50 | 51 | import org.scijava.test.TestUtils; |
51 | 52 | import org.scijava.util.FileUtils; |
@@ -107,6 +108,38 @@ public void testFindScripts() { |
107 | 108 | assertMenuPath("Math > Trig > tan", scripts, 10); |
108 | 109 | } |
109 | 110 |
|
| 111 | + /** |
| 112 | + * Tests that menu prefixes work as expected when |
| 113 | + * {@link ScriptService#addScriptDirectory(File, org.scijava.MenuPath)} is |
| 114 | + * called. |
| 115 | + */ |
| 116 | + @Test |
| 117 | + public void testMenuPrefixes() { |
| 118 | + final Context context = new Context(ScriptService.class); |
| 119 | + final ScriptService scriptService = context.service(ScriptService.class); |
| 120 | + |
| 121 | + final MenuPath menuPrefix = new MenuPath("Foo > Bar"); |
| 122 | + assertEquals(2, menuPrefix.size()); |
| 123 | + assertEquals("Bar", menuPrefix.getLeaf().getName()); |
| 124 | + scriptService.addScriptDirectory(scriptsDir, menuPrefix); |
| 125 | + |
| 126 | + final ArrayList<ScriptInfo> scripts = findScripts(scriptService); |
| 127 | + |
| 128 | + assertEquals(12, scripts.size()); |
| 129 | + assertMenuPath("Foo > Bar > Scripts > The Lazy Dog", scripts, 0); |
| 130 | + assertMenuPath("Foo > Bar > Math > add", scripts, 1); |
| 131 | + assertMenuPath("Foo > Bar > Scripts > brown", scripts, 2); |
| 132 | + assertMenuPath("Foo > Bar > Math > Trig > cos", scripts, 3); |
| 133 | + assertMenuPath("Foo > Bar > Math > divide", scripts, 4); |
| 134 | + assertMenuPath("Foo > Bar > Scripts > fox", scripts, 5); |
| 135 | + assertMenuPath("Foo > Bar > ignored", scripts, 6); |
| 136 | + assertMenuPath("Foo > Bar > Math > multiply", scripts, 7); |
| 137 | + assertMenuPath("Foo > Bar > Scripts > quick", scripts, 8); |
| 138 | + assertMenuPath("Foo > Bar > Math > Trig > sin", scripts, 9); |
| 139 | + assertMenuPath("Foo > Bar > Math > subtract", scripts, 10); |
| 140 | + assertMenuPath("Foo > Bar > Math > Trig > tan", scripts, 11); |
| 141 | + } |
| 142 | + |
110 | 143 | // -- Helper methods -- |
111 | 144 |
|
112 | 145 | private ArrayList<ScriptInfo> findScripts(final ScriptService scriptService) { |
|
0 commit comments