mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
改进ContentType.get忽略空格
This commit is contained in:
@@ -14,9 +14,12 @@ package org.dromara.hutool.http;
|
||||
|
||||
import org.dromara.hutool.core.util.CharsetUtil;
|
||||
import org.dromara.hutool.http.meta.ContentType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* ContentType 单元测试
|
||||
*
|
||||
@@ -26,6 +29,15 @@ public class ContentTypeTest {
|
||||
@Test
|
||||
public void testBuild() {
|
||||
final String result = ContentType.build(ContentType.JSON, CharsetUtil.UTF_8);
|
||||
Assertions.assertEquals("application/json;charset=UTF-8", result);
|
||||
assertEquals("application/json;charset=UTF-8", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetWithLeadingSpace() {
|
||||
final String json = " {\n" +
|
||||
" \"name\": \"hutool\"\n" +
|
||||
" }";
|
||||
final ContentType contentType = ContentType.get(json);
|
||||
assertEquals(ContentType.JSON, contentType);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user