Add Tests for DumpLog

This commit is contained in:
Fuzzlemann 2017-08-17 14:40:53 +02:00
parent 15587946e6
commit 47d97252a6
2 changed files with 47 additions and 7 deletions

View File

@ -17,7 +17,7 @@ public class DumpLog {
* *
* @param header The name of the header * @param header The name of the header
*/ */
void addHeader(String header) { public void addHeader(String header) {
addLine(""); addLine("");
addLine("--- " + header + " ---"); addLine("--- " + header + " ---");
} }
@ -28,7 +28,7 @@ public class DumpLog {
* @param key The key * @param key The key
* @param value The value * @param value The value
*/ */
void add(String key, String value) { public void add(String key, String value) {
addLine(key + ": " + value); addLine(key + ": " + value);
} }
@ -38,7 +38,7 @@ public class DumpLog {
* @param key The key * @param key The key
* @param value The value * @param value The value
*/ */
void add(String key, boolean value) { public void add(String key, boolean value) {
addLine(key + ": " + value); addLine(key + ": " + value);
} }
@ -49,7 +49,7 @@ public class DumpLog {
* @param key The key * @param key The key
* @param value The CharSequences stored in an Iterable * @param value The CharSequences stored in an Iterable
*/ */
void add(String key, Iterable<? extends CharSequence> value) { public void add(String key, Iterable<? extends CharSequence> value) {
addLine(key + ": " + String.join(", ", value)); addLine(key + ": " + String.join(", ", value));
} }
@ -58,7 +58,7 @@ public class DumpLog {
* *
* @param lines The CharSequences stored in an Iterable * @param lines The CharSequences stored in an Iterable
*/ */
void addLines(Iterable<? extends CharSequence> lines) { public void addLines(Iterable<? extends CharSequence> lines) {
lines.forEach(this::addLine); lines.forEach(this::addLine);
} }
@ -67,7 +67,7 @@ public class DumpLog {
* *
* @param lines The lines * @param lines The lines
*/ */
void addLines(CharSequence... lines) { public void addLines(CharSequence... lines) {
Arrays.stream(lines).forEach(this::addLine); Arrays.stream(lines).forEach(this::addLine);
} }
@ -76,7 +76,7 @@ public class DumpLog {
* *
* @param line The content of the line * @param line The content of the line
*/ */
private void addLine(CharSequence line) { public void addLine(CharSequence line) {
lines.add(line == null ? "\n" : line.toString()); lines.add(line == null ? "\n" : line.toString());
} }

View File

@ -0,0 +1,40 @@
package test.java.main.java.com.djrapitops.plan.utilities.dump;
import main.java.com.djrapitops.plan.utilities.file.dump.DumpLog;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
/**
* @author Fuzzlemann
*/
public class DumpLogTest {
@Test
public void testDumpLogCreation() {
DumpLog testLog = new DumpLog();
testLog.addHeader("Test Header");
testLog.add("StringValue", "Test");
testLog.add("BooleanValue", true);
testLog.add("IterableValue", Arrays.asList("Iterable 1", "Iterable 2"));
testLog.addLine(new StringBuilder("CharSequence Test"));
testLog.addLines(new StringBuilder("CharSequences Test"), new StringBuilder("CharSequences Test"));
testLog.addLines(Arrays.asList("Iterable 1", "Iterable 2"));
String expResult = "\n--- Test Header ---\n" +
"StringValue: Test\n" +
"BooleanValue: true\n" +
"IterableValue: Iterable 1, Iterable 2\n" +
"CharSequence Test\n" +
"CharSequences Test\n" +
"CharSequences Test\n" +
"Iterable 1\n" +
"Iterable 2";
String result = testLog.toString();
Assert.assertEquals(expResult, result);
}
}