|
| 1 | +/** |
| 2 | + * Copyright (C) 2009-2018 Slava Semushin <slava.semushin@gmail.com> |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | + */ |
| 18 | +package ru.mystamps.web.service |
| 19 | + |
| 20 | +import org.slf4j.helpers.NOPLogger |
| 21 | + |
| 22 | +import spock.lang.Specification |
| 23 | + |
| 24 | +import ru.mystamps.web.dao.SeriesSalesImportDao |
| 25 | +import ru.mystamps.web.dao.dto.SeriesSalesParsedDataDbDto |
| 26 | +import ru.mystamps.web.tests.Random |
| 27 | + |
| 28 | +@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace']) |
| 29 | +class SeriesSalesImportServiceImplTest extends Specification { |
| 30 | + |
| 31 | + private final SeriesSalesImportDao seriesSalesImportDao = Mock() |
| 32 | + |
| 33 | + private SeriesSalesImportService service |
| 34 | + |
| 35 | + def setup() { |
| 36 | + service = new SeriesSalesImportServiceImpl(NOPLogger.NOP_LOGGER, seriesSalesImportDao) |
| 37 | + } |
| 38 | + |
| 39 | + // |
| 40 | + // Tests for saveParsedData() |
| 41 | + // |
| 42 | + |
| 43 | + def 'saveParsedData() should throw exception when request id is null'() { |
| 44 | + when: |
| 45 | + service.saveParsedData(null, TestObjects.createSeriesSalesParsedDataDbDto()) |
| 46 | + then: |
| 47 | + IllegalArgumentException ex = thrown() |
| 48 | + ex.message == 'Request id must be non null' |
| 49 | + } |
| 50 | + |
| 51 | + def 'saveParsedData() should throw exception when parsed data is null'() { |
| 52 | + when: |
| 53 | + service.saveParsedData(Random.id(), null) |
| 54 | + then: |
| 55 | + IllegalArgumentException ex = thrown() |
| 56 | + ex.message == 'Parsed data must be non null' |
| 57 | + } |
| 58 | + |
| 59 | + def 'saveParsedData() should save series parsed data'() { |
| 60 | + given: |
| 61 | + Integer expectedRequestId = Random.id() |
| 62 | + SeriesSalesParsedDataDbDto expectedParsedData = TestObjects.createSeriesSalesParsedDataDbDto() |
| 63 | + when: |
| 64 | + service.saveParsedData(expectedRequestId, expectedParsedData) |
| 65 | + then: |
| 66 | + 1 * seriesSalesImportDao.addParsedData(expectedRequestId, expectedParsedData) |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments