Skip to content

Instantly share code, notes, and snippets.

@meza
Created June 7, 2013 14:43
Show Gist options
  • Save meza/5729760 to your computer and use it in GitHub Desktop.
Save meza/5729760 to your computer and use it in GitHub Desktop.
private String getCreateContentForm(String contentType) {
if ("article".equals(contentType)) {
return createArticleForm();
}
if ("audio".equals(contentType)) {
return createAudioForm();
}
if ("cartoon".equals(contentType)) {
return createCartoonForm();
}
if ("competition".equals(contentType)) {
return createCompetitionForm();
}
throw new IllegalArgumentException("No such content type");
}
@meza
Copy link
Author

meza commented Jun 7, 2013

For anyone stumbling on this thread:

The following examples are modified for the sake of the gist, but the end solution is something like:

public enum ContentType {
    ARTICLE("article"),
    AUDIO("audio"),
    CARTOON("cartoon"),
    COMPETITION("competition");

    private String label;

    ContentTypeForm(String label) {
        this.label = label;
    }

    public String toString() {
        return label;
    }

    public String formPostData() {

        switch (this) {
            case ARTICLE:
                return createArticleFormPostData();
            case AUDIO:
                return createAudioFormPostData();
            case CARTOON:
                return createCartoonFormPostData();
            case COMPETITION:
                return createCompetitionFormPostData();
            default:
                throw new IllegalArgumentException("No such content type");

        }
    }
}

As Cucumber can use ENUMS as parameters, the usage follows:

@When("^I have launched a new \"([^\"]*)\" page$")
public void iHaveLaunchedANewPage(ContentType contentType) {
    String contentFormData = contentType.formPostData();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment