Files
notes_estom/Java/JavaDemo/codedemo/jetty/HttpGetTest.java
2025-09-14 03:49:42 -04:00

56 lines
1.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package cn.aofeng.demo.jetty;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* {@link HttpGet}的单元测试用例。
*
* @author <a href="mailto:aofengblog@163.com">聂勇</a>
*/
public class HttpGetTest {
private HttpServerMock _mock;
private HttpGet _httpGet = new HttpGet();
@Before
public void setUp() throws Exception {
_mock = new HttpServerMock();
}
@After
public void tearDown() throws Exception {
if (null != _mock) {
_mock.stop();
}
}
/**
* 用例响应状态码为200且有响应内容。
*/
@Test
public void testGetSomeThing4Success() throws Exception {
String response = "Hello, The World!";
_mock.start(response, "text/plain");
String content = _httpGet.getSomeThing("http://localhost:9191/hello");
assertEquals(response, content);
}
/**
* 用例响应状态码为非200。
*/
@Test
public void testGetSomeThing4Fail() throws Exception {
String response = "Hello, The World!";
_mock.start(response, "text/plain", 500);
String content = _httpGet.getSomeThing("http://localhost:9191/hello");
assertNull(content);
}
}