private void assertEquals(Object expected, Object actual) { assertEquals("assertEquals violation", expected, actual); }
/** checks that for all elements, the path can be obtained, parsed, and give the same element when evaluated */ public void checkElementToPathToElementEquivalence() { _rootPackage.getPackage("spoon").getElements(e -> true).parallelStream().forEach(element -> { CtPath path = element.getPath(); String pathStr = path.toString(); try { CtPath pathRead = new CtPathStringBuilder().fromString(pathStr); assertEquals(pathStr, pathRead.toString()); Collection<CtElement> returnedElements = pathRead.evaluateOn(_rootPackage); //contract: CtUniqueRolePathElement.evaluateOn() returns a unique elements if provided only a list of one inputs assertEquals(1, returnedElements.size()); CtElement actualElement = (CtElement) returnedElements.toArray()[0]; //contract: Element -> Path -> String -> Path -> Element leads to the original element assertSame(element, actualElement); } catch (CtPathException e) { throw new AssertionError("Path " + pathStr + " is either incorrectly generated or incorrectly read", e); } catch (AssertionError e) { throw new AssertionError("Path " + pathStr + " detection failed on " + element.getClass().getSimpleName() + ": " + element.toString(), e); } }); }
assertEquals("All parents have to be consistent", 0, inconsistentParents.size());
assertEquals(counterInclNull.scan, counterBiScan.scan); assertEquals(counterInclNull.scan, counterBiScan2.scan);
/** verifies that the explicit modifier should be present in the original source code */ public void checkModifiers() { for (CtModifiable modifiable : _rootPackage.getElements(new TypeFilter<>(CtModifiable.class))) { for (CtExtendedModifier modifier : modifiable.getExtendedModifiers()) { if (modifier.isImplicit()) { continue; } SourcePosition position = modifier.getPosition(); CompilationUnit compilationUnit = position.getCompilationUnit(); String originalSourceCode = compilationUnit.getOriginalSourceCode(); assertEquals(modifier.getKind().toString(), originalSourceCode.substring(position.getSourceStart(), position.getSourceEnd() + 1)); } } }