Skip to content

Commit

Permalink
additional conditions and asserts
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
  • Loading branch information
stbischof committed May 7, 2021
1 parent 953caad commit beafdac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,4 @@ public MapAssert<String, Object> hasMetadataThat() {
.as(actual + ".metadata");
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.osgi.test.assertj.feature;

import java.util.Objects;

import org.assertj.core.api.AbstractObjectAssert;
import org.osgi.util.feature.ID;

Expand Down Expand Up @@ -50,20 +48,7 @@ protected AbstractIDAssert(A actual, Class<S> selfType) {
* the given one.
*/
public S hasArtifactId(String artifactId) {
// check that actual ID we want to make assertions on is not null.
isNotNull();

// overrides the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting artifactId of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";

// null safe check
String actualArtifactId = actual.getArtifactId();
if (!Objects.deepEquals(actualArtifactId, artifactId)) {
failWithMessage(assertjErrorMessage, actual, artifactId, actualArtifactId);
}

// return the current assertion for method chaining
return myself;
return isNotNull().has(FeaturesConditions.IDConditions.artifactId(artifactId));
}

/**
Expand All @@ -76,20 +61,9 @@ public S hasArtifactId(String artifactId) {
* the given one.
*/
public S hasClassifier(String classifier) {
// check that actual ID we want to make assertions on is not null.
isNotNull();

// overrides the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting classifier of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";
return isNotNull().has(FeaturesConditions.IDConditions.classifier(classifier));

// null safe check
String actualClassifier = actual.getClassifier();
if (!Objects.deepEquals(actualClassifier, classifier)) {
failWithMessage(assertjErrorMessage, actual, classifier, actualClassifier);
}

// return the current assertion for method chaining
return myself;
}

/**
Expand All @@ -101,20 +75,7 @@ public S hasClassifier(String classifier) {
* given one.
*/
public S hasGroupId(String groupId) {
// check that actual ID we want to make assertions on is not null.
isNotNull();

// overrides the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting groupId of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";

// null safe check
String actualGroupId = actual.getGroupId();
if (!Objects.deepEquals(actualGroupId, groupId)) {
failWithMessage(assertjErrorMessage, actual, groupId, actualGroupId);
}

// return the current assertion for method chaining
return myself;
return isNotNull().has(FeaturesConditions.IDConditions.groupId(groupId));
}

/**
Expand All @@ -126,20 +87,7 @@ public S hasGroupId(String groupId) {
* given one.
*/
public S hasType(String type) {
// check that actual ID we want to make assertions on is not null.
isNotNull();

// overrides the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting type of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";

// null safe check
String actualType = actual.getType();
if (!Objects.deepEquals(actualType, type)) {
failWithMessage(assertjErrorMessage, actual, type, actualType);
}

// return the current assertion for method chaining
return myself;
return isNotNull().has(FeaturesConditions.IDConditions.type(type));
}

/**
Expand All @@ -151,20 +99,7 @@ public S hasType(String type) {
* given one.
*/
public S hasVersion(String version) {
// check that actual ID we want to make assertions on is not null.
isNotNull();

// overrides the default error message with a more explicit one
String assertjErrorMessage = "\nExpecting version of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>";

// null safe check
String actualVersion = actual.getVersion();
if (!Objects.deepEquals(actualVersion, version)) {
failWithMessage(assertjErrorMessage, actual, version, actualVersion);
}

// return the current assertion for method chaining
return myself;
return isNotNull().has(FeaturesConditions.IDConditions.version(version));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,27 @@ static Condition<FeatureBundle> metadataEmpty() {
}

interface IDConditions {
Condition<ID> c4 = null;
static Condition<ID> version(String version) {
return new Condition<ID>(f -> Objects.equals(f.getVersion(), version), "version must be %s", version);
}

static Condition<ID> groupId(String groupId) {
return new Condition<ID>(f -> Objects.equals(f.getGroupId(), groupId), "groupId must be %s", groupId);
}

static Condition<ID> artifactId(String artifactId) {
return new Condition<ID>(f -> Objects.equals(f.getArtifactId(), artifactId), "artifactId must be %s",
artifactId);
}

static Condition<ID> type(String type) {
return new Condition<ID>(f -> Objects.equals(f.getType(), type), "type must be %s", type);
}

static Condition<ID> classifier(String classifier) {
return new Condition<ID>(f -> Objects.equals(f.getClassifier(), classifier), "classifier must be %s",
classifier);
}
}

interface FeatureConfigurationConditions {
Expand Down

0 comments on commit beafdac

Please sign in to comment.