Skip to content

Commit 5c319ec

Browse files
committed
TimedImagePreviewStrategy.createPreview(): add unit test.
Fix #581 No functional changes.
1 parent d20e632 commit 5c319ec

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright (C) 2009-2017 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+
import spock.lang.Unroll
24+
25+
@SuppressWarnings(['ClassJavadoc', 'MethodName', 'NoDef', 'NoTabCharacter', 'TrailingWhitespace'])
26+
class TimedImagePreviewStrategyTest extends Specification {
27+
28+
private final ImagePreviewStrategy origStrategy = Mock()
29+
30+
private ImagePreviewStrategy strategy
31+
32+
def setup() {
33+
strategy = new TimedImagePreviewStrategy(NOPLogger.NOP_LOGGER, origStrategy)
34+
}
35+
36+
//
37+
// Tests for createPreview()
38+
//
39+
40+
@Unroll
41+
@SuppressWarnings(['ClosureAsLastMethodParameter', 'FactoryMethodName', 'UnnecessaryReturnKeyword'])
42+
def 'createPreview() should pass #expectedData and return result of original strategy'(byte[] expectedData) {
43+
given:
44+
byte[] expectedResult = 'foobar'.bytes
45+
when:
46+
byte[] result = strategy.createPreview(expectedData)
47+
then:
48+
1 * origStrategy.createPreview({ byte[] image ->
49+
image == expectedData
50+
return true
51+
}) >> expectedResult
52+
and:
53+
result == expectedResult
54+
where:
55+
expectedData | _
56+
null | _
57+
'foo'.bytes | _
58+
59+
}
60+
61+
}

0 commit comments

Comments
 (0)