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

com.greenpepper.maven.plugin.spy.SpySystemUnderDevelopment Maven / Gradle / Ivy

There is a newer version: 4.2.4
Show newest version
package com.greenpepper.maven.plugin.spy;

import com.greenpepper.reflect.Fixture;
import com.greenpepper.spy.MetaInformation;
import com.greenpepper.systemunderdevelopment.DefaultSystemUnderDevelopment;
import com.greenpepper.util.NameUtils;
import com.greenpepper.util.StringUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class SpySystemUnderDevelopment extends DefaultSystemUnderDevelopment implements MetaInformation {
    private HashMap fixtures = new HashMap();
    private List imports = new ArrayList();

    public HashMap getFixtures() {
        return this.fixtures;
    }

    @Override
    public List getImports() {
        return this.imports;
    }

    public Fixture getFixture(String name, String ... parameters) {
        String fixtureName = this.buildName(name);
        SpyFixture fixture = this.fixtures.get(fixtureName);
        if (fixture == null) {
            fixture = new SpyFixture(fixtureName);
            fixture.setRawName(name);
        }
        fixture.addConstructors(new Constructor(fixtureName, parameters.length));
        if (!StringUtil.isEmpty(name)) {
            this.fixtures.put(fixtureName, fixture);
        }
        return fixture;
    }

    public void addImport(String theImport) {
        this.imports.add(theImport);
    }

    private String buildName(String fixtureName) {
        if (!fixtureName.toLowerCase().endsWith("fixture")) {
            fixtureName = String.valueOf(fixtureName) + " fixture";
        }
        if (fixtureName.indexOf(".") > 0) {
            return NameUtils.toClassName(NameUtils.humanize(fixtureName.substring(fixtureName.lastIndexOf(".") + 1, fixtureName.length())));
        }
        return NameUtils.toClassName(NameUtils.humanize(fixtureName));
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy