将 2 个数组与其中的 kafka 生产者记录进行比较时,我的 Junit 测试失败。失败是阵列后的一个额外空间。
预期的:
java.util.ArrayList<[ProducerRecord(topic=producer-test, partition=null,
headers=RecordHeaders(headers = [], isReadOnly = false), key=0,
value=Message: test-message,
Number: 0, timestamp=null), ProducerRecord(topic=producer-test,
partition=null, headers=RecordHeaders(headers = [], isReadOnly = false),
key=1, value=Message: test-message,
Number: 1, timestamp=null)]>
实际的:
java.util.ArrayList<[ProducerRecord(topic=producer-test, partition=null,
headers=RecordHeaders(headers = [], isReadOnly = false), key=0,
value=Message: test-message,
Number: 0, timestamp=null), ProducerRecord(topic=producer-test,
partition=null, headers=RecordHeaders(headers = [], isReadOnly = false),
key=1, value=Message: test-message,
Number: 1, timestamp=null)]>
IDE 告诉我唯一的区别是在 Expected 中的 arrayList 末尾后面有一个空格,您可以通过突出显示末尾来查看。到底是怎么回事?!
编辑:
这是其他一些代码
List<ProducerRecord<Integer, TestObj>> history = producer.history();
//To be inserted into expected
TestObj obj0 = new TestObj("test-message", 0);
TestObj obj1 = new TestObj("test-message", 1);
//new arraylist is needed or else the lists have slightly different types for some reason
List<ProducerRecord<Integer, TestObj>> expected = new ArrayList<ProducerRecord<Integer, TestObj>>(Arrays.asList(
new ProducerRecord<Integer, TestObj>("producer-test", 0, obj0),
new ProducerRecord<Integer, TestObj>("producer-test", 1, obj1)
));
Assert.assertEquals("Sent didn't match expected!", expected, history);
不负相思意
相关分类