From cb03f0aadefd5279236c3f592b8b6112c1de420f Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 12 Feb 2024 18:08:06 +0000 Subject: [PATCH] a reformat code --- .../test/java/org/approvaltests/Creator.java | 4 +- .../java/org/approvaltests/ParseInput.java | 92 ++++----- .../org/approvaltests/ParseInputTest.java | 174 +++++++++--------- 3 files changed, 121 insertions(+), 149 deletions(-) diff --git a/approvaltests-tests/src/test/java/org/approvaltests/Creator.java b/approvaltests-tests/src/test/java/org/approvaltests/Creator.java index b6aa0510..2f6ca227 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/Creator.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/Creator.java @@ -3,6 +3,6 @@ import org.lambda.functions.Function1; import org.lambda.query.Queryable; -public interface Creator extends Function1, T> { +public interface Creator extends Function1, T> +{ } - diff --git a/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java b/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java index 0fadcabc..a5253b3d 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/ParseInput.java @@ -6,59 +6,41 @@ import org.lambda.query.Query; import org.lambda.query.Queryable; -public class ParseInput { - - private String expected; - private final Function1> transformer; - - - - public static ParseInput create(String expected) { - return new ParseInput(expected, s -> new Tuple<>(s,s)); - - } - public static ParseInput create(String expected,Function1 transformer) { - return new ParseInput(expected,s -> new Tuple<>(s,transformer.call(s))); - - } - - private ParseInput(String expected, Function1> transformer) { - this.expected = expected; - this.transformer = transformer; - } - - public static ParseInput createFromParts(String expected, Function1, T> transformer) { - return new ParseInput(expected,s -> { - var temp = Queryable.as(s.split(",")).select(String::trim); - return new Tuple<>(s, transformer.call(temp)); - }); - } - - public Queryable> parse(String expected) { - return Queryable.as(expected.lines()) - .select(l -> l.split(" -> ")[0].trim()) - .select(l -> transformer.call(l)); - } - - public String print(String input, Object output) { - return input + " -> " + output; - } - - public void verifyAll(Function1 transform) { - Approvals.verifyAll("", parse(expected), - s -> print(s.getFirst(), transform.call(s.getSecond())), new Options().inline(expected)); - } +public class ParseInput +{ + private String expected; + private final Function1> transformer; + public static ParseInput create(String expected) + { + return new ParseInput(expected, s -> new Tuple<>(s, s)); + } + public static ParseInput create(String expected, Function1 transformer) + { + return new ParseInput(expected, s -> new Tuple<>(s, transformer.call(s))); + } + private ParseInput(String expected, Function1> transformer) + { + this.expected = expected; + this.transformer = transformer; + } + public static ParseInput createFromParts(String expected, Function1, T> transformer) + { + return new ParseInput(expected, s -> { + var temp = Queryable.as(s.split(",")).select(String::trim); + return new Tuple<>(s, transformer.call(temp)); + }); + } + public Queryable> parse(String expected) + { + return Queryable.as(expected.lines()).select(l -> l.split(" -> ")[0].trim()).select(l -> transformer.call(l)); + } + public String print(String input, Object output) + { + return input + " -> " + output; + } + public void verifyAll(Function1 transform) + { + Approvals.verifyAll("", parse(expected), s -> print(s.getFirst(), transform.call(s.getSecond())), + new Options().inline(expected)); + } } - - - - - - - - - - - - - diff --git a/approvaltests-tests/src/test/java/org/approvaltests/ParseInputTest.java b/approvaltests-tests/src/test/java/org/approvaltests/ParseInputTest.java index 807100b5..aad19333 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/ParseInputTest.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/ParseInputTest.java @@ -7,98 +7,88 @@ import java.util.Objects; -public class ParseInputTest { - - @Test - void uppercasse() { - var expected = """ - a -> A - b -> B - hh -> HH - c -> C - d -> D - e -> E - cco -> CCO - f -> F - g -> G - eue -> EUE - aza -> AZA - """; - ParseInput.create(expected).verifyAll(s -> s.toUpperCase()); - +public class ParseInputTest +{ + @Test + void uppercasse() + { + var expected = """ + a -> A + b -> B + hh -> HH + c -> C + d -> D + e -> E + cco -> CCO + f -> F + g -> G + eue -> EUE + aza -> AZA + """; + ParseInput.create(expected).verifyAll(s -> s.toUpperCase()); + } + @Test + void toBinary() + { + var expected = """ + 1 -> 1 + 2 -> 10 + 4 -> 100 + 8 -> 1000 + 9 -> 1001 + """; + ParseInput.create(expected, Integer::parseInt).verifyAll(s -> Integer.toBinaryString(s)); + } + public static final class Person + { + private final String name; + private final int age; + public Person(String name, int age) + { + this.name = name; + this.age = age; } - - @Test - void toBinary() { - var expected = """ - 1 -> 1 - 2 -> 10 - 4 -> 100 - 8 -> 1000 - 9 -> 1001 - """; - - ParseInput.create(expected, Integer::parseInt) - .verifyAll(s -> Integer.toBinaryString(s)); - + public String getAgeLabel() + { + return age > 20 ? "adult" : "teenager"; } - - public static final class Person { - private final String name; - private final int age; - - public Person(String name, int age) { - this.name = name; - this.age = age; - } - - public String getAgeLabel() { - return age > 20 ? "adult" : "teenager"; - } - - public String name() { - return name; - } - - public int age() { - return age; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; - var that = (Person) obj; - return Objects.equals(this.name, that.name) && - this.age == that.age; - } - - @Override - public int hashCode() { - return Objects.hash(name, age); - } - - @Override - public String toString() { - return "Person[" + - "name=" + name + ", " + - "age=" + age + ']'; - } - - - } - - @Test - void testPeople() { - var expected = """ - Llewellyn, 25 -> adult - Oliver, 15 -> teenager - """; - - Creator createPerson = (a) -> new Person(a.first(), Integer.parseInt(a.last())); - ParseInput.createFromParts(expected, createPerson) - .verifyAll(s -> s.getAgeLabel()); - + public String name() + { + return name; } - - } \ No newline at end of file + public int age() + { + return age; + } + @Override + public boolean equals(Object obj) + { + if (obj == this) + return true; + if (obj == null || obj.getClass() != this.getClass()) + return false; + var that = (Person) obj; + return Objects.equals(this.name, that.name) && this.age == that.age; + } + @Override + public int hashCode() + { + return Objects.hash(name, age); + } + @Override + public String toString() + { + return "Person[" + "name=" + name + ", " + "age=" + age + ']'; + } + } + @Test + void testPeople() + { + var expected = """ + Llewellyn, 25 -> adult + Oliver, 15 -> teenager + """; + Creator createPerson = (a) -> new Person(a.first(), Integer.parseInt(a.last())); + ParseInput.createFromParts(expected, createPerson).verifyAll(s -> s.getAgeLabel()); + } +} \ No newline at end of file