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

io.github.cweijan.mock.jupiter.MockInstanceHolder Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package io.github.cweijan.mock.jupiter;

import io.github.cweijan.mock.Mocker;
import io.github.cweijan.mock.context.HttpMockContext;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cweijan
 * @since 2020/05/25 18:17
 */
public class MockInstanceHolder {

    private final HttpMockContext context;
    private final Map instanceMap;

    public MockInstanceHolder(String scheme, String host, Integer port) {
        this.context =new HttpMockContext(scheme, host, port);
        this.instanceMap=new HashMap<>();
    }

    @SuppressWarnings("unchecked")
    public  T getInstance(Class instanceClass){

        return (T) instanceMap.computeIfAbsent(
                instanceClass.getSimpleName()+"_"+ context.getScheme()+"_"+context.getHost()+"_"+context.getPort(),
                key -> Mocker.api(instanceClass, context)
        );
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy