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

com.github.dreamhead.moco.resource.reader.ExtractorVariable Maven / Gradle / Ivy

Go to download

Moco is an easy setup stub framework, mainly focusing on testing and integration.

There is a newer version: 1.5.0
Show newest version
package com.github.dreamhead.moco.resource.reader;

import com.github.dreamhead.moco.Request;
import com.github.dreamhead.moco.RequestExtractor;
import com.google.common.base.Optional;

public final class ExtractorVariable implements Variable {
    private final RequestExtractor extractor;

    public ExtractorVariable(final RequestExtractor extractor) {
        this.extractor = extractor;
    }

    @Override
    public Object toTemplateVariable(final Request request) {
        Optional extractContent = extractor.extract(request);
        if (!extractContent.isPresent()) {
            return null;
        }

        T target = extractContent.get();
        if (target instanceof String[]) {
            return target;
        }

        return target.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy