AllSameStrategy extends AbstractMergeStrategy { @Override public Single<Boolean> canMerge(XMLChunkMeta meta) { return Single.defer(() -> { if (getParents() == null || getParents().equals(meta.getParents())) { return Single.just(Boolean.TRUE); } else { return Single.just(Boolean.FALSE); } }); }  @Override Single<Boolean> canMerge(XMLChunkMeta meta);  }
@Test public void canMerge(TestContext context) { XMLChunkMeta cm2 = new XMLChunkMeta(Arrays.asList(new XMLStartElement("other")), 10, 20); XMLChunkMeta cm3 = new XMLChunkMeta(Arrays.asList(new XMLStartElement("pre", "root")), 10, 20); XMLChunkMeta cm4 = new XMLChunkMeta(Arrays.asList(new XMLStartElement(null, "root", new String[] { "" }, new String[] { "uri" })), 10, 20); Async async = context.async(); MergeStrategy strategy = new AllSameStrategy(); strategy.canMerge(cm) .doOnSuccess(context::assertTrue) .flatMapCompletable(v -> strategy.init(cm)) .andThen(strategy.canMerge(cm)) .doOnSuccess(context::assertTrue) .flatMap(v -> strategy.canMerge(cm2)) .doOnSuccess(context::assertFalse) .flatMap(v -> strategy.canMerge(cm3)) .doOnSuccess(context::assertFalse) .flatMap(v -> strategy.canMerge(cm4)) .doOnSuccess(context::assertFalse) .subscribe(v -> { async.complete(); }, context::fail); }