test-feat(util): Added ability to add a messages to all methods in GraphAssert.
*/
package com.synopsys.integration.detectable.util.graph;
+import org.junit.jupiter.api.Assertions;
+
import com.synopsys.integration.bdio.graph.DependencyGraph;
import com.synopsys.integration.bdio.model.Forge;
import com.synopsys.integration.bdio.model.externalid.ExternalId;
@@ -39,31 +41,55 @@ public class GraphAssert {
}
public ExternalId hasRootDependency(final ExternalId externalId) {
- assert graph.getRootDependencyExternalIds().contains(externalId);
+ return hasRootDependency(externalId, String.format("Expected '%s' to be in the root of graph.", externalId.createExternalId()));
+ }
+
+ public ExternalId hasRootDependency(final ExternalId externalId, final String message) {
+ Assertions.assertTrue(graph.getRootDependencyExternalIds().contains(externalId), message);
return externalId;
}
public ExternalId hasDependency(final ExternalId externalId) {
- assert graph.hasDependency(externalId);
+ return hasDependency(externalId, String.format("Expected '%s' to be in the graph.", externalId.createExternalId()));
+ }
+
+ public ExternalId hasDependency(final ExternalId externalId, final String message) {
+ Assertions.assertTrue(graph.hasDependency(externalId), message);
return externalId;
}
public ExternalId hasNoDependency(final ExternalId externalId) {
- assert !graph.hasDependency(externalId);
+ return hasNoDependency(externalId, String.format("Did not expect '%s' to be in the graph.", externalId.createExternalId()));
+ }
+
+ public ExternalId hasNoDependency(final ExternalId externalId, final String message) {
+ Assertions.assertFalse(graph.hasDependency(externalId), message);
return externalId;
}
public ExternalId hasParentChildRelationship(final ExternalId parent, final ExternalId child) {
- assert graph.getChildrenExternalIdsForParent(parent).contains(child);
+ return hasParentChildRelationship(parent, child, String.format("Expected parent '%s' to have child '%s'.", parent.createExternalId(), child.createExternalId()));
+ }
+
+ public ExternalId hasParentChildRelationship(final ExternalId parent, final ExternalId child, final String message) {
+ Assertions.assertTrue(graph.getChildrenExternalIdsForParent(parent).contains(child), message);
return child;
}
public void hasRelationshipCount(final ExternalId parent, final int count) {
- assert graph.getChildrenExternalIdsForParent(parent).size() == count;
+ hasRelationshipCount(parent, count, String.format("Expected '%s' to have a relationship count of %d.", parent.createExternalId(), count));
+ }
+
+ public void hasRelationshipCount(final ExternalId parent, final int count, final String message) {
+ Assertions.assertEquals(count, graph.getChildrenExternalIdsForParent(parent).size(), message);
}
public void hasRootSize(final int size) {
- assert graph.getRootDependencies().size() == size;
+ hasRootSize(size, String.format("Graph should have a root size of %d", size));
+ }
+
+ public void hasRootSize(final int size, final String message) {
+ Assertions.assertEquals(size, graph.getRootDependencies().size(), message);
}
}
