Java Code Examples for org.assertj.core.api.StringAssert

The following examples show how to use org.assertj.core.api.StringAssert. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: initializr   Source File: MavenBuildAssert.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Assert {@code pom.xml} defines the specified dependency.
 * @param dependency the dependency
 * @return {@code this} assertion object
 */
public MavenBuildAssert hasDependency(Dependency dependency) {
	this.pom.nodesAtPath("/project/dependencies/dependency").areExactly(1, new Condition<>((candidate) -> {
		Dependency actual = toDependency(candidate);
		if (dependency.getGroupId().equals(actual.getGroupId())
				&& dependency.getArtifactId().equals(actual.getArtifactId())) {
			if (dependency.getVersion() != null) {
				new StringAssert(actual.getVersion()).isEqualTo(dependency.getVersion());
			}
			if (dependency.getScope() != null) {
				new StringAssert(actual.getScope()).isEqualTo(dependency.getScope());
			}
			if (dependency.getType() != null) {
				new StringAssert(actual.getType()).isEqualTo(dependency.getType());
			}
			return true;
		}
		return false;
	}, "matching dependency"));
	return this;
}
 
Example 2
Source Project: initializr   Source File: MavenBuildAssert.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Assert {@code pom.xml} defines the specified repository.
 * @param id the id of the repository
 * @param name the name of the repository
 * @param url the url of the repository
 * @param snapshotsEnabled whether snapshot is enabled for the repository
 * @return {@code this} assertion object
 */
public MavenBuildAssert hasRepository(String id, String name, String url, Boolean snapshotsEnabled) {
	this.pom.nodesAtPath("/project/repositories/repository").areExactly(1, new Condition<>((candidate) -> {
		String actualId = ((Element) candidate).getElementsByTagName("id").item(0).getTextContent();
		if (actualId.equals(id)) {
			Repository repository = toRepository(candidate);
			if (name != null) {
				new StringAssert(repository.getName()).isEqualTo(name);
			}
			if (url != null) {
				try {
					new UrlAssert(repository.getUrl()).isEqualTo(new URL(url));
				}
				catch (MalformedURLException ex) {
					throw new IllegalArgumentException("Cannot parse URL", ex);
				}
			}
			if (snapshotsEnabled) {
				new BooleanAssert(repository.isSnapshotsEnabled()).isEqualTo(snapshotsEnabled);
			}
			return true;
		}
		return false;
	}, "matching repository"));
	return this;
}
 
Example 3
Source Project: initializr   Source File: NodeAssert.java    License: Apache License 2.0 5 votes vote down vote up
public StringAssert textAtPath(String xpath) {
	try {
		return new StringAssert(
				(String) this.xpath.evaluate(xpath + "/text()", this.actual, XPathConstants.STRING));
	}
	catch (XPathExpressionException ex) {
		throw new RuntimeException(ex);
	}
}
 
Example 4
Source Project: initializr   Source File: NodeAssert.java    License: Apache License 2.0 5 votes vote down vote up
StringAssert textAtPath(String xpath) {
	try {
		return new StringAssert(
				(String) this.xpath.evaluate(xpath + "/text()", this.actual, XPathConstants.STRING));
	}
	catch (XPathExpressionException ex) {
		throw new RuntimeException(ex);
	}
}
 
Example 5
Source Project: vertx-web   Source File: JsonAssert.java    License: Apache License 2.0 4 votes vote down vote up
public StringAssert asString() {
  assertThat(actual).isInstanceOf(String.class);
  return new StringAssert((String) actual);
}
 
Example 6
Source Project: xmlunit   Source File: AssertionsAdapter.java    License: Apache License 2.0 4 votes vote down vote up
static AbstractCharSequenceAssert<?, String> assertThat(String actual) {
    return new StringAssert(actual);
}