MethodChecksUtils { public static boolean hasTestMethodKeyword(AstNode astNode) { boolean hasAnnotation = false; List<AstNode> modifiersChildren = astNode.getChildren(MODIFIERS); for (AstNode modifier : modifiersChildren) { for (AstNode modifierChild : modifier.getChildren()) { if ((modifierChild.getTokenOriginalValue().matches(TEST_METHOD_PATTERN))) { hasAnnotation = true; break; } } } return hasAnnotation; }  static boolean hasAssertion(List<AstNode> nameNodes, String pattern); static boolean hasTestMethodKeyword(AstNode astNode);  }
@Test public void testHasTestMethodKeywordEmptyModifiersChildrenList() { AstNode parentNode = mock(AstNode.class); when(parentNode.getChildren(MODIFIERS)).thenReturn(new LinkedList<>()); assertFalse(MethodChecksUtils.hasTestMethodKeyword(parentNode)); }
@Test public void testHasTestMethodKeywordEmptyChildrenListOfModifiers() { AstNode parentNode = mock(AstNode.class); List<AstNode> modifiers = new LinkedList<>(); AstNode modifier = mock(AstNode.class); when(modifier.getChildren()).thenReturn(new LinkedList<>()); modifiers.add(modifier); when(parentNode.getChildren()).thenReturn(modifiers); assertFalse(MethodChecksUtils.hasTestMethodKeyword(parentNode)); }
@Test public void testHasTestMethodKeywordNotMatchesTestMethodPattern() { AstNode astNode = mock(AstNode.class); AstNode modifier = mock(AstNode.class); AstNode notTestMethodNode = mock(AstNode.class); List<AstNode> modifiers = new LinkedList<>(); List<AstNode> modifierChildren = new LinkedList<>(); when(notTestMethodNode.getTokenOriginalValue()).thenReturn("somethingElse"); modifierChildren.add(notTestMethodNode); when(modifier.getChildren()).thenReturn(modifierChildren); modifiers.add(modifier); when(astNode.getChildren(MODIFIERS)).thenReturn(modifiers); assertFalse(MethodChecksUtils.hasTestMethodKeyword(astNode)); }
@Test public void testHasTestMethodKeywordMatchesTestMethodPattern() { AstNode astNode = mock(AstNode.class); AstNode modifier = mock(AstNode.class); AstNode notTestMethodNode = mock(AstNode.class); List<AstNode> modifiers = new LinkedList<>(); List<AstNode> modifierChildren = new LinkedList<>(); when(notTestMethodNode.getTokenOriginalValue()).thenReturn("testMethod"); modifierChildren.add(notTestMethodNode); when(modifier.getChildren()).thenReturn(modifierChildren); modifiers.add(modifier); when(astNode.getChildren(MODIFIERS)).thenReturn(modifiers); assertTrue(MethodChecksUtils.hasTestMethodKeyword(astNode)); }