@Test public void execute() { assertTrue("Java project doesn't exist.", Eclim.projectExists(Jdt.TEST_PROJECT)); String result = Eclim.execute( new String[] { "java_delegate", "-p", Jdt.TEST_PROJECT, "-f", TEST_FILE, "-o", "124", "-e", "utf-8" }); // handle difference between 1.5 and 1.6 result = result.replaceAll("Double \\w\\b", "Double o"); System.out.println(result); assertTrue("Wrong first line.", result.startsWith("org.eclim.test.delegate.TestDelegate")); assertTrue( "Interface not in results.", result.indexOf("package java.util;\npublic interface List<Double> {") != -1); assertTrue( "Method not in results.", result.indexOf("\tpublic abstract Iterator<Double> iterator()") != -1); assertTrue( "Method not in results.", result.indexOf("\tpublic abstract boolean add(Double o)") != -1); result = Eclim.execute( new String[] { "java_delegate", "-p", Jdt.TEST_PROJECT, "-f", TEST_FILE, "-o", "124", "-e", "utf-8", "-t", "org.eclim.test.delegate.TestDelegate", "-s", "java.util.List%3CDouble%3E", "-m", "add(Double)" }); // handle difference between 1.5 and 1.6 result = result.replaceAll("Double \\w\\b", "Double o"); System.out.println(result); String contents = Eclim.fileToString(Jdt.TEST_PROJECT, TEST_FILE); assertTrue( "Method not found or invalid.", Pattern.compile( "public boolean add\\(Double \\w\\)\n \\{\n " + "\treturn list.add\\(\\w\\);") .matcher(contents) .find()); assertTrue( "Method not commented out in results.", result.indexOf("//public abstract boolean add(Double o)") != -1); }
@Test @SuppressWarnings("unchecked") public void execute() { assertTrue("Java project doesn't exist.", Eclim.projectExists(Jdt.TEST_PROJECT)); Pattern listImport = Pattern.compile("import\\s+java\\.util\\.List;"); String file = Eclim.fileToString(Jdt.TEST_PROJECT, TEST_FILE); assertFalse(listImport.matcher(file).find()); List<String> results = (List<String>) Eclim.execute( new String[] { "java_import", "-p", Jdt.TEST_PROJECT, "-f", TEST_FILE, "-o", "72", "-e", "utf-8", }); assertEquals(2, results.size()); assertEquals("java.awt.List", results.get(0)); assertEquals("java.util.List", results.get(1)); file = Eclim.fileToString(Jdt.TEST_PROJECT, TEST_FILE); assertFalse(listImport.matcher(file).find()); Map<String, Object> position = (Map<String, Object>) Eclim.execute( new String[] { "java_import", "-p", Jdt.TEST_PROJECT, "-f", TEST_FILE, "-o", "72", "-e", "utf-8", "-t", "java.util.List", }); file = Eclim.fileToString(Jdt.TEST_PROJECT, TEST_FILE); assertTrue(listImport.matcher(file).find()); assertEquals(96, position.get("offset")); assertEquals(7, position.get("line")); assertEquals(14, position.get("column")); position = (Map<String, Object>) Eclim.execute( new String[] { "java_import", "-p", Jdt.TEST_PROJECT, "-f", TEST_FILE, "-o", "109", "-e", "utf-8", }); Pattern arrayListImport = Pattern.compile("import\\s+java\\.util\\.ArrayList;"); file = Eclim.fileToString(Jdt.TEST_PROJECT, TEST_FILE); assertTrue(arrayListImport.matcher(file).find()); assertEquals(137, position.get("offset")); assertEquals(8, position.get("line")); assertEquals(27, position.get("column")); position = (Map<String, Object>) Eclim.execute( new String[] { "java_import", "-p", Jdt.TEST_PROJECT, "-f", TEST_FILE, "-o", "163", "-e", "utf-8", }); Pattern patternImport = Pattern.compile("import\\s+java\\.util\\.regex\\.Pattern;"); file = Eclim.fileToString(Jdt.TEST_PROJECT, TEST_FILE); assertTrue(patternImport.matcher(file).find()); assertEquals(196, position.get("offset")); assertEquals(11, position.get("line")); assertEquals(14, position.get("column")); position = (Map<String, Object>) Eclim.execute( new String[] { "java_import", "-p", Jdt.TEST_PROJECT, "-f", TEST_FILE, "-o", "220", "-e", "utf-8", }); Pattern fileImport = Pattern.compile("import\\s+java\\.io\\.File;"); file = Eclim.fileToString(Jdt.TEST_PROJECT, TEST_FILE); assertTrue(fileImport.matcher(file).find()); assertEquals(242, position.get("offset")); assertEquals(14, position.get("line")); assertEquals(11, position.get("column")); }