Skip to content

Commit d70840d

Browse files
committed
a reformat code
1 parent d25344f commit d70840d

File tree

8 files changed

+133
-117
lines changed

8 files changed

+133
-117
lines changed

approvaltests-tests/src/test/java/org/approvaltests/combinations/PairWiseTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,30 @@ public class PairWiseTest
3030
@Test
3131
void forTable()
3232
{
33-
String [] headers = {"Number of Parameters", "Variations per Parameter", "Total Combinations", "Pairwise Combinations"};
33+
String[] headers = {"Number of Parameters",
34+
"Variations per Parameter",
35+
"Total Combinations",
36+
"Pairwise Combinations"};
3437
MarkdownTable table = MarkdownTable.withHeaders(headers);
3538
table.setColumnProperties(MarkdownColumn.RIGHT_JUSTIFIED);
36-
// + "| --------------------: | -----------------------: | ------------------: | ---------------------: |\n");
39+
// + "| --------------------: | -----------------------: | ------------------: | ---------------------: |\n");
3740
addPairwiseTableRow(2, 5, table);
3841
addPairwiseTableRow(3, 3, table);
3942
addPairwiseTableRow(3, 4, table);
4043
addPairwiseTableRow(4, 5, table);
4144
addPairwiseTableRow(5, 6, table);
4245
addPairwiseTableRow(9, 9, table);
4346
// added blank lines at beginning due to markdown snippets bug
44-
Approvals.verify(String.format("\n\n%s\n\n", table.toMarkdown()), new Options().forFile().withExtension("include.md"));
47+
Approvals.verify(String.format("\n\n%s\n\n", table.toMarkdown()),
48+
new Options().forFile().withExtension("include.md"));
4549
}
4650
private String addPairwiseTableRow(int pCount, int variations, MarkdownTable table)
4751
{
4852
Object[] p = Range.get(1, variations);
4953
Pairwise pairwise = Pairwise.toPairWise(p, p, 3 <= pCount ? p : CombinationApprovals.EMPTY,
50-
4 <= pCount ? p : CombinationApprovals.EMPTY, 5 <= pCount ? p : CombinationApprovals.EMPTY,
51-
6 <= pCount ? p : CombinationApprovals.EMPTY, 7 <= pCount ? p : CombinationApprovals.EMPTY,
52-
8 <= pCount ? p : CombinationApprovals.EMPTY, 9 <= pCount ? p : CombinationApprovals.EMPTY);
54+
4 <= pCount ? p : CombinationApprovals.EMPTY, 5 <= pCount ? p : CombinationApprovals.EMPTY,
55+
6 <= pCount ? p : CombinationApprovals.EMPTY, 7 <= pCount ? p : CombinationApprovals.EMPTY,
56+
8 <= pCount ? p : CombinationApprovals.EMPTY, 9 <= pCount ? p : CombinationApprovals.EMPTY);
5357
final List<Case> cases = pairwise.getCases();
5458
int totalPossibleSize = pairwise.getTotalPossibleCombinations();
5559
DecimalFormat df = new DecimalFormat("###,###,###");

approvaltests-util-tests/src/test/java/com/spun/util/markdown/table/MarkdownTableTest.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@
44
import org.approvaltests.utils.VerifiableMarkdownTable;
55
import org.junit.jupiter.api.Test;
66

7-
public class MarkdownTableTest {
8-
@Test
9-
void testRightJustified() {
10-
VerifiableMarkdownTable table = VerifiableMarkdownTable.withHeaders("Number");
11-
table.setColumnProperties(MarkdownColumn.RIGHT_JUSTIFIED);
12-
for (int i = 9; i <= 11; i++) {
13-
table.addRow(i);
14-
}
15-
Approvals.verify(table);
7+
public class MarkdownTableTest
8+
{
9+
@Test
10+
void testRightJustified()
11+
{
12+
VerifiableMarkdownTable table = VerifiableMarkdownTable.withHeaders("Number");
13+
table.setColumnProperties(MarkdownColumn.RIGHT_JUSTIFIED);
14+
for (int i = 9; i <= 11; i++)
15+
{
16+
table.addRow(i);
1617
}
17-
18-
@Test
19-
void testDefaultJustification() {
20-
VerifiableMarkdownTable table = VerifiableMarkdownTable.withHeaders("Number", "Number++");
21-
for (int i = 9; i <= 11; i++) {
22-
table.addRow(i, i+1);
23-
}
24-
Approvals.verify(table);
18+
Approvals.verify(table);
19+
}
20+
@Test
21+
void testDefaultJustification()
22+
{
23+
VerifiableMarkdownTable table = VerifiableMarkdownTable.withHeaders("Number", "Number++");
24+
for (int i = 9; i <= 11; i++)
25+
{
26+
table.addRow(i, i + 1);
2527
}
28+
Approvals.verify(table);
29+
}
2630
}

approvaltests-util/src/main/java/com/spun/util/StringUtils.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,12 @@ public static String pad(String contents, int targetLength)
615615
}
616616
return contents;
617617
}
618-
619-
public static String padLeft(String contents, int targetLength) {
620-
while(contents.length() < targetLength) {
621-
contents = " " + contents;
622-
}
623-
return contents;
618+
public static String padLeft(String contents, int targetLength)
619+
{
620+
while (contents.length() < targetLength)
621+
{
622+
contents = " " + contents;
624623
}
624+
return contents;
625+
}
625626
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.spun.util.markdown.table;
22

33
public enum MarkdownColumn {
4-
DEFAULT,
5-
RIGHT_JUSTIFIED
4+
DEFAULT, RIGHT_JUSTIFIED
65
}

approvaltests-util/src/main/java/com/spun/util/markdown/table/MarkdownTable.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
public class MarkdownTable implements MarkdownCompatible
88
{
9-
public Queryable<MarkdownTableElement> markdown = new Queryable<MarkdownTableElement>(MarkdownTableElement.class);
10-
private boolean fixedWidth = true;
11-
private MarkdownColumn columnProperties = MarkdownColumn.DEFAULT;
12-
13-
public void setColumnsConsistentWidth(boolean setting) {
9+
public Queryable<MarkdownTableElement> markdown = new Queryable<MarkdownTableElement>(
10+
MarkdownTableElement.class);
11+
private boolean fixedWidth = true;
12+
private MarkdownColumn columnProperties = MarkdownColumn.DEFAULT;
13+
public void setColumnsConsistentWidth(boolean setting)
14+
{
1415
fixedWidth = setting;
1516
}
1617
public static <I, O> MarkdownTable create(I[] inputs, Function1<I, O> o, String column1, String column2)
@@ -58,32 +59,33 @@ public String toMarkdown()
5859
handleFixedWidth();
5960
return render(markdown);
6061
}
61-
62-
private void handleFixedWidth() {
63-
if (!fixedWidth) { return; }
62+
private void handleFixedWidth()
63+
{
64+
if (!fixedWidth)
65+
{ return; }
6466
Queryable<Queryable<MarkdownTableElement>> rows = markdown.split(e -> e == MarkdownTableElement.NEWLINE);
65-
for (int column = 0; column < rows.get(0).size(); column++) {
67+
for (int column = 0; column < rows.get(0).size(); column++)
68+
{
6669
int col = column;
67-
if (rows.get(0).get(column) instanceof MarkdownTableContents) {
68-
Queryable<Resizable> select = rows
69-
.select(e -> e.get(col))
70-
.where(e -> e instanceof Resizable)
71-
.select(e -> (Resizable) e);
72-
select.forEach(e -> e.setJustification(columnProperties));
73-
int length = select.max(e -> e.getLength()).getLength();
74-
select.forEach(e -> e.setPadding(length));
70+
if (rows.get(0).get(column) instanceof MarkdownTableContents)
71+
{
72+
Queryable<Resizable> select = rows.select(e -> e.get(col)).where(e -> e instanceof Resizable)
73+
.select(e -> (Resizable) e);
74+
select.forEach(e -> e.setJustification(columnProperties));
75+
int length = select.max(e -> e.getLength()).getLength();
76+
select.forEach(e -> e.setPadding(length));
7577
}
7678
}
7779
}
78-
7980
public static String printColumnHeaders(String... headers)
8081
{
8182
return render(constructColumnHeaders(headers));
8283
}
8384
public static Queryable<MarkdownTableElement> constructColumnHeaders(String... headers)
8485
{
8586
Queryable<MarkdownTableElement> row = constructRow(headers);
86-
for (int i = 0; i < headers.length; i++) {
87+
for (int i = 0; i < headers.length; i++)
88+
{
8789
row.add(MarkdownTableElement.DELIMITER);
8890
row.add(new MarkdownTableHeader());
8991
}
@@ -95,11 +97,10 @@ public static String printRow(Object... columns)
9597
{
9698
return render(constructRow(columns));
9799
}
98-
99-
private static String render(Queryable<MarkdownTableElement> table) {
100+
private static String render(Queryable<MarkdownTableElement> table)
101+
{
100102
return table.join("");
101103
}
102-
103104
public static Queryable<MarkdownTableElement> constructRow(Object... columns)
104105
{
105106
Queryable row = new Queryable(MarkdownTableElement.class);
@@ -112,8 +113,8 @@ public static Queryable<MarkdownTableElement> constructRow(Object... columns)
112113
row.add(MarkdownTableElement.NEWLINE);
113114
return row;
114115
}
115-
116-
public void setColumnProperties(MarkdownColumn columnProperties) {
116+
public void setColumnProperties(MarkdownColumn columnProperties)
117+
{
117118
this.columnProperties = columnProperties;
118119
}
119120
}

approvaltests-util/src/main/java/com/spun/util/markdown/table/MarkdownTableContents.java

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,40 @@
22

33
import com.spun.util.StringUtils;
44

5-
public class MarkdownTableContents implements MarkdownTableElement, Resizable {
6-
private String contents;
7-
private int padUntil;
8-
private MarkdownColumn columnProperties = MarkdownColumn.DEFAULT;
9-
10-
public MarkdownTableContents(String contents) {
11-
this.contents = contents;
12-
}
13-
14-
@Override
15-
public String toString() {
16-
String c;
17-
if (columnProperties == MarkdownColumn.RIGHT_JUSTIFIED) {
18-
c = StringUtils.padLeft(contents, padUntil);
19-
} else {
20-
c = StringUtils.pad(contents, padUntil);
21-
}
22-
return " " + c + " ";
23-
}
24-
25-
public int getLength() {
26-
return contents.length();
27-
}
28-
29-
public void setPadding(int length) {
30-
padUntil = length;
5+
public class MarkdownTableContents implements MarkdownTableElement, Resizable
6+
{
7+
private String contents;
8+
private int padUntil;
9+
private MarkdownColumn columnProperties = MarkdownColumn.DEFAULT;
10+
public MarkdownTableContents(String contents)
11+
{
12+
this.contents = contents;
13+
}
14+
@Override
15+
public String toString()
16+
{
17+
String c;
18+
if (columnProperties == MarkdownColumn.RIGHT_JUSTIFIED)
19+
{
20+
c = StringUtils.padLeft(contents, padUntil);
3121
}
32-
33-
@Override
34-
public void setJustification(MarkdownColumn columnProperties) {
35-
this.columnProperties = columnProperties;
22+
else
23+
{
24+
c = StringUtils.pad(contents, padUntil);
3625
}
26+
return " " + c + " ";
27+
}
28+
public int getLength()
29+
{
30+
return contents.length();
31+
}
32+
public void setPadding(int length)
33+
{
34+
padUntil = length;
35+
}
36+
@Override
37+
public void setJustification(MarkdownColumn columnProperties)
38+
{
39+
this.columnProperties = columnProperties;
40+
}
3741
}
Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
package com.spun.util.markdown.table;
22

3-
public class MarkdownTableHeader implements MarkdownTableElement, Resizable {
4-
private int padUntil = 1;
5-
private MarkdownColumn columnProperties;
6-
7-
public MarkdownTableHeader() {
8-
}
9-
10-
@Override
11-
public String toString() {
12-
int dashCount = padUntil + 2; // Math.max(3, padUntil + 2);
13-
String dashes = "----------------------------------".substring(0, dashCount);
14-
if (columnProperties == MarkdownColumn.RIGHT_JUSTIFIED) {
15-
dashes = dashes.substring(0, dashCount - 1) + ":";
16-
}
17-
return dashes;
18-
}
19-
20-
public int getLength() {
21-
return 1;
22-
}
23-
24-
public void setPadding(int length) {
25-
padUntil = length;
26-
}
27-
28-
@Override
29-
public void setJustification(MarkdownColumn columnProperties) {
30-
this.columnProperties = columnProperties;
3+
public class MarkdownTableHeader implements MarkdownTableElement, Resizable
4+
{
5+
private int padUntil = 1;
6+
private MarkdownColumn columnProperties;
7+
public MarkdownTableHeader()
8+
{
9+
}
10+
@Override
11+
public String toString()
12+
{
13+
int dashCount = padUntil + 2; // Math.max(3, padUntil + 2);
14+
String dashes = "----------------------------------".substring(0, dashCount);
15+
if (columnProperties == MarkdownColumn.RIGHT_JUSTIFIED)
16+
{
17+
dashes = dashes.substring(0, dashCount - 1) + ":";
3118
}
19+
return dashes;
20+
}
21+
public int getLength()
22+
{
23+
return 1;
24+
}
25+
public void setPadding(int length)
26+
{
27+
padUntil = length;
28+
}
29+
@Override
30+
public void setJustification(MarkdownColumn columnProperties)
31+
{
32+
this.columnProperties = columnProperties;
33+
}
3234
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.spun.util.markdown.table;
22

3-
public interface Resizable {
4-
public int getLength();
5-
public void setPadding(int length);
6-
public void setJustification(MarkdownColumn columnProperties);
3+
public interface Resizable
4+
{
5+
public int getLength();
6+
public void setPadding(int length);
7+
public void setJustification(MarkdownColumn columnProperties);
78
}

0 commit comments

Comments
 (0)