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

[WIP] Spock to JUnit migration #1249

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ language: java

env:
matrix:
- SPRING_PROFILES_ACTIVE=test
- SPRING_PROFILES_ACTIVE=travis
- SPRING_PROFILES_ACTIVE=postgres
global:
- MAVEN_OPTS='-Xss256k'
- secure: "fBav56BzY+A+Vs1g9YSfo1oLDCO1rFrXl49lJkOA5/XpnsKEEs4lI2RcOzz0wiJKXFNgcliiAJWoYMI8Esqz+lkyFWan4ij5Co0UzJcytDuY+2o+jaqwx45DuDYPogABzT+hWjLCxQLLG46gUkChzT8kcvOOn6JxC7Ff8q5MnoM="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import spock.lang.Specification
import spock.lang.Unroll

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class LocaleUtilsTest extends Specification {
class LegacyLocaleUtilsTest extends Specification {

//
// Tests for getLanguageOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import spock.lang.Specification
import spock.lang.Unroll

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class PagerTest extends Specification {
class LegacyPagerTest extends Specification {

//
// Tests for Pager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import spock.lang.Specification
import spock.lang.Unroll

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class SlugUtilsTest extends Specification {
class LegacySlugUtilsTest extends Specification {

//
// Tests for slugify()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import ru.mystamps.web.tests.Random
import spock.lang.Specification

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class UserServiceImplTest extends Specification {
class LegacyUserServiceImplTest extends Specification {

private final UserDao userDao = Mock()
private final UsersActivationService usersActivationService = Mock()
Expand All @@ -36,18 +36,19 @@ class UserServiceImplTest extends Specification {
private UserService service
private ActivateAccountForm activationForm

@SuppressWarnings('UnnecessaryGetter')
def setup() {
AddUserDbDto user = TestObjects.createAddUserDbDto()

encoder.encode(_ as String) >> user.hash
encoder.encode(_ as String) >> user.getHash()

UsersActivationDto activation = TestObjects.createUsersActivationDto()
usersActivationService.findByActivationKey(_ as String) >> activation

activationForm = new ActivateAccountForm()
activationForm.setLogin(user.login)
activationForm.setLogin(user.getLogin())
activationForm.setPassword(TestObjects.TEST_PASSWORD)
activationForm.setName(user.name)
activationForm.setName(user.getName())
activationForm.setActivationKey(TestObjects.TEST_ACTIVATION_KEY)

service = new UserServiceImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import spock.lang.Specification
import spock.lang.Unroll

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class UsersActivationServiceImplTest extends Specification {
class LegacyUsersActivationServiceImplTest extends Specification {

private final UsersActivationDao usersActivationDao = Mock()
private final MailService mailService = Mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import static io.qala.datagen.StringModifier.Impls.oneOf
'NoTabCharacter',
'TrailingWhitespace',
])
class CategoryServiceImplTest extends Specification {
class LegacyCategoryServiceImplTest extends Specification {

private final CategoryDao categoryDao = Mock()
private final CategoryService service = new CategoryServiceImpl(NOPLogger.NOP_LOGGER, categoryDao)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import static io.qala.datagen.RandomShortApi.positiveLong
'NoTabCharacter',
'TrailingWhitespace',
])
class CollectionServiceImplTest extends Specification {
class LegacyCollectionServiceImplTest extends Specification {

private final CollectionDao collectionDao = Mock()

Expand Down Expand Up @@ -70,7 +70,7 @@ class CollectionServiceImplTest extends Specification {
}

@SuppressWarnings('FactoryMethodName')
def 'createCollection() should throw exception when owner login can\'t be converted to slug'() {
def "createCollection() should throw exception when owner login can't be converted to slug"() {
when:
service.createCollection(Random.userId(), '')
then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import static io.qala.datagen.StringModifier.Impls.oneOf
'NoTabCharacter',
'TrailingWhitespace',
])
class CountryServiceImplTest extends Specification {
class LegacyCountryServiceImplTest extends Specification {

private final CountryDao countryDao = Mock()
private final CountryService service = new CountryServiceImpl(NOPLogger.NOP_LOGGER, countryDao)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ru.mystamps.web.service.TestObjects
import spock.lang.Specification

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class DatabaseImagePersistenceStrategyTest extends Specification {
class LegacyDatabaseImagePersistenceStrategyTest extends Specification {

private final ImageDataDao imageDataDao = Mock()
private final MultipartFile multipartFile = Mock()
Expand All @@ -32,13 +32,15 @@ class DatabaseImagePersistenceStrategyTest extends Specification {
private ImagePersistenceStrategy strategy

def setup() {
strategy = new DatabaseImagePersistenceStrategy(
DatabaseImagePersistenceStrategy dbStrategy = new DatabaseImagePersistenceStrategy(
NOPLogger.NOP_LOGGER,
imageDataDao
)

// init() does nothing except logging but by invoking it we're improving code coverage
strategy.init()
dbStrategy.init()

strategy = dbStrategy
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import spock.lang.Specification
import java.nio.file.Path

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class FilesystemImagePersistenceStrategyTest extends Specification {
private static final STORAGE_DIR = File.separator + 'tmp'
private static final PREVIEW_DIR = File.separator + 'tmp'
class LegacyFilesystemImagePersistenceStrategyTest extends Specification {
private static final String STORAGE_DIR = File.separator + 'tmp'
private static final String PREVIEW_DIR = File.separator + 'tmp'

private final MultipartFile multipartFile = Mock()
private final ImageInfoDto imageInfoDto = TestObjects.createImageInfoDto()
Expand Down Expand Up @@ -94,7 +94,7 @@ class FilesystemImagePersistenceStrategyTest extends Specification {
// Tests for get()
//

def 'get() should return null when file doesn\'t exist'() {
def "get() should return null when file doesn't exist"() {
given:
strategy.exists(_ as Path) >> false
and:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import spock.lang.Specification
import spock.lang.Unroll

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class ImageServiceImplTest extends Specification {
class LegacyImageServiceImplTest extends Specification {

private final ImageDao imageDao = Mock()
private final MultipartFile multipartFile = Mock()
Expand All @@ -40,10 +40,11 @@ class ImageServiceImplTest extends Specification {
imageDao
)

@SuppressWarnings('UnnecessaryGetter')
def setup() {
multipartFile.size >> 1024L
multipartFile.contentType >> 'image/png'
multipartFile.originalFilename >> 'super-image.png'
multipartFile.getSize() >> 1024L
multipartFile.getContentType() >> 'image/png'
multipartFile.getOriginalFilename() >> 'super-image.png'
imageDao.add(_ as String, _ as String) >> 17
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import spock.lang.Specification
import spock.lang.Unroll

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class TimedImagePreviewStrategyTest extends Specification {
class LegacyTimedImagePreviewStrategyTest extends Specification {

private final ImagePreviewStrategy origStrategy = Mock()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import static io.qala.datagen.RandomShortApi.nullOrBlank
'NoTabCharacter',
'TrailingWhitespace',
])
class ParticipantServiceImplTest extends Specification {
class LegacyParticipantServiceImplTest extends Specification {

private final ParticipantDao participantDao = Mock()
private final ParticipantService service = new ParticipantServiceImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import spock.lang.Specification
import spock.lang.Unroll

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class CatalogUtilsTest extends Specification {
class LegacyCatalogUtilsTest extends Specification {

//
// Tests for toShortForm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import static io.qala.datagen.RandomShortApi.positiveLong
'NoTabCharacter',
'TrailingWhitespace',
])
class SeriesServiceImplTest extends Specification {
class LegacySeriesServiceImplTest extends Specification {
private final ImageService imageService = Mock()
private final SeriesDao seriesDao = Mock()
private final StampsCatalogService michelCatalogService = Mock()
Expand Down Expand Up @@ -758,7 +758,7 @@ class SeriesServiceImplTest extends Specification {
result.createdBy == expectedInfo.createdBy

result.imageIds == expectedImageIds

result.michel?.numbers == expectedMichelNumbers
result.michel?.price == expectedInfo.michelPrice

Expand Down Expand Up @@ -955,7 +955,7 @@ class SeriesServiceImplTest extends Specification {
1 * solovyovCatalogService.findSeriesIdsByNumber(expectedNumber) >> []
}

def 'findBySolovyovNumber() shouldn\'t try to find series info if there are no series'() {
def "findBySolovyovNumber() shouldn't try to find series info if there are no series"() {
given:
solovyovCatalogService.findSeriesIdsByNumber(_ as String) >> []
when:
Expand Down Expand Up @@ -994,7 +994,7 @@ class SeriesServiceImplTest extends Specification {
1 * zagorskiCatalogService.findSeriesIdsByNumber(expectedNumber) >> []
}

def 'findByZagorskiNumber() shouldn\'t try to find series info if there are no series'() {
def "findByZagorskiNumber() shouldn't try to find series info if there are no series"() {
given:
zagorskiCatalogService.findSeriesIdsByNumber(_ as String) >> []
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import spock.lang.Specification
import spock.lang.Unroll

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class StampsCatalogServiceImplTest extends Specification {
class LegacyStampsCatalogServiceImplTest extends Specification {

private final StampsCatalogDao stampsCatalogDao = Mock()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import static io.qala.datagen.RandomValue.between
'NoTabCharacter',
'TrailingWhitespace',
])
class SeriesImportServiceImplTest extends Specification {
class LegacySeriesImportServiceImplTest extends Specification {

private final SeriesImportDao seriesImportDao = Mock()
private final SeriesService seriesService = Mock()
Expand Down Expand Up @@ -329,7 +329,6 @@ class SeriesImportServiceImplTest extends Specification {
assert status?.newStatus == expectedNewStatus
return true
})

}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import static ru.mystamps.web.feature.series.importing.SeriesInfoExtractorServic
'NoTabCharacter',
'TrailingWhitespace',
])
class SeriesInfoExtractorServiceImplTest extends Specification {
class LegacySeriesInfoExtractorServiceImplTest extends Specification {

private final CategoryService categoryService = Mock()
private final CountryService countryService = Mock()
Expand Down Expand Up @@ -327,7 +327,7 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
year == expectedYear
}

def 'extractReleaseYear() shouldn\'t extract dates before 1840'() {
def "extractReleaseYear() shouldn't extract dates before 1840"() {
given:
Integer unsupportedYear = between(0, SeriesValidation.MIN_RELEASE_YEAR - 1).integer()
String fragment = String.valueOf(unsupportedYear)
Expand All @@ -337,7 +337,7 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
year == null
}

def 'extractReleaseYear() shouldn\'t extract dates after 2099'() {
def "extractReleaseYear() shouldn't extract dates after 2099"() {
given:
Integer unsupportedYear = between(MAX_SUPPORTED_RELEASE_YEAR + 1, Integer.MAX_VALUE).integer()
String fragment = String.valueOf(unsupportedYear)
Expand All @@ -348,7 +348,7 @@ class SeriesInfoExtractorServiceImplTest extends Specification {
}

@Unroll
def 'extractReleaseYear() shouldn\'t extract date from "#fragment"'(String fragment) {
def "extractReleaseYear() shouldn't extract date from '#fragment'"(String fragment) {
when:
Integer year = service.extractReleaseYear(fragment)
then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import static io.qala.datagen.RandomShortApi.nullOr
'NoTabCharacter',
'TrailingWhitespace',
])
class TimedSeriesInfoExtractorServiceTest extends Specification {
class LegacyTimedSeriesInfoExtractorServiceTest extends Specification {

private final SeriesInfoExtractorService origService = Mock()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import ru.mystamps.web.tests.Random
import spock.lang.Specification

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class SeriesSalesImportServiceImplTest extends Specification {
class LegacySeriesSalesImportServiceImplTest extends Specification {

private final SeriesSalesImportDao seriesSalesImportDao = Mock()
private final DownloaderService downloaderService = Mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import spock.lang.Specification
import spock.lang.Unroll

@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
class SeriesSalesServiceImplTest extends Specification {
class LegacySeriesSalesServiceImplTest extends Specification {

private final SeriesSalesDao seriesSalesDao = Mock()
private final SeriesSalesService service = new SeriesSalesServiceImpl(
Expand Down
Loading