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

com.github.httpmock.request.RequestCounter Maven / Gradle / Ivy

The newest version!
package com.github.httpmock.request;

import com.github.httpmock.MockReplayListener;
import com.github.httpmock.dto.ConfigurationDto;
import com.github.httpmock.dto.RequestDto;

import java.util.Map;

import static com.github.httpmock.util.CollectionUtil.emptyMap;

public class RequestCounter implements MockReplayListener {

	private Map counts;

	public RequestCounter() {
		counts = emptyMap();
	}

	public void count(RequestDto request) {
		if (counts.get(request) == null) {
			counts.put(request, 1);
		} else {
			counts.put(request, counts.get(request) + 1);
		}
	}

	public int getCount(RequestDto requestDto) {
		Integer num = counts.get(requestDto);
		if (num == null)
			return 0;
		return num;
	}

	@Override
	public void onReplay(ConfigurationDto configuration) {
		count(configuration.getRequest());
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy