com.noenv.wiremongo.mapping.find.FindOne 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.find;
import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.find.FindOneCommand;
import com.noenv.wiremongo.mapping.WithQuery;
import com.noenv.wiremongo.matching.Matcher;
import io.vertx.core.json.JsonObject;
import static com.noenv.wiremongo.matching.EqualsMatcher.equalTo;
public class FindOne extends WithQuery {
private Matcher fields;
public FindOne() {
super("findOne");
}
public FindOne(JsonObject json) {
super(json);
fields = Matcher.create(json.getJsonObject("fields"));
}
@Override
public FindOne returns(final JsonObject response) {
return super.stub(c -> null == response ? null : response.copy());
}
@Override
public boolean matches(Command cmd) {
if (!super.matches(cmd)) {
return false;
}
if (!(cmd instanceof FindOneCommand)) {
return false;
}
FindOneCommand c = (FindOneCommand) cmd;
return fields == null || fields.matches(c.getFields());
}
@Override
protected JsonObject parseResponse(Object jsonValue) {
return (JsonObject) jsonValue;
}
public FindOne withFields(JsonObject fields) {
return withFields(equalTo(fields));
}
public FindOne withFields(Matcher fields) {
this.fields = fields;
return self();
}
}