Skip to content

Commit 13ab61e

Browse files
committed
refactor(tests): check not only a presence of an exception itself but also its message.
Follow-up to #925 No functional changes.
1 parent fa2b393 commit 13ab61e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/test/groovy/ru/mystamps/web/feature/image/DatabaseImagePersistenceStrategyTest.groovy

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ class DatabaseImagePersistenceStrategyTest extends Specification {
5050

5151
def "save() should convert IOException to ImagePersistenceException"() {
5252
given:
53-
multipartFile.bytes >> { throw new IOException() }
53+
multipartFile.bytes >> { throw new IOException('oops') }
5454
when:
5555
strategy.save(multipartFile, imageInfoDto)
5656
then:
5757
ImagePersistenceException ex = thrown()
5858
and:
5959
ex.cause instanceof IOException
60+
ex.cause?.message == 'oops'
6061
}
6162

6263
@SuppressWarnings(['ClosureAsLastMethodParameter', 'UnnecessaryReturnKeyword'])

src/test/groovy/ru/mystamps/web/feature/image/FilesystemImagePersistenceStrategyTest.groovy

+4-2
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ class FilesystemImagePersistenceStrategyTest extends Specification {
8383

8484
def 'save() should convert IOException to ImagePersistenceException'() {
8585
given:
86-
strategy.writeToFile(_ as MultipartFile, _ as Path) >> { throw new IOException() }
86+
strategy.writeToFile(_ as MultipartFile, _ as Path) >> { throw new IOException('oops') }
8787
when:
8888
strategy.save(multipartFile, imageInfoDto)
8989
then:
9090
ImagePersistenceException ex = thrown()
9191
and:
9292
ex.cause instanceof IOException
93+
ex.cause?.message == 'oops'
9394
}
9495

9596
//
@@ -113,13 +114,14 @@ class FilesystemImagePersistenceStrategyTest extends Specification {
113114
and:
114115
strategy.generateFilePath(_ as File, _ as ImageInfoDto) >> mockFile
115116
and:
116-
strategy.toByteArray(_ as Path) >> { throw new IOException() }
117+
strategy.toByteArray(_ as Path) >> { throw new IOException('oops') }
117118
when:
118119
strategy.get(imageInfoDto)
119120
then:
120121
ImagePersistenceException ex = thrown()
121122
and:
122123
ex.cause instanceof IOException
124+
ex.cause?.message == 'oops'
123125
}
124126

125127
def 'get() should return result with correct type and content'() {

0 commit comments

Comments
 (0)