-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jakub Stejskal <[email protected]>
- Loading branch information
Showing
7 changed files
with
381 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
83 changes: 83 additions & 0 deletions
83
test-docs-generator-maven-plugin/src/test/java/io/skodjob/DocGeneratorTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright Skodjob authors. | ||
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). | ||
*/ | ||
package io.skodjob; | ||
|
||
import io.skodjob.annotations.TestDoc; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class DocGeneratorTest { | ||
@Test | ||
void testCreateTableOfSteps() throws IOException { | ||
String expectedFilePath = DocGeneratorTest.class.getClassLoader().getResource("expected-docs.md").getPath(); | ||
String generatedFilePath = "target/io/test.md"; | ||
DocGenerator.generate(TestClass.class, generatedFilePath); | ||
|
||
assertThat(compareFiles(expectedFilePath, generatedFilePath), is(true)); | ||
} | ||
|
||
public static class TestClass { | ||
|
||
@TestDoc( | ||
description = @TestDoc.Desc("Test checking that the application works as expected"), | ||
steps = { | ||
@TestDoc.Step(value = "Create object instance", expected = "Instance of an object is created"), | ||
@TestDoc.Step(value = "Do a magic trick", expected = "Magic trick is done with success"), | ||
@TestDoc.Step(value = "Clean up the test case", expected = "Everything is cleared") | ||
}, | ||
usecases = { | ||
@TestDoc.Usecase(id = "core") | ||
} | ||
) | ||
void testMethodOne() { | ||
|
||
} | ||
|
||
@TestDoc( | ||
description = @TestDoc.Desc("Test checking that the application works as expected. " + | ||
"This is just a little bit longer line, nothing else."), | ||
steps = { | ||
@TestDoc.Step(value = "Create object instance", expected = "Instance of an object is created"), | ||
@TestDoc.Step(value = "Do a magic trick", expected = "Magic trick is done with success"), | ||
@TestDoc.Step(value = "Clean up the test case", expected = "Everything is cleared"), | ||
@TestDoc.Step(value = "Do a magic cleanup check", expected = "Everything magically work") | ||
}, | ||
usecases = { | ||
@TestDoc.Usecase(id = "core"), | ||
@TestDoc.Usecase(id = "core+"), | ||
@TestDoc.Usecase(id = "core+++") | ||
} | ||
) | ||
void testMethodTwo() { | ||
|
||
} | ||
|
||
@TestDoc( | ||
description = @TestDoc.Desc("Test checking that the application works as expected. " + | ||
"This is just a little bit longer line, nothing else."), | ||
steps = { | ||
}, | ||
usecases = { | ||
} | ||
) | ||
void testMethodThree() { | ||
|
||
} | ||
} | ||
|
||
public static boolean compareFiles(String filePath1, String filePath2) throws IOException { | ||
byte[] file1Content = Files.readAllBytes(Paths.get(filePath1)); | ||
byte[] file2Content = Files.readAllBytes(Paths.get(filePath2)); | ||
|
||
return Arrays.equals(file1Content, file2Content); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
test-docs-generator-maven-plugin/src/test/java/io/skodjob/markdown/HeaderTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Skodjob authors. | ||
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). | ||
*/ | ||
package io.skodjob.markdown; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class HeaderTest { | ||
|
||
@Test | ||
void testFirstLevelHeader() { | ||
String text = "Something"; | ||
String expectedHeader = "# Something"; | ||
|
||
assertThat(expectedHeader, is(Header.firstLevelHeader(text))); | ||
} | ||
|
||
@Test | ||
void testSecondLevelHeader() { | ||
String text = "Something"; | ||
String expectedHeader = "## Something"; | ||
|
||
assertThat(expectedHeader, is(Header.secondLevelHeader(text))); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
test-docs-generator-maven-plugin/src/test/java/io/skodjob/markdown/TableTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright Skodjob authors. | ||
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). | ||
*/ | ||
package io.skodjob.markdown; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class TableTest { | ||
|
||
@Test | ||
void testCreateTable() { | ||
// Test data | ||
List<String> headers = Arrays.asList("Name", "Age", "City"); | ||
List<String> rows = Arrays.asList("John Doe | 30 | New York", "Jane Smith | 25 | Los Angeles"); | ||
|
||
// Expected table | ||
String expectedTable = "| Name | Age | City |\n" + | ||
"| - | - | - |\n" + | ||
"John Doe | 30 | New York\n" + | ||
"Jane Smith | 25 | Los Angeles\n"; | ||
|
||
// Call the method | ||
String actualTable = Table.createTable(headers, rows); | ||
|
||
// Assertions | ||
assertThat(actualTable, is(expectedTable)); | ||
} | ||
|
||
@Test | ||
void testCreateTableWithEmptyHeadersAndRows() { | ||
// Test data | ||
List<String> headers = Arrays.asList(); | ||
List<String> rows = Arrays.asList(); | ||
|
||
// Expected table | ||
String expectedTable = ""; | ||
|
||
// Call the method | ||
String actualTable = Table.createTable(headers, rows); | ||
|
||
// Assertions | ||
assertThat(actualTable, is(expectedTable)); | ||
} | ||
|
||
@Test | ||
void testCreateTableWithEmptyRows() { | ||
// Test data | ||
List<String> headers = Arrays.asList("Name", "Age"); | ||
List<String> rows = Arrays.asList(); | ||
|
||
// Expected table | ||
String expectedTable = "| Name | Age |\n" + | ||
"| - | - |\n"; | ||
|
||
// Call the method | ||
String actualTable = Table.createTable(headers, rows); | ||
|
||
// Assertions | ||
assertThat(actualTable, is(expectedTable)); | ||
} | ||
|
||
@Test | ||
void testCreateTableWithSingleHeaderAndRow() { | ||
// Test data | ||
List<String> headers = Arrays.asList("Name"); | ||
List<String> rows = Arrays.asList("John Doe"); | ||
|
||
// Expected table | ||
String expectedTable = "| Name |\n" + | ||
"| - |\n" + | ||
"John Doe\n"; | ||
|
||
// Call the method | ||
String actualTable = Table.createTable(headers, rows); | ||
|
||
// Assertions | ||
assertThat(actualTable, is(expectedTable)); | ||
} | ||
|
||
@Test | ||
void testCreateRow() { | ||
String item1 = "item1"; | ||
String item2 = "item2"; | ||
String item3 = "item3"; | ||
String expectedRow = String.format("| %s | %s | %s |", item1, item2, item3); | ||
|
||
assertThat(Table.createRow(item1, item2, item3), is(expectedRow)); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
test-docs-generator-maven-plugin/src/test/java/io/skodjob/markdown/TextListTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Skodjob authors. | ||
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). | ||
*/ | ||
package io.skodjob.markdown; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class TextListTest { | ||
|
||
@Test | ||
void testCreateTextList() { | ||
// Test data | ||
List<String> objects = Arrays.asList("Apple", "Banana", "Orange"); | ||
|
||
// Expected list | ||
String expectedList = "* Apple\n" + | ||
"* Banana\n" + | ||
"* Orange\n"; | ||
|
||
// Call the method | ||
String actualList = TextList.createUnorderedList(objects); | ||
|
||
// Assertions | ||
assertThat(actualList, is(expectedList)); | ||
} | ||
|
||
@Test | ||
void testCreateTextListWithEmptyList() { | ||
// Test data | ||
List<String> objects = List.of(); | ||
|
||
// Expected list | ||
String expectedList = ""; | ||
|
||
// Call the method | ||
String actualList = TextList.createUnorderedList(objects); | ||
|
||
// Assertions | ||
assertThat(actualList, is(expectedList)); | ||
} | ||
|
||
@Test | ||
void testCreateTextListWithSingleObject() { | ||
// Test data | ||
List<String> objects = List.of("Apple"); | ||
|
||
// Expected list | ||
String expectedList = "* Apple\n"; | ||
|
||
// Call the method | ||
String actualList = TextList.createUnorderedList(objects); | ||
|
||
// Assertions | ||
assertThat(actualList, is(expectedList)); | ||
} | ||
} |
Oops, something went wrong.