Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.junit.Before;
- import org.junit.jupiter.api.Test;
- import java.io.IOException;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.mockito.Mockito.mock;
- import static org.mockito.Mockito.when;
- class DirProcessorTest
- {
- @Test
- void testFolder1() throws IOException {
- FileProcessor fileProcessor = mock(FileProcessor.class);
- DirProcessor dp = new DirProcessor(fileProcessor);
- when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolder\\1.txt")).thenReturn(5);
- when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolder\\2.txt")).thenReturn(4);
- assertEquals(9, dp.countSymbolsFromPackage("src\\test\\resources\\DPFiles\\NotEmptyFolder"));
- }
- @Test
- void testFolder2() throws IOException {
- FileProcessor fileProcessor = mock(FileProcessor.class);
- DirProcessor dp = new DirProcessor(fileProcessor);
- when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\Folder2\\1.txt")).thenReturn(5);
- when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\Folder2\\2.txt")).thenReturn(10);
- assertEquals(15, dp.countSymbolsFromPackage("src\\test\\resources\\DPFiles\\Folder2"));
- }
- @Test
- void testFolderWithEmptyFile() throws IOException {
- FileProcessor fileProcessor = mock(FileProcessor.class);
- DirProcessor dp = new DirProcessor(fileProcessor);
- when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\EmptyFolder\\1.txt")).thenReturn(0);
- assertEquals(0, dp.countSymbolsFromPackage("src\\test\\resources\\DPFiles\\EmptyFolder"));
- }
- @Test
- void shouldNotOpenXML() throws IOException {
- FileProcessor fileProcessor = mock(FileProcessor.class);
- DirProcessor dp = new DirProcessor(fileProcessor);
- when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolderWithXML\\1.txt")).thenReturn(5);
- when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolderWithXML\\2.txt")).thenReturn(4);
- when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolderWithXML\\3.xml")).thenReturn(5);
- when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolderWithXML\\4.xml")).thenReturn(3);
- assertEquals(9, dp.countSymbolsFromPackage("src\\test\\resources\\DPFiles\\NotEmptyFolderWithXML"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement