Skip to content

Commit

Permalink
Test now checks for the order of the files listed
Browse files Browse the repository at this point in the history
  • Loading branch information
adoble committed Aug 22, 2024
1 parent 0e9f390 commit 1c76433
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/test/java/org/doble/adr/CommandListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
Expand All @@ -13,6 +14,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class CommandListTest {
Expand Down Expand Up @@ -44,9 +46,9 @@ public void setUp() throws Exception {
.build();

// Initialize up the directory structure
String[] args = {"init"};
String[] args = { "init" };
int exitCode = ADR.run(args, env);
assertEquals(exitCode, 0);
assertEquals(exitCode, 0);
}

@AfterEach
Expand All @@ -67,10 +69,11 @@ public void testList() throws Exception {

// Create some ADRs
for (int i = 0; i < testData.length; i++) {
assertEquals(ADR.run(TestUtilities.argify(testData[i]), env), 0);;
assertEquals(ADR.run(TestUtilities.argify(testData[i]), env), 0);
;
}

//Catch the output
// Catch the output
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream testOut = new PrintStream(baos);
Environment localEnv = new Environment.Builder(fileSystem)
Expand All @@ -81,11 +84,11 @@ public void testList() throws Exception {
.editorRunner(new TestEditorRunner())
.build();


int exitCode = ADR.run(TestUtilities.argify("list"), localEnv);
assertEquals(exitCode, 0);

String[] expectedFiles = {
"0001-record-architecture-decisions.md",
"0002-an-adr.md",
"0003-yet-another-adr.md",
"0004-this-adr-is-going-to-be-linked-to.md",
Expand All @@ -94,8 +97,11 @@ public void testList() throws Exception {
};

String list = new String(baos.toByteArray());
for (String expected : expectedFiles) {
assertTrue(list.contains(expected));
}
String[] list_array = list.split("\n");
list_array = Arrays.stream(list_array).map(String::trim).toArray(String[]::new);

assertArrayEquals(expectedFiles, list_array);

}

}

0 comments on commit 1c76433

Please sign in to comment.