|
| 1 | +package io.cucumber.docstring; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import static org.hamcrest.CoreMatchers.equalTo; |
| 6 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 7 | + |
| 8 | +class DocStringFormatterTest { |
| 9 | + |
| 10 | + @Test |
| 11 | + void should_print_docstring_with_content_type() { |
| 12 | + DocString docString = DocString.create("{\n" + |
| 13 | + " \"key1\": \"value1\",\n" + |
| 14 | + " \"key2\": \"value2\",\n" + |
| 15 | + " \"another1\": \"another2\"\n" + |
| 16 | + "}\n", |
| 17 | + "application/json"); |
| 18 | + |
| 19 | + DocStringFormatter formatter = DocStringFormatter.builder().build(); |
| 20 | + String format = formatter.format(docString); |
| 21 | + assertThat(format, equalTo( |
| 22 | + "\"\"\"application/json\n" + |
| 23 | + "{\n" + |
| 24 | + " \"key1\": \"value1\",\n" + |
| 25 | + " \"key2\": \"value2\",\n" + |
| 26 | + " \"another1\": \"another2\"\n" + |
| 27 | + "}\n" + |
| 28 | + "\"\"\"\n")); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + void should_print_docstring_without_content_type() { |
| 33 | + DocString docString = DocString.create("{\n" + |
| 34 | + " \"key1\": \"value1\",\n" + |
| 35 | + " \"key2\": \"value2\",\n" + |
| 36 | + " \"another1\": \"another2\"\n" + |
| 37 | + "}\n"); |
| 38 | + |
| 39 | + DocStringFormatter formatter = DocStringFormatter.builder().build(); |
| 40 | + String format = formatter.format(docString); |
| 41 | + assertThat(format, equalTo( |
| 42 | + "\"\"\"\n" + |
| 43 | + "{\n" + |
| 44 | + " \"key1\": \"value1\",\n" + |
| 45 | + " \"key2\": \"value2\",\n" + |
| 46 | + " \"another1\": \"another2\"\n" + |
| 47 | + "}\n" + |
| 48 | + "\"\"\"\n")); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + void should_print_docstring_with_indentation() { |
| 53 | + DocString docString = DocString.create("Hello", |
| 54 | + "text/plain"); |
| 55 | + |
| 56 | + DocStringFormatter formatter = DocStringFormatter.builder().indentation(" ").build(); |
| 57 | + String format = formatter.format(docString); |
| 58 | + assertThat(format, equalTo( |
| 59 | + " \"\"\"text/plain\n" + |
| 60 | + " Hello\n" + |
| 61 | + " \"\"\"\n")); |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments