com.noenv.wiremongo.mapping.collection.WithCollection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-wiremongo Show documentation
Show all versions of vertx-wiremongo Show documentation
Lightweight mongo mocking for Vert.x
package com.noenv.wiremongo.mapping.collection;
import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.collection.WithCollectionCommand;
import com.noenv.wiremongo.mapping.MappingBase;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;
import static com.noenv.wiremongo.matching.EqualsMatcher.equalTo;
public abstract class WithCollection> extends MappingBase {
private Matcher collection;
public WithCollection(String method) {
super(method);
}
public WithCollection(JsonObject json) {
super(json);
collection = Matcher.create(json.getJsonObject("collection"));
}
public C inCollection(String collection) {
return inCollection(equalTo(collection));
}
public C inCollection(Matcher collection) {
this.collection = collection;
return self();
}
@Override
public boolean matches(Command cmd) {
if (!super.matches(cmd)) {
return false;
}
if (!(cmd instanceof WithCollectionCommand)) {
return false;
}
WithCollectionCommand c = (WithCollectionCommand) cmd;
return collection == null || collection.matches(c.getCollection());
}
}