org.conqat.lib.commons.uniformpath.UniformPathAssert Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of teamscale-commons-test-fixtures Show documentation
Show all versions of teamscale-commons-test-fixtures Show documentation
Provides common DTOs for Teamscale
/*
* Copyright (c) CQSE GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.conqat.lib.commons.uniformpath;
import org.assertj.core.api.AbstractAssert;
import org.conqat.lib.commons.uniformpath.UniformPath.EType;
/** Custom asserts on {@link UniformPath}. */
public class UniformPathAssert extends AbstractAssert {
private UniformPathAssert(UniformPath actual) {
super(actual, UniformPathAssert.class);
}
/** Creates a new {@link UniformPathAssert}. */
public static UniformPathAssert assertThat(UniformPath actual) {
return new UniformPathAssert(actual);
}
/** Asserts that the uniform path has the given string representation. */
public UniformPathAssert hasPath(String path) {
assertThat(actual).hasToString(path);
return this;
}
/** Asserts that the uniform path is a code path. */
public UniformPathAssert isCodePath() {
return assertPathType(EType.CODE);
}
/** Asserts that the uniform path is an architecture path. */
public UniformPathAssert isArchitecturePath() {
return assertPathType(EType.ARCHITECTURE);
}
/** Asserts that the uniform path is a non-code path. */
public UniformPathAssert isNonCodePath() {
return assertPathType(EType.NON_CODE);
}
/** Asserts that the uniform path is an issue query path. */
public UniformPathAssert isIssueQueryPath() {
return assertPathType(EType.ISSUE_QUERY);
}
/** Asserts that the uniform path is a test implementation. */
public UniformPathAssert isTestImplementationPath() {
return assertPathType(EType.TEST_IMPLEMENTATION);
}
/** Asserts that the uniform path is a test execution path. */
public UniformPathAssert isTestExecutionPath() {
return assertPathType(EType.TEST_EXECUTION);
}
/** Asserts that the uniform path is a test query path. */
public UniformPathAssert isTestQueryPath() {
return assertPathType(EType.TEST_QUERY);
}
/** Asserts that the uniform path has the given type. */
private UniformPathAssert assertPathType(EType pathType) {
isNotNull();
if (actual.type != pathType) {
failWithMessage("Expected path to have type <%s> but was <%s>", pathType, actual.type);
}
return this;
}
/** Asserts that the uniform path is a root path. */
public UniformPathAssert isRootPath() {
isNotNull();
if (!actual.isRoot()) {
failWithMessage("Expected path to be a root path");
}
return this;
}
/** Asserts that the uniform path is not a root path. */
public UniformPathAssert isNotRootPath() {
isNotNull();
if (actual.isRoot()) {
failWithMessage("Expected path not to be a root path");
}
return this;
}
/** Asserts that the uniform path has the given ancestor. */
public UniformPathAssert hasAncestor(UniformPath potentialAncestor) {
isNotNull();
if (!actual.hasAncestor(potentialAncestor)) {
failWithMessage("Expected <%s> to have ancestor <%s>", actual.toString(), potentialAncestor.toString());
}
return this;
}
/** Asserts that the uniform path doesn't have the given ancestor. */
public UniformPathAssert notHasAncestor(UniformPath potentialAncestor) {
isNotNull();
if (actual.hasAncestor(potentialAncestor)) {
failWithMessage("Expected <%s> not to have ancestor <%s>", actual.toString(), potentialAncestor.toString());
}
return this;
}
/** Asserts that the uniform path has the given descendant. */
public UniformPathAssert hasDescendant(UniformPath potentialDescendant) {
isNotNull();
if (!actual.hasDescendant(potentialDescendant)) {
failWithMessage("Expected <%s> to have descendant <%s>", actual.toString(), potentialDescendant.toString());
}
return this;
}
/** Asserts that the uniform path doesn't have the given descendant. */
public UniformPathAssert notHasDescendant(UniformPath potentialDescendant) {
isNotNull();
if (actual.hasDescendant(potentialDescendant)) {
failWithMessage("Expected <%s> not to have descendant <%s>", actual.toString(),
potentialDescendant.toString());
}
return this;
}
/** Asserts that the uniform path has the given parent. */
public UniformPathAssert hasParent(UniformPath potentialParent) {
isNotNull();
if (!actual.getParent().equals(potentialParent)) {
failWithMessage("Expected <%s> to be a parent of <%s>", potentialParent.toString(), actual.toString());
}
return this;
}
/** Asserts that the uniform path doesn't have the given parent. */
public UniformPathAssert notHasParent(UniformPath potentialParent) {
isNotNull();
if (actual.getParent().equals(potentialParent)) {
failWithMessage("Expected <%s> not to be a parent of <%s>", potentialParent.toString(), actual.toString());
}
return this;
}
}