Skip to content

Commit 7272013

Browse files
authored
Merge pull request #81 from rabbitmq/unwrap-byte-array-from-binary-application-property
Unwrap byte array from binary application property
2 parents 4822ac1 + 66992a7 commit 7272013

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/main/java/com/rabbitmq/client/amqp/impl/AmqpMessage.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,12 @@ public String replyToGroupId() {
284284

285285
@Override
286286
public Object property(String key) {
287-
return returnFromDelegate(m -> m.property(key));
287+
Object value = returnFromDelegate(m -> m.property(key));
288+
if (value instanceof Binary) {
289+
return ((Binary) value).asByteArray();
290+
} else {
291+
return value;
292+
}
288293
}
289294

290295
@Override

src/test/java/com/rabbitmq/client/amqp/impl/Assertions.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.rabbitmq.client.amqp.Message;
2424
import java.time.Duration;
2525
import java.util.List;
26-
import java.util.Objects;
2726
import java.util.concurrent.CountDownLatch;
2827
import java.util.concurrent.TimeUnit;
2928
import java.util.concurrent.atomic.AtomicReference;
@@ -245,9 +244,7 @@ MessageAssert hasCorrelationId(Object id) {
245244
}
246245

247246
MessageAssert hasUserId(byte[] userId) {
248-
isNotNull();
249-
org.assertj.core.api.Assertions.assertThat(actual.userId()).isEqualTo(userId);
250-
return this;
247+
return hasField("user-id", actual.userId(), userId);
251248
}
252249

253250
MessageAssert hasTo(String to) {
@@ -317,11 +314,11 @@ MessageAssert hasProperty(String key, Object value) {
317314
}
318315
isNotNull();
319316
hasProperty(key);
320-
if (!value.equals(this.actual.property(key))) {
321-
fail(
322-
"Message should have property '%s = %s' but has '%s = %s'",
323-
key, value, key, this.actual.property(key));
324-
}
317+
org.assertj.core.api.Assertions.assertThat(this.actual.property(key))
318+
.describedAs(
319+
"Message should have property '%s = %s' but has '%s = %s'",
320+
key, value, key, this.actual.property(key))
321+
.isEqualTo(value);
325322
return this;
326323
}
327324

@@ -339,11 +336,11 @@ MessageAssert hasAnnotation(String key, Object value) {
339336
}
340337
isNotNull();
341338
hasAnnotation(key);
342-
if (!value.equals(this.actual.annotation(key))) {
343-
fail(
344-
"Message should have annotation '%s = %s' but has '%s = %s'",
345-
key, value, key, this.actual.annotation(key));
346-
}
339+
org.assertj.core.api.Assertions.assertThat(this.actual.annotation(key))
340+
.describedAs(
341+
"Message should have annotation '%s = %s' but has '%s = %s'",
342+
key, value, key, this.actual.annotation(key))
343+
.isEqualTo(value);
347344
return this;
348345
}
349346

@@ -357,9 +354,9 @@ MessageAssert doesNotHaveAnnotation(String key) {
357354

358355
private MessageAssert hasField(String fieldLabel, Object value, Object expected) {
359356
isNotNull();
360-
if (!Objects.equals(value, expected)) {
361-
fail("Field '%s' should be '%s' but is '%s'", fieldLabel, expected, value);
362-
}
357+
org.assertj.core.api.Assertions.assertThat(value)
358+
.describedAs("Field '%s' should be '%s' but is '%s'", fieldLabel, expected, value)
359+
.isEqualTo(expected);
363360
return this;
364361
}
365362
}

src/test/java/com/rabbitmq/client/amqp/impl/SourceFiltersTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import net.jqwik.api.arbitraries.ArrayArbitrary;
4444
import net.jqwik.api.arbitraries.IntegerArbitrary;
4545
import net.jqwik.api.arbitraries.StringArbitrary;
46-
import org.apache.qpid.protonj2.types.Binary;
4746
import org.apache.qpid.protonj2.types.Symbol;
4847
import org.junit.jupiter.api.*;
4948

@@ -310,7 +309,7 @@ void filterExpressionApplicationProperties() {
310309
msgs.forEach(m -> assertThat(m).hasProperty("foo", uuid));
311310

312311
msgs = consume(messageCount, options -> options.property("foo", binary));
313-
msgs.forEach(m -> assertThat(m).hasProperty("foo", new Binary(binary)));
312+
msgs.forEach(m -> assertThat(m).hasProperty("foo", binary));
314313

315314
msgs = consume(messageCount, options -> options.property("foo", "baz"));
316315
msgs.forEach(m -> assertThat(m).hasProperty("foo", "baz"));

0 commit comments

Comments
 (0)