|
| 1 | +package imageconverter_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/gopherdojo/dojo2/kadai2/kadai2-2/imageconverter" |
| 7 | +) |
| 8 | + |
| 9 | +var ( |
| 10 | + calledCountSearcherRun int |
| 11 | + calledCountConverterRun int |
| 12 | +) |
| 13 | + |
| 14 | +type SearcherMock struct{} |
| 15 | + |
| 16 | +func (SearcherMock) Run(target imageconverter.FileInfo) []imageconverter.FileInfo { |
| 17 | + calledCountSearcherRun += 1 |
| 18 | + fis := []imageconverter.FileInfo{ |
| 19 | + imageconverter.FileInfo{Path: imageconverter.FilePath("../sample_dir1/Octocat.jpeg")}, |
| 20 | + imageconverter.FileInfo{Path: imageconverter.FilePath("../sample_dir1/dummy_fuga.md")}, |
| 21 | + imageconverter.FileInfo{Path: imageconverter.FilePath("../sample_dir1/dummy_hoge.txt")}, |
| 22 | + } |
| 23 | + return fis |
| 24 | +} |
| 25 | + |
| 26 | +type ConverterMock struct{} |
| 27 | + |
| 28 | +func (ConverterMock) Run(f imageconverter.FileInfo, in, out imageconverter.Format) { |
| 29 | + calledCountConverterRun += 1 |
| 30 | + return |
| 31 | +} |
| 32 | + |
| 33 | +func TestFacade_Run(t *testing.T) { |
| 34 | + var searcher SearcherMock |
| 35 | + var converter ConverterMock |
| 36 | + |
| 37 | + targetPath := imageconverter.FilePath("../sample_dir1") |
| 38 | + inputFormat := imageconverter.Format("jpg") |
| 39 | + outputFormat := imageconverter.Format("png") |
| 40 | + |
| 41 | + facade := imageconverter.Facade{Searcher: searcher, Converter: converter} |
| 42 | + facade.Run(targetPath, inputFormat, outputFormat) |
| 43 | + |
| 44 | + if calledCountSearcherRun != 1 { |
| 45 | + t.Errorf("Facade Run called count is wrong.") |
| 46 | + } |
| 47 | + if calledCountConverterRun != 3 { |
| 48 | + t.Errorf("Facade Run called count is wrong.") |
| 49 | + } |
| 50 | + |
| 51 | +} |
0 commit comments