Skip to content

Commit 503d6d5

Browse files
committed
simplify buildShell
1 parent ce85f9c commit 503d6d5

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

src/main/java/org/embulk/output/CommandFileOutputPlugin.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.io.OutputStream;
66
import java.io.FilterOutputStream;
77
import java.io.IOException;
8-
98
import com.google.common.annotations.VisibleForTesting;
109
import org.slf4j.Logger;
1110
import com.google.common.base.Throwables;
@@ -65,9 +64,8 @@ public TransactionalFileOutput open(TaskSource taskSource, final int taskIndex)
6564
{
6665
PluginTask task = taskSource.loadTask(PluginTask.class);
6766

68-
List<String> shell = new ShellFactory().build().get();
6967
List<String> cmdline = new ArrayList<String>();
70-
cmdline.addAll(shell);
68+
cmdline.addAll(buildShell());
7169
cmdline.add(task.getCommand());
7270

7371
logger.info("Using command {}", cmdline);
@@ -76,22 +74,13 @@ public TransactionalFileOutput open(TaskSource taskSource, final int taskIndex)
7674
}
7775

7876
@VisibleForTesting
79-
static class ShellFactory
77+
static List<String> buildShell()
8078
{
81-
private List<String> shell;
82-
83-
public List<String> get() {
84-
return this.shell;
85-
}
86-
87-
public ShellFactory build() {
88-
String osName = System.getProperty("os.name");
89-
if(osName.indexOf("Windows") >= 0) {
90-
this.shell = ImmutableList.of("PowerShell.exe", "-Command");
91-
} else {
92-
this.shell = ImmutableList.of("sh", "-c");
93-
}
94-
return this;
79+
String osName = System.getProperty("os.name");
80+
if(osName.indexOf("Windows") >= 0) {
81+
return ImmutableList.of("PowerShell.exe", "-Command");
82+
} else {
83+
return ImmutableList.of("sh", "-c");
9584
}
9685
}
9786

src/test/java/org/embulk/output/TestCommandFileOutputPlugin.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.junit.Rule;
66
import org.junit.Test;
77
import org.embulk.EmbulkTestRuntime;
8-
import org.embulk.output.CommandFileOutputPlugin.ShellFactory;
8+
import static org.embulk.output.CommandFileOutputPlugin.buildShell;
99

1010
import java.util.List;
1111

@@ -16,24 +16,13 @@ public class TestCommandFileOutputPlugin
1616
@Rule
1717
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
1818

19-
private ShellFactory shellFactory;
20-
21-
@Before
22-
public void createResources()
23-
{
24-
shellFactory = new ShellFactory().build();
25-
}
26-
2719
@Test
2820
public void testShell() {
29-
List<String> shell = shellFactory.get();
30-
String osName = System.getProperty("os.name");
31-
List<String> actualShellCmd;
32-
if (osName.indexOf("Windows") >= 0) {
33-
actualShellCmd = ImmutableList.of("PowerShell.exe", "-Command");
34-
} else {
35-
actualShellCmd = ImmutableList.of("sh", "-c");
21+
if (System.getProperty("os.name").indexOf("Windows") >= 0) {
22+
assertEquals(ImmutableList.of("PowerShell.exe", "-Command"), buildShell());
23+
}
24+
else {
25+
assertEquals(ImmutableList.of("sh", "-c"), buildShell());
3626
}
37-
assertEquals(actualShellCmd, shell);
3827
}
3928
}

0 commit comments

Comments
 (0)