Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. import org.junit.Before;
  2. import org.junit.jupiter.api.Test;
  3.  
  4. import java.io.IOException;
  5.  
  6. import static org.junit.jupiter.api.Assertions.assertEquals;
  7. import static org.mockito.Mockito.mock;
  8. import static org.mockito.Mockito.when;
  9.  
  10. class DirProcessorTest
  11. {
  12. @Test
  13. void testFolder1() throws IOException {
  14. FileProcessor fileProcessor = mock(FileProcessor.class);
  15. DirProcessor dp = new DirProcessor(fileProcessor);
  16. when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolder\\1.txt")).thenReturn(5);
  17. when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolder\\2.txt")).thenReturn(4);
  18. assertEquals(9, dp.countSymbolsFromPackage("src\\test\\resources\\DPFiles\\NotEmptyFolder"));
  19. }
  20. @Test
  21. void testFolder2() throws IOException {
  22. FileProcessor fileProcessor = mock(FileProcessor.class);
  23. DirProcessor dp = new DirProcessor(fileProcessor);
  24. when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\Folder2\\1.txt")).thenReturn(5);
  25. when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\Folder2\\2.txt")).thenReturn(10);
  26. assertEquals(15, dp.countSymbolsFromPackage("src\\test\\resources\\DPFiles\\Folder2"));
  27. }
  28. @Test
  29. void testFolderWithEmptyFile() throws IOException {
  30. FileProcessor fileProcessor = mock(FileProcessor.class);
  31. DirProcessor dp = new DirProcessor(fileProcessor);
  32. when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\EmptyFolder\\1.txt")).thenReturn(0);
  33. assertEquals(0, dp.countSymbolsFromPackage("src\\test\\resources\\DPFiles\\EmptyFolder"));
  34. }
  35. @Test
  36. void shouldNotOpenXML() throws IOException {
  37. FileProcessor fileProcessor = mock(FileProcessor.class);
  38. DirProcessor dp = new DirProcessor(fileProcessor);
  39. when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolderWithXML\\1.txt")).thenReturn(5);
  40. when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolderWithXML\\2.txt")).thenReturn(4);
  41. when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolderWithXML\\3.xml")).thenReturn(5);
  42. when(fileProcessor.countSymbols("src\\test\\resources\\DPFiles\\NotEmptyFolderWithXML\\4.xml")).thenReturn(3);
  43. assertEquals(9, dp.countSymbolsFromPackage("src\\test\\resources\\DPFiles\\NotEmptyFolderWithXML"));
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement