com.noenv.wiremongo.mapping.WithQuery 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;
import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.WithQueryCommand;
import com.noenv.wiremongo.mapping.collection.WithCollection;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;
import static com.noenv.wiremongo.matching.EqualsMatcher.equalTo;
public abstract class WithQuery> extends WithCollection {
private Matcher query;
public WithQuery(String method) {
super(method);
}
public WithQuery(JsonObject json) {
super(json);
query = Matcher.create(json.getJsonObject("query"));
}
public C withQuery(JsonObject query) {
return withQuery(equalTo(query));
}
public C withQuery(Matcher query) {
this.query = query;
return self();
}
@Override
public boolean matches(Command cmd) {
if (!super.matches(cmd)) {
return false;
}
if (!(cmd instanceof WithQueryCommand)) {
return false;
}
WithQueryCommand c = (WithQueryCommand) cmd;
return query == null || query.matches(c.getQuery());
}
}