Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Shi Chen <[email protected]>
  • Loading branch information
CsCherrYY committed Sep 6, 2022
1 parent 3bd6dcc commit c4be6ba
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public static String getTypeName(AbstractTypeDeclaration node) {
}

public static boolean hasMethod(IType type, String methodName, Class... parameterTypes) {
if (type == null) {
return false;
}
try {
return Stream.of(type.getMethods()).anyMatch(method -> {
if (!method.getElementName().equals(methodName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,23 @@ public void testGenerateToStringQuickAssist_emptyFields() throws JavaModelExcept
quickAssistActions = CodeActionHandlerTest.findActions(codeActions, JavaCodeActionKind.QUICK_ASSIST);
Assert.assertFalse(CodeActionHandlerTest.commandExists(quickAssistActions, CodeActionHandler.COMMAND_ID_APPLY_EDIT, ActionMessages.GenerateToStringAction_label));
}

@Test
public void testGenerateToStringQuickAssistExists() throws JavaModelException {
//@formatter:off
ICompilationUnit unit = fPackageP.createCompilationUnit("A.java", "package p;\r\n" +
"\r\n" +
"public class A {\r\n" +
" String name;\r\n" +
" public String toString() {\r\n" +
" return this.name;\r\n" +
" }\r\n" +
"}"
, true, null);
//@formatter:on
CodeActionParams params = CodeActionUtil.constructCodeActionParams(unit, "A");
List<Either<Command, CodeAction>> codeActions = server.codeAction(params).join();
Assert.assertNotNull(codeActions);
Assert.assertNull(CodeActionHandlerTest.findAction(codeActions, JavaCodeActionKind.QUICK_ASSIST, "Generate toString()..."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,25 @@ public void testHashCodeEqualsQuickAssist() throws JavaModelException {
Assert.assertFalse(quickAssistActions.isEmpty());
Assert.assertFalse(CodeActionHandlerTest.commandExists(quickAssistActions, SourceAssistProcessor.COMMAND_ID_ACTION_HASHCODEEQUALSPROMPT));
}

@Test
public void testHashCodeEqualsQuickAssistExists() throws JavaModelException {
//@formatter:off
ICompilationUnit unit = fPackageP.createCompilationUnit("A.java", "package p;\r\n" +
"\r\n" +
"public class A {\r\n" +
" String name;\r\n" +
" public int hashCode() {\r\n" +
" }\r\n" +
" public boolean equals(Object a) {\r\n" +
" return true;\r\n" +
" }\r\n" +
"}"
, true, null);
//@formatter:on
CodeActionParams params = CodeActionUtil.constructCodeActionParams(unit, "A");
List<Either<Command, CodeAction>> codeActions = server.codeAction(params).join();
Assert.assertNotNull(codeActions);
Assert.assertNull(CodeActionHandlerTest.findAction(codeActions, JavaCodeActionKind.QUICK_ASSIST, "Generate hashCode() and equals()..."));
}
}

0 comments on commit c4be6ba

Please sign in to comment.