All Downloads are FREE. Search and download functionalities are using the official Maven repository.

by.stub.yaml.StubResponseBuilder Maven / Gradle / Ivy

There is a newer version: 3.3.0
Show newest version
package by.stub.yaml;

import by.stub.utils.ReflectionUtils;
import by.stub.yaml.stubs.StubResponse;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author Alexander Zagniotov
 * @since 4/14/13, 4:54 PM
 */
final class StubResponseBuilder implements StubBuilder {

   private final Map fieldNameAndValues;
   private String status;
   private String body;
   private File file;
   private String latency;
   private Map headers;

   StubResponseBuilder() {
      this.status = null;
      this.body = null;
      this.file = null;
      this.latency = null;
      this.headers = new LinkedHashMap<>();
      this.fieldNameAndValues = new HashMap<>();
   }

   @Override
   public void store(final String fieldName, final Object fieldValue) {
      fieldNameAndValues.put(fieldName.toLowerCase(), fieldValue);
   }

   @Override
   public StubResponse build() throws Exception {
      ReflectionUtils.injectObjectFields(this, fieldNameAndValues);
      return new StubResponse(status, body, file, latency, headers);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy