MethodChecksUtils { public static boolean hasAssertion(List<AstNode> nameNodes, String pattern) { StringBuilder validcall = new StringBuilder(); for (AstNode nameNodeChild : nameNodes) { if (nameNodeChild.getTokenOriginalValue().matches(SYSTEM_PATTERN)) { nameNodeChild.getChildren().stream().forEach((AstNode nameNodeGrandChild) -> { validcall.append(nameNodeGrandChild.getTokenOriginalValue()); }); break; } } return validcall.toString().matches(pattern); }  static boolean hasAssertion(List<AstNode> nameNodes, String pattern); static boolean hasTestMethodKeyword(AstNode astNode);  }
@Test public void testHasAssertionNodeNoSystemNameButEmptyChildrenList() { List<AstNode> nameNodes = new LinkedList<>(); AstNode systemNodeMock = mock(AstNode.class); when(systemNodeMock.getTokenOriginalValue()).thenReturn("insert"); nameNodes.add(systemNodeMock); assertFalse(MethodChecksUtils.hasAssertion(nameNodes, SYSTEM_ASSERT_PATTERN)); }
@Test public void testHasAssertionNodeWhithSystemNameButEmptyChildrenList() { List<AstNode> nameNodes = new LinkedList<>(); AstNode systemNodeMock = mock(AstNode.class); when(systemNodeMock.getTokenOriginalValue()).thenReturn("System"); when(systemNodeMock.getChildren()).thenReturn(new LinkedList<>()); nameNodes.add(systemNodeMock); assertFalse(MethodChecksUtils.hasAssertion(nameNodes, SYSTEM_ASSERT_PATTERN)); }
@Test public void testHasAssertionValidCase() { List<AstNode> nameNodes = new LinkedList<>(); List<AstNode> children = new LinkedList<>(); AstNode systemNodeMock = mock(AstNode.class); when(systemNodeMock.getTokenOriginalValue()).thenReturn("System"); nameNodes.add(systemNodeMock); AstNode dotNodeMock = mock(AstNode.class); when(dotNodeMock.getTokenOriginalValue()).thenReturn("."); AstNode assertEqualsNodeMock = mock(AstNode.class); when(assertEqualsNodeMock.getTokenOriginalValue()).thenReturn("assertEquals"); children.add(systemNodeMock); children.add(dotNodeMock); children.add(assertEqualsNodeMock); when(systemNodeMock.getChildren()).thenReturn(children); assertTrue(MethodChecksUtils.hasAssertion(nameNodes, SYSTEM_ASSERT_PATTERN)); }
@Test public void testHasAssertionEmptyListInput() { assertFalse(MethodChecksUtils.hasAssertion(new LinkedList<>(), SYSTEM_ASSERT_PATTERN)); }