Created
May 9, 2013 04:09
-
-
Save mia-0032/5545502 to your computer and use it in GitHub Desktop.
PlayFramework2.0でHelloWorld+UnitTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@(title: String, message: String) | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>@title</title> | |
</head> | |
<body> | |
<p>@message</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers; | |
import play.mvc.*; | |
import views.html.*; | |
public class HelloWorld extends Controller { | |
public static Result index() { | |
return ok("<b>Hello World</b>").as("text/html"); | |
} | |
public static Result fetchTemplate(){ | |
return ok(hello.render("タイトルは未定", "こんにちは、世界")); | |
} | |
public int getNumber(){ | |
return 1; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import controllers.HelloWorld; | |
import controllers.routes; | |
import org.junit.*; | |
import play.mvc.*; | |
import play.test.*; | |
import play.libs.F.*; | |
import static org.fest.assertions.Assertions.assertThat; | |
import static play.test.Helpers.*; | |
import static org.fest.assertions.Assertions.*; | |
public class HelloWorldTest { | |
@Test | |
public void indexメソッドで想定文字列が返ってくる(){ | |
Result result = callAction( | |
routes.ref.HelloWorld.index() | |
); | |
assertThat(status(result)).isEqualTo(OK); | |
assertThat(contentType(result)).isEqualTo("text/html"); | |
assertThat(contentAsString(result)).contains("<b>Hello World</b>"); | |
} | |
@Test | |
public void fetchTemplateメソッドで想定文字列が返ってくる(){ | |
Result result = callAction( | |
routes.ref.HelloWorld.fetchTemplate() | |
); | |
assertThat(status(result)).isEqualTo(OK); | |
assertThat(contentType(result)).isEqualTo("text/html"); | |
assertThat(contentAsString(result)).contains("<title>タイトルは未定</title>"); | |
assertThat(contentAsString(result)).contains("こんにちは、世界"); | |
} | |
@Test | |
public void getNumberメソッドで想定数値が返ってくる(){ | |
HelloWorld hw = new HelloWorld(); | |
int num = hw.getNumber(); | |
assertThat(num).isEqualTo(1); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET / controllers.HelloWorld.index() | |
GET /template controllers.HelloWorld.fetchTemplate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment