Skip to content

Commit

Permalink
minor cleanups in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dfa1 committed Dec 22, 2023
1 parent 1d39fc0 commit 3032c20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class DurationParsing {

/**
* Parsing duration ISO 8601 format with possibility to omit leading 'PT' prefix.
*
* Any invalid input, including null, returns empty.
*/
public static Optional<Duration> parse(String value) {
Expand Down
26 changes: 16 additions & 10 deletions runtime/src/test/java/hosh/runtime/ExternalCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ void processNoArgs() throws Exception {
given(process.getOutputStream()).willReturn(OutputStream.nullOutputStream());
given(process.getInputStream()).willReturn(InputStream.nullInputStream());
given(process.getErrorStream()).willReturn(InputStream.nullInputStream());
given(state.getCwd()).willReturn(Paths.get("."));
Path cwd = temporaryFolder.toPath();
given(state.getCwd()).willReturn(cwd);
given(state.getVariables()).willReturn(Collections.emptyMap());
ExitStatus exitStatus = sut.run(Collections.emptyList(), in, out, err);
assertThat(exitStatus).isSuccess();
then(processFactory).should().create(
List.of(executable.toString()),
Paths.get("."),
cwd,
Collections.emptyMap(),
Position.SOLE);
then(in).should().recv();
Expand All @@ -123,13 +124,14 @@ void processWithArgs() throws Exception {
given(process.getOutputStream()).willReturn(OutputStream.nullOutputStream());
given(process.getInputStream()).willReturn(InputStream.nullInputStream());
given(process.getErrorStream()).willReturn(InputStream.nullInputStream());
given(state.getCwd()).willReturn(Paths.get("."));
Path cwd = temporaryFolder.toPath();
given(state.getCwd()).willReturn(cwd);
given(state.getVariables()).willReturn(Collections.emptyMap());
ExitStatus exitStatus = sut.run(Collections.singletonList("file.hosh"), in, out, err);
assertThat(exitStatus).isSuccess();
then(processFactory).should().create(
List.of(executable.toString(), "file.hosh"),
Paths.get("."),
cwd,
Collections.emptyMap(),
Position.SOLE);
then(in).should().recv();
Expand All @@ -144,13 +146,14 @@ void processExitsWithError() throws Exception {
given(process.getInputStream()).willReturn(InputStream.nullInputStream());
given(process.getErrorStream()).willReturn(InputStream.nullInputStream());
given(process.getOutputStream()).willReturn(OutputStream.nullOutputStream());
given(state.getCwd()).willReturn(Paths.get("."));
Path cwd = temporaryFolder.toPath();
given(state.getCwd()).willReturn(cwd);
given(state.getVariables()).willReturn(Collections.emptyMap());
ExitStatus exitStatus = sut.run(Collections.singletonList("file.hosh"), in, out, err);
assertThat(exitStatus).isError();
then(processFactory).should().create(
List.of(executable.toString(), "file.hosh"),
Paths.get("."),
cwd,
Collections.emptyMap(),
Position.SOLE);
then(in).should(times(1)).recv();
Expand All @@ -165,13 +168,14 @@ void processException() throws Exception {
given(process.getInputStream()).willReturn(InputStream.nullInputStream());
given(process.getErrorStream()).willReturn(InputStream.nullInputStream());
given(process.getOutputStream()).willReturn(OutputStream.nullOutputStream());
given(state.getCwd()).willReturn(Paths.get("."));
Path cwd = temporaryFolder.toPath();
given(state.getCwd()).willReturn(cwd);
given(state.getVariables()).willReturn(Collections.emptyMap());
ExitStatus exitStatus = sut.run(Collections.singletonList("file.hosh"), in, out, err);
assertThat(exitStatus).isError();
then(processFactory).should().create(
List.of(executable.toString(), "file.hosh"),
Paths.get("."),
cwd,
Collections.emptyMap(),
Position.SOLE);
then(in).should(times(1)).recv();
Expand Down Expand Up @@ -202,7 +206,8 @@ void processSendRecordsToErr() throws Exception {
given(process.getOutputStream()).willReturn(OutputStream.nullOutputStream());
given(process.getInputStream()).willReturn(InputStream.nullInputStream());
given(process.getErrorStream()).willReturn(new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8)));
given(state.getCwd()).willReturn(Paths.get("."));
Path cwd = temporaryFolder.toPath();
given(state.getCwd()).willReturn(cwd);
given(state.getVariables()).willReturn(Collections.emptyMap());
ExitStatus exitStatus = sut.run(Collections.singletonList("file.hosh"), in, out, err);
assertThat(exitStatus).isSuccess();
Expand Down Expand Up @@ -236,7 +241,8 @@ void processRecordsFromIn() throws Exception {
@Test
void throwsIoException() throws Exception {
given(processFactory.create(any(), any(), any(), any())).willThrow(new IOException("simulated error"));
given(state.getCwd()).willReturn(Paths.get("."));
Path cwd = temporaryFolder.toPath();
given(state.getCwd()).willReturn(cwd);
given(state.getVariables()).willReturn(Collections.emptyMap());
ExitStatus exitStatus = sut.run(Collections.singletonList("file.hosh"), in, out, err);
assertThat(exitStatus).isError();
Expand Down

0 comments on commit 3032c20

Please sign in to comment.