Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Adding missing tests to FileUtils class #660

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/test/java/com/crowdin/cli/utils/file/FileUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

public class FileUtilsTest extends WorkWithProjectTestPart {

Expand Down Expand Up @@ -46,4 +43,30 @@ public void testWriteToFile_2() throws IOException {
String result = org.apache.commons.io.FileUtils.readFileToString(file, "UTF-8");
assertEquals(text, result);
}
@Test
public void testReadYamlFile_UnexpectedException() {
File yamlFile = new File(tempProject.getBasePath() + "invalid.yaml");
try (FileOutputStream fos = new FileOutputStream(yamlFile)) {
fos.write("invalid_yaml_content: @#!@".getBytes());
} catch (IOException e) {
fail("Failed to setup test: " + e.getMessage());
}

assertThrows(RuntimeException.class, () -> FileUtils.readYamlFile(yamlFile));
}

@Test
public void testReadYamlFile_NullFile() {
assertThrows(NullPointerException.class, () -> FileUtils.readYamlFile(null));
}

@Test
public void testReadYamlFile_NonYamlExtension() {
File nonYamlFile = new File(tempProject.getBasePath() + "somefile.txt");
try {
FileUtils.readYamlFile(nonYamlFile);
} catch (RuntimeException e) {
assertFalse(e.getMessage().equals("error.configuration_file_not_exist"));
}
}
}
Loading