com.greenpepper.maven.plugin.spy.SpySystemUnderDevelopment Maven / Gradle / Ivy
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));
}
}