LoginSignup
0
1

More than 5 years have passed since last update.

spockメモ

Posted at

spockメモ

コード

@Data
@AllArgsConstructor
public class Person {
    private String name;
    private String nickName;
    private Sex Sex;
}

public class PersonFactory {
    public static Person get(String name) {
        switch (name) {
            case "nagasawa":
                return new Person("nagasawa", "sparrow", Sex.MALE);
            case "misawa":
                return new Person("misawa", "sparrow", Sex.MALE);
            case "naruse":
                return new Person("naruse", "head", Sex.FAMALE);
            default:
                return new Person("NONE", "NONE", Sex.MALE);
        }
    }
}
public enum Sex {
    MALE, FAMALE
}

テストコード

class PersonFactoryTest extends spock.lang.Specification {

    @Unroll
    def "#nameの時はあだ名が#expectedになる"() {
        expect:
        PersonFactory.get(name).nickName == expected

        where:
        name       | expected
        "misawa"   | "sparrow"
        "nagasawa" | "jonny"
        "naruse"   | "head"
    }
}

実行結果

s

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1