<commit_before>package lv.ctco.cukesrest.internal;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.isEmptyString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;

import java.util.Map;

import org.hamcrest.Matchers;

import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.response.ResponseBody;

import lv.ctco.cukesrest.CukesOptions;
import lv.ctco.cukesrest.internal.context.GlobalWorldFacade;
import lv.ctco.cukesrest.internal.context.InflateContext;
import lv.ctco.cukesrest.internal.json.JsonParser;
import lv.ctco.cukesrest.internal.matchers.ArrayWithSizeMatcher;
import lv.ctco.cukesrest.internal.matchers.ContainsPattern;
import lv.ctco.cukesrest.internal.matchers.EndsWithRegexp;
import lv.ctco.cukesrest.internal.matchers.EqualToIgnoringTypeMatcher;
import lv.ctco.cukesrest.internal.matchers.JsonMatchers;
import lv.ctco.cukesrest.internal.matchers.MiscMatchers;
import lv.ctco.cukesrest.internal.matchers.OfTypeMatcher;
import lv.ctco.cukesrest.internal.switches.SwitchedBy;

@Singleton
@SwitchedBy(CukesOptions.ASSERTIONS_DISABLED)
@InflateContext
public class AssertionFacadeImpl implements AssertionFacade {

    @Inject
    private GlobalWorldFacade world;

    @Inject
    private JsonParser jsonParser;

    @Inject
    ResponseFacade facade;

    @Override
    public void bodyEqualTo(String body) {
        this.facade.response().then().body(equalTo(body));
    }

    @Override
    public void bodyNotEqualTo(String body) {
        this.facade.response().then().body(not(equalTo(body)));
    }

    @Override
    public void bodyNotEmpty() {
        this.facade.response().then().body(not(isEmptyOrNullString()));
    }

    @Override
    public void bodyContains(String body) {
        this.facade.response().then().body(containsString(body));
    }

    @Override
    public void bodyDoesNotContain(String body) {
        this.facade.response().then().body(not(containsString(body)));
    }

    @Override
    public void headerIsEmpty(String headerName) {
        this.facade.response().then().header(headerName, isEmptyString());
    }

    @Override
    public void headerIsNotEmpty(String headerName) {
        this.facade.response().then().header(headerName, not(isEmptyString()));
    }

    @Override
    public void statusCodeIs(final int statusCode) {

        final Response response = this.facade.response();
        final String body = response.getBody().print();

        /*
         * This is a temporary hack due to:
         * https://github.com/rest-assured/rest-assured/issues/781
         */
        try {
            response.then().statusCode(statusCode);
        } catch (AssertionError error) {
            if (this.world.getBoolean(CukesOptions.ASSERTS_STATUS_CODE_DISPLAY_BODY, false)) {
                final Optional<String> maxSizeOptional = this.world.get(CukesOptions.ASSERTS_STATUS_CODE_MAX_SIZE);<commit_msg>Unnecessary print to console removed<commit_after>package lv.ctco.cukesrest.internal;

import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.response.ResponseBody;
import lv.ctco.cukesrest.CukesOptions;
import lv.ctco.cukesrest.internal.context.GlobalWorldFacade;
import lv.ctco.cukesrest.internal.context.InflateContext;
import lv.ctco.cukesrest.internal.json.JsonParser;
import lv.ctco.cukesrest.internal.matchers.ArrayWithSizeMatcher;
import lv.ctco.cukesrest.internal.matchers.ContainsPattern;
import lv.ctco.cukesrest.internal.matchers.EndsWithRegexp;
import lv.ctco.cukesrest.internal.matchers.EqualToIgnoringTypeMatcher;
import lv.ctco.cukesrest.internal.matchers.JsonMatchers;
import lv.ctco.cukesrest.internal.matchers.MiscMatchers;
import lv.ctco.cukesrest.internal.matchers.OfTypeMatcher;
import lv.ctco.cukesrest.internal.switches.SwitchedBy;
import org.hamcrest.Matchers;

import java.util.Map;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.isEmptyString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;

@Singleton
@SwitchedBy(CukesOptions.ASSERTIONS_DISABLED)
@InflateContext
public class AssertionFacadeImpl implements AssertionFacade {

    @Inject
    private GlobalWorldFacade world;

    @Inject
    private JsonParser jsonParser;

    @Inject
    ResponseFacade facade;

    @Override
    public void bodyEqualTo(String body) {
        this.facade.response().then().body(equalTo(body));
    }

    @Override
    public void bodyNotEqualTo(String body) {
        this.facade.response().then().body(not(equalTo(body)));
    }

    @Override
    public void bodyNotEmpty() {
        this.facade.response().then().body(not(isEmptyOrNullString()));
    }

    @Override
    public void bodyContains(String body) {
        this.facade.response().then().body(containsString(body));
    }

    @Override
    public void bodyDoesNotContain(String body) {
        this.facade.response().then().body(not(containsString(body)));
    }

    @Override
    public void headerIsEmpty(String headerName) {
        this.facade.response().then().header(headerName, isEmptyString());
    }

    @Override
    public void headerIsNotEmpty(String headerName) {
        this.facade.response().then().header(headerName, not(isEmptyString()));
    }

    @Override
    public void statusCodeIs(final int statusCode) {

        final Response response = this.facade.response();
        final String body = response.getBody().asString();

        /*
         * This is a temporary hack due to:
         * https://github.com/rest-assured/rest-assured/issues/781
         */
        try {
            response.then().statusCode(statusCode);
        } catch (AssertionError error) {
            if (this.world.getBoolean(CukesOptions.ASSERTS_STATUS_CODE_DISPLAY_BODY, false)) {
                final Optional<String> maxSizeOptional = this.world.get(CukesOptions.ASSERTS_STATUS_CODE_MAX_SIZE);
{'fraction_non_alphanumeric': 0.10751374465485644, 'fraction_numerical': 0.0009163103237629811, 'mean_word_length': 4.080682699767261, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '681769', 'n_tokens_mistral': 2071, 'n_tokens_neox': 2010, 'n_words': 323}