Skip to content

Commit 1728ad1

Browse files
authored
Merge pull request #1044 from stbischof/ocx
fix: assertj feature
2 parents 492ef98 + e4e2c49 commit 1728ad1

File tree

6 files changed

+47
-12
lines changed

6 files changed

+47
-12
lines changed

org.osgi.test.assertj.feature/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,24 @@
6666
<artifactId>junit-jupiter-params</artifactId>
6767
</dependency>
6868
</dependencies>
69+
70+
<build>
71+
<plugins>
72+
<plugin>
73+
<groupId>biz.aQute.bnd</groupId>
74+
<artifactId>bnd-maven-plugin</artifactId>
75+
<executions>
76+
<execution>
77+
<id>test-jar</id>
78+
<goals>
79+
<goal>test-jar</goal>
80+
</goals>
81+
<configuration>
82+
<artifactFragment>true</artifactFragment>
83+
</configuration>
84+
</execution>
85+
</executions>
86+
</plugin>
87+
</plugins>
88+
</build>
6989
</project>

org.osgi.test.assertj.feature/src/main/java/org/osgi/test/assertj/feature/AbstractFeatureAssert.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24+
import org.assertj.core.api.AbstractObjectAssert;
2425
import org.assertj.core.api.InstanceOfAssertFactories;
2526
import org.assertj.core.api.InstanceOfAssertFactory;
2627
import org.assertj.core.api.ListAssert;
@@ -35,7 +36,7 @@
3536
* CustomAssertionGenerator.
3637
*/
3738
public abstract class AbstractFeatureAssert<S extends AbstractFeatureAssert<S, A>, A extends Feature>
38-
extends AbstractFeatureArtifactAssert<S, A> {
39+
extends AbstractObjectAssert<S, A> {
3940

4041
/**
4142
* Creates a new <code>{@link AbstractFeatureAssert}</code> to make
@@ -47,6 +48,12 @@ protected AbstractFeatureAssert(A actual, Class<S> selfType) {
4748
super(actual, selfType);
4849
}
4950

51+
public IDAssert hasIDThat() {
52+
isNotNull();
53+
return IDAssert.assertThat(actual.getID())
54+
.as(actual + ".id");
55+
}
56+
5057
@SuppressWarnings("rawtypes")
5158
static InstanceOfAssertFactory<List, ListAssert<FeatureBundle>> BUNDLE_LIST = InstanceOfAssertFactories
5259
.list(FeatureBundle.class);

org.osgi.test.assertj.feature/src/main/java/org/osgi/test/assertj/feature/AbstractFeatureBundleAssert.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.Map;
2222

23+
import org.assertj.core.api.AbstractObjectAssert;
2324
import org.assertj.core.api.InstanceOfAssertFactories;
2425
import org.assertj.core.api.InstanceOfAssertFactory;
2526
import org.assertj.core.api.MapAssert;
@@ -30,7 +31,7 @@
3031
* by CustomAssertionGenerator.
3132
*/
3233
public abstract class AbstractFeatureBundleAssert<S extends AbstractFeatureBundleAssert<S, A>, A extends FeatureBundle>
33-
extends AbstractFeatureArtifactAssert<S, A> {
34+
extends AbstractObjectAssert<S, A> {
3435

3536
/**
3637
* Creates a new <code>{@link AbstractFeatureBundleAssert}</code> to make
@@ -42,6 +43,12 @@ protected AbstractFeatureBundleAssert(A actual, Class<S> selfType) {
4243
super(actual, selfType);
4344
}
4445

46+
public IDAssert hasIDThat() {
47+
isNotNull();
48+
return IDAssert.assertThat(actual.getID())
49+
.as(actual + ".id");
50+
}
51+
4552
@SuppressWarnings("rawtypes")
4653
static InstanceOfAssertFactory<Map, MapAssert<String, Object>> METADATA_MAP = InstanceOfAssertFactories
4754
.map(String.class, Object.class);

org.osgi.test.assertj.feature/src/main/java/org/osgi/test/assertj/feature/FeaturesConditions.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static Condition<Feature> complete() {
6060
}
6161

6262
static Condition<Feature> descriptionEmpty() {
63-
return new Condition<>(f -> !f.getDescription()
63+
return new Condition<>(f -> f.getDescription() == null || !f.getDescription()
6464
.isPresent(), "description <isEmpty>");
6565
}
6666

@@ -101,7 +101,7 @@ static Condition<Feature> licenseMatches(String pattern) {
101101
}
102102

103103
static Condition<Feature> licenseEmpty() {
104-
return new Condition<>(f -> !f.getLicense()
104+
return new Condition<>(f -> f.getLicense() == null || !f.getLicense()
105105
.isPresent(), "license <isEmpty>");
106106
}
107107

@@ -124,7 +124,7 @@ static Condition<Feature> nameMatches(String pattern) {
124124
}
125125

126126
static Condition<Feature> nameEmpty() {
127-
return new Condition<>(f -> !f.getName()
127+
return new Condition<>(f -> f.getName() == null || !f.getName()
128128
.isPresent(), "name <isEmpty>");
129129
}
130130

@@ -151,7 +151,7 @@ static Condition<Feature> vendorMatches(String pattern) {
151151
}
152152

153153
static Condition<Feature> vendorEmpty() {
154-
return new Condition<>(f -> !f.getVendor()
154+
return new Condition<>(f -> f.getVendor() == null || !f.getVendor()
155155
.isPresent(), "vendor <isEmpty>");
156156
}
157157

@@ -291,7 +291,7 @@ static Condition<FeatureExtension> nameNull() {
291291
}
292292

293293
static Condition<FeatureExtension> type(final FeatureExtension.Type type) {
294-
return kind(null);
294+
return new Condition<>(f -> Objects.equals(f.getType(), type), "type <%s>", type);
295295
}
296296

297297
static Condition<FeatureExtension> typeArtifacts() {

org.osgi.test.assertj.feature/src/test/java/org/osgi/test/assertj/feature/FeaturesConditionsAssertTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void testComplete() throws Exception {
6666
// assertion fail
6767
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> Assertions.assertThat(feature)
6868
.isComplete())
69-
.withMessage(format("%nExpecting:%n " + featureName + "%nto be complete"));
69+
.withMessage(format("%nExpecting actual:%n " + featureName + "%nto be complete"));
7070
}
7171

7272
@Test
@@ -89,7 +89,7 @@ void testNotComplete() throws Exception {
8989
// assertion fail
9090
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> Assertions.assertThat(feature)
9191
.isNotComplete())
92-
.withMessage(format("%nExpecting:%n " + featureName + "%nnot to be complete"));
92+
.withMessage(format("%nExpecting actual:%n " + featureName + "%nnot to be complete"));
9393

9494
}
9595

@@ -108,12 +108,12 @@ void testNameNull() throws Exception {
108108
when(feature.getName()).thenReturn(Optional.of("featureName"));
109109

110110
// condition fail
111-
failingHas(FeaturesConditions.FeatureConditions.nameEmpty(), feature, "name <null>");
111+
failingHas(FeaturesConditions.FeatureConditions.nameEmpty(), feature, "name <isEmpty>");
112112

113113
// assertion fail
114114
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> Assertions.assertThat(feature)
115115
.hasNameEmpty())
116-
.withMessage(format("%nExpecting:%n " + featureName + "%nto have:%n name <null>"));
116+
.withMessage(format("%nExpecting actual:%n " + featureName + "%nto have name <isEmpty>"));
117117
}
118118
}
119119
// TODO: All additional tests after specification is more stable.

org.osgi.test.junit5.cm/src/test/java/org/osgi/test/junit5/cm/test/ConfigAnnotationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public void oldWay(@InjectService
6464

6565
Configuration c = ca.createFactoryConfiguration(FACTORY_CONFIGURATION_PID);
6666
c.update(Dictionaries.dictionaryOf("foo", "bar"));
67-
67+
// test
68+
c.delete();
6869
}
6970

7071
// START TESTS

0 commit comments

Comments
 (0)