
hope.kola.contract.assertj.model.AssertSegment Maven / Gradle / Ivy
package hope.kola.contract.assertj.model;
import com.squareup.javapoet.CodeBlock;
import java.util.ArrayList;
import java.util.List;
public class AssertSegment {
protected final String match;
protected List arguments = new ArrayList<>();
public AssertSegment(String match) {
this.match = match;
}
public String match() {
return match;
}
public AssertSegment argument(DynamicProperty argument) {
this.arguments.add(argument);
return this;
}
/**
* Get the assert logic of this segment
*
* @return code block
*/
public CodeBlock.Builder code() {
if (arguments == null || arguments.isEmpty()) {
return CodeBlock.builder().add("$L()", match);
} else {
CodeBlock.Builder cbb = CodeBlock.builder();
cbb.add("$L(", match);
final int size = arguments.size();
int idx = 1;
for (final DynamicProperty each : arguments) {
cbb.add(each.code().build());
if (idx != size) {
cbb.add(", ");
}
idx++;
}
cbb.add(")");
return cbb;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy