Skip to content

Commit

Permalink
R migrate from if else to List lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 31, 2021
1 parent 844596b commit 78717c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import org.approvaltests.core.Options;
import org.approvaltests.namer.NamedEnvironment;
import org.approvaltests.namer.NamerFactory;
import org.approvaltests.writers.ApprovalWriterFactory;
import org.approvaltests.writers.ComponentApprovalWriter;
import org.approvaltests.writers.DefaultApprovalWriterFactory;
import org.approvaltests.writers.ImageApprovalWriter;
import org.approvaltests.writers.PaintableApprovalWriter;
import org.lambda.functions.Function1;

import com.spun.swing.Paintable;
Expand All @@ -25,6 +25,10 @@ public class AwtApprovals
{
DefaultApprovalWriterFactory.addDefault(c -> c instanceof Component,
(Object c, Options o) -> new ComponentApprovalWriter((Component) c));
DefaultApprovalWriterFactory.addDefault(o -> o instanceof Paintable,
(c, o) -> new PaintableApprovalWriter((Paintable) c));
DefaultApprovalWriterFactory.addDefault(o -> o instanceof PaintableMultiFrame,
(c, o) -> new PaintableMultiframeWriter((PaintableMultiFrame) c));
}
public static void verify(Image image)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,16 @@ public class DefaultApprovalWriterFactory
static
{
addDefault(o -> o instanceof ResultSet, (c, o) -> new ResultSetApprovalWriter((ResultSet) c));
addDefault(o -> o instanceof File, (c, o) -> new FileApprovalWriter((File) c));
addDefault(o -> o instanceof ResultSet, (c, o) -> new ResultSetApprovalWriter((ResultSet) c));
}
public static ApprovalWriterFactory getDefaultFactory()
{
return (c, o) -> {
Tuple<Function1<Object, Boolean>, ApprovalWriterFactory> first = factories
.first(t -> t.getFirst().call(c));
Tuple<Function1<Object, Boolean>, ApprovalWriterFactory> first = factories.first(t -> t.getFirst().call(c));
if (first != null)
{ return first.getSecond().create(c, o); }
if (c instanceof File)
{
return new FileApprovalWriter((File) c);
}
else if (c instanceof Paintable)
{
return new PaintableApprovalWriter((Paintable) c);
}
else if (c instanceof PaintableMultiFrame)
{
return new PaintableMultiframeWriter((PaintableMultiFrame) c);
return first.getSecond().create(c, o);
}
else
{
Expand Down

0 comments on commit 78717c5

Please sign in to comment.