spring-boot-realworld-examp.../src/test/java/io/spring/core/article/ArticleTest.java
2021-03-16 17:17:06 +08:00

41 lines
1.2 KiB
Java

package io.spring.core.article;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.Arrays;
import org.junit.Test;
public class ArticleTest {
@Test
public void should_get_right_slug() {
Article article = new Article("a new title", "desc", "body", Arrays.asList("java"), "123");
assertThat(article.getSlug(), is("a-new-title"));
}
@Test
public void should_get_right_slug_with_number_in_title() {
Article article = new Article("a new title 2", "desc", "body", Arrays.asList("java"), "123");
assertThat(article.getSlug(), is("a-new-title-2"));
}
@Test
public void should_get_lower_case_slug() {
Article article = new Article("A NEW TITLE", "desc", "body", Arrays.asList("java"), "123");
assertThat(article.getSlug(), is("a-new-title"));
}
@Test
public void should_handle_other_language() {
Article article = new Article("中文:标题", "desc", "body", Arrays.asList("java"), "123");
assertThat(article.getSlug(), is("中文-标题"));
}
@Test
public void should_handle_commas() {
Article article = new Article("what?the.hell,w", "desc", "body", Arrays.asList("java"), "123");
assertThat(article.getSlug(), is("what-the-hell-w"));
}
}