Skip to content

Commit

Permalink
file input test
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina20 committed Oct 30, 2023
1 parent e1b3871 commit d8c4d18
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class GenerateSubcommand extends GenericActCommand<NoProperties, NoClient
@CommandLine.Option(names = {"-d", "--destination"}, paramLabel = "...", descriptionKey = "crowdin.generate.destination", defaultValue = "crowdin.yml", order = -2)
private Path destinationPath;

@CommandLine.Option(names = "--skip-generate-description", hidden = true, order = -2)
@CommandLine.Option(names = "--skip-generate-description", hidden = true)
private boolean skipGenerateDescription;

protected NewAction<NoProperties, NoClient> getAction(Actions actions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.io.*;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -62,6 +64,30 @@ public void userInputTest() throws IOException {
verifyNoMoreInteractions(files);
}

@Test
public void userInputAllTest() throws IOException {
FilesInterface files = mock(FilesInterface.class);

action = new GenerateAction(files, "token", "https://api.crowdin.com", ".", "42", "file.json", "translation.json", true, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action.act(Outputter.getDefault(), new NoProperties(), mock(NoClient.class));

ArgumentCaptor<InputStream> contentCaptor = ArgumentCaptor.forClass(InputStream.class);
verify(files).writeToFile(anyString(), contentCaptor.capture());
verifyNoMoreInteractions(files);

List<String> actualLines = new BufferedReader(new InputStreamReader(contentCaptor.getValue(), UTF_8))
.lines()
.collect(Collectors.toList());

assertTrue(actualLines.contains("\"project_id\": \"42\""));
assertTrue(actualLines.contains("\"api_token\": \"token\""));
assertTrue(actualLines.contains("\"base_path\": \".\""));
assertTrue(actualLines.contains("\"base_url\": \"https://api.crowdin.com\""));
assertTrue(actualLines.contains("\"preserve_hierarchy\": true"));
assertTrue(actualLines.contains(" \"source\": \"file.json\","));
assertTrue(actualLines.contains(" \"translation\": \"translation.json\","));
}

@Test
public void writeToFileThrowsTest() throws IOException {
FilesInterface files = mock(FilesInterface.class);
Expand Down Expand Up @@ -145,6 +171,6 @@ private static InputStream setResponses(
+ apiToken + "\n"
+ projectId + "\n"
+ basePath + "\n";
return new ByteArrayInputStream(responsesString.getBytes(StandardCharsets.UTF_8));
return new ByteArrayInputStream(responsesString.getBytes(UTF_8));
}
}

0 comments on commit d8c4d18

Please sign in to comment.