1
+ /*
2
+ ------------------------------------------------------------------------
3
+ JavaANPR - Automatic Number Plate Recognition System for Java
4
+ ------------------------------------------------------------------------
5
+
6
+ This file is a part of the JavaANPR, licensed under the terms of the
7
+ Educational Community License
8
+
9
+ Copyright (c) 2006-2007 Ondrej Martinsky. All rights reserved
10
+
11
+ This Original Work, including software, source code, documents, or
12
+ other related items, is being provided by the copyright holder(s)
13
+ subject to the terms of the Educational Community License. By
14
+ obtaining, using and/or copying this Original Work, you agree that you
15
+ have read, understand, and will comply with the following terms and
16
+ conditions of the Educational Community License:
17
+
18
+ Permission to use, copy, modify, merge, publish, distribute, and
19
+ sublicense this Original Work and its documentation, with or without
20
+ modification, for any purpose, and without fee or royalty to the
21
+ copyright holder(s) is hereby granted, provided that you include the
22
+ following on ALL copies of the Original Work or portions thereof,
23
+ including modifications or derivatives, that you make:
24
+
25
+ # The full text of the Educational Community License in a location
26
+ viewable to users of the redistributed or derivative work.
27
+
28
+ # Any pre-existing intellectual property disclaimers, notices, or terms
29
+ and conditions.
30
+
31
+ # Notice of any changes or modifications to the Original Work,
32
+ including the date the changes were made.
33
+
34
+ # Any modifications of the Original Work must be distributed in such a
35
+ manner as to avoid any confusion with the Original Work of the
36
+ copyright holders.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
39
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
42
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
43
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
44
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45
+
46
+ The name and trademarks of copyright holder(s) may NOT be used in
47
+ advertising or publicity pertaining to the Original or Derivative Works
48
+ without specific, written prior permission. Title to copyright in the
49
+ Original Work and any associated documentation will at all times remain
50
+ with the copyright holders.
51
+
52
+ If you want to alter upon this work, you MUST attribute it in
53
+ a) all source files
54
+ b) on every place, where is the copyright of derivated work
55
+ exactly by the following label :
56
+
57
+ ---- label begin ----
58
+ This work is a derivate of the JavaANPR. JavaANPR is a intellectual
59
+ property of Ondrej Martinsky. Please visit http://javaanpr.sourceforge.net
60
+ for more info about JavaANPR.
61
+ ---- label end ----
62
+
63
+ ------------------------------------------------------------------------
64
+ http://javaanpr.sourceforge.net
65
+ ------------------------------------------------------------------------
66
+ */
67
+
68
+ package net .sf .javaanpr .gui ;
69
+
70
+ import static org .junit .Assert .assertEquals ;
71
+ import static org .junit .Assert .fail ;
72
+
73
+ import java .awt .image .BufferedImage ;
74
+ import java .io .File ;
75
+ import java .io .FileInputStream ;
76
+ import java .io .IOException ;
77
+ import java .io .InputStream ;
78
+
79
+ import net .sf .javaanpr .imageanalysis .CarSnapshot ;
80
+ import net .sf .javaanpr .test .util .TestUtility ;
81
+
82
+ import org .junit .Test ;
83
+
84
+ /**
85
+ * Tests the class {@link ReportGenerator}
86
+ */
87
+ public class ReportGeneratorTest {
88
+ TestUtility testUtility = new TestUtility ();
89
+ private CarSnapshot carSnapshot ;
90
+
91
+ /**
92
+ * Tests {@link ReportGenerator#insertImage(BufferedImage, String, int, int)} with valid inputs.
93
+ * @throws IllegalArgumentException the illegal argument exception
94
+ * @throws IOException Signals that an I/O exception has occurred.
95
+ */
96
+ @ Test
97
+ public void testInsertImage_Valid () throws IllegalArgumentException , IOException {
98
+ final int w = 1 ;
99
+ final CarSnapshot carSnapshot = new CarSnapshot ("snapshots/test_001.jpg" );
100
+ final BufferedImage image = carSnapshot .renderGraph ();
101
+ final String cls = "test" ;
102
+ final int h = 1 ;
103
+ final ReportGenerator reportGenerator = new ReportGenerator ("target/test-classes/" );
104
+ try {
105
+ reportGenerator .insertImage (image , cls , w , h );
106
+ } catch (final Exception e ) {
107
+ fail ();
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Tests {@link ReportGenerator#insertImage(BufferedImage, String, int, int)} throws an error when the input is not
113
+ * valid.
114
+ * @throws IllegalArgumentException the illegal argument exception
115
+ * @throws IOException Signals that an I/O exception has occurred.
116
+ */
117
+ @ Test
118
+ public void testInsertImage_BadInput () throws IllegalArgumentException , IOException {
119
+ try {
120
+ final ReportGenerator reportGenerator = new ReportGenerator ("target/test-classes/" );
121
+ final int w = 1 ;
122
+ final CarSnapshot carSnapshot = new CarSnapshot ("snapshots/test_00.jpg" );
123
+ final BufferedImage image = carSnapshot .renderGraph ();
124
+ final String cls = "test" ;
125
+ final int h = 1 ;
126
+ reportGenerator .insertImage (image , cls , w , h );
127
+ } catch (final Exception e ) {
128
+ assertEquals ("input == null!" , e .getMessage ());
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Tests {@link ReportGenerator#insertText(String)} with null input.
134
+ * @throws IllegalArgumentException the illegal argument exception
135
+ * @throws IOException Signals that an I/O exception has occurred.
136
+ */
137
+ @ Test
138
+ public void testInsertText_NullInput () throws IllegalArgumentException , IOException {
139
+ try {
140
+ final ReportGenerator reportGenerator = new ReportGenerator ("target/test-classes/" );
141
+ reportGenerator .insertText (null );
142
+ } catch (final Exception e ) {
143
+ fail ();
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Tests {@link ReportGenerator#insertText(String)} with empty string input.
149
+ * @throws IllegalArgumentException the illegal argument exception
150
+ * @throws IOException Signals that an I/O exception has occurred.
151
+ */
152
+ @ Test
153
+ public void testInsertText_EmptyInput () throws IllegalArgumentException , IOException {
154
+ try {
155
+ final ReportGenerator reportGenerator = new ReportGenerator ("target/test-classes/" );
156
+ reportGenerator .insertText ("" );
157
+ } catch (final Exception e ) {
158
+ fail ();
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Tests {@link ReportGenerator#saveStreamToFile(java.io.InputStream, java.io.File)} with null input stream.
164
+ * @throws IllegalArgumentException the illegal argument exception
165
+ * @throws IOException Signals that an I/O exception has occurred.
166
+ */
167
+ @ Test
168
+ public void testSaveStreamToFile_InvalidInput () throws IllegalArgumentException , IOException {
169
+ try {
170
+ final ReportGenerator reportGenerator = new ReportGenerator ("target/test-classes/" );
171
+ final InputStream inStream = null ;
172
+ final File io = new File ("target/test-classes/out.txt" );
173
+ reportGenerator .saveStreamToFile (null , io );
174
+ } catch (final Exception e ) {
175
+ assertEquals (null , e .getMessage ());
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Tests {@link ReportGenerator#saveStreamToFile(java.io.InputStream, java.io.File)} with null output stream input.
181
+ * @throws IllegalArgumentException the illegal argument exception
182
+ * @throws IOException Signals that an I/O exception has occurred.
183
+ */
184
+ @ Test
185
+ public void testSaveStreamToFile_InvalidOutput () throws IllegalArgumentException , IOException {
186
+ try {
187
+ final ReportGenerator reportGenerator = new ReportGenerator ("target/test-classes/" );
188
+ final InputStream inStream = new FileInputStream ("src/test/resources/snapshots/test_001.jpg" );
189
+ reportGenerator .saveStreamToFile (inStream , null );
190
+ } catch (final Exception e ) {
191
+ assertEquals (null , e .getMessage ());
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Tests {@link ReportGenerator#saveStreamToFile(java.io.InputStream, java.io.File)} with valid input and output
197
+ * stream.
198
+ * @throws IllegalArgumentException the illegal argument exception
199
+ * @throws IOException Signals that an I/O exception has occurred.
200
+ */
201
+ @ Test
202
+ public void testSaveStreamToFile_Valid () throws IllegalArgumentException , IOException {
203
+ final ReportGenerator reportGenerator = new ReportGenerator ("target/test-classes/" );
204
+ final InputStream inStream = new FileInputStream ("src/test/resources/snapshots/test_001.jpg" );
205
+ final File io = new File ("target/test-classes/out.txt" );
206
+ reportGenerator .saveStreamToFile (inStream , io );
207
+ StringBuilder sb = new StringBuilder ();
208
+ sb = testUtility .readFile ("target/test-classes/out.txt" );
209
+ assertEquals (true , sb .toString ().contains ("Hewlett-Packard" ));
210
+ }
211
+
212
+ /**
213
+ * Tests {@link ReportGenerator#saveImage(BufferedImage, String)} with valid input.
214
+ * @throws IllegalArgumentException the illegal argument exception
215
+ * @throws IOException Signals that an I/O exception has occurred.
216
+ */
217
+ @ Test
218
+ public void testSaveImage_Valid () throws IllegalArgumentException , IOException {
219
+ try {
220
+ final ReportGenerator reportGenerator = new ReportGenerator ("target/test-classes/" );
221
+ final CarSnapshot carSnapshot = new CarSnapshot ("snapshots/test_001.jpg" );
222
+ final BufferedImage image = carSnapshot .renderGraph ();
223
+ final String cls = "test" ;
224
+ final int h = 0 ;
225
+ final int w = 0 ;
226
+ reportGenerator .saveImage (image , "png" );
227
+ } catch (final Exception e ) {
228
+ fail (e .getMessage ());
229
+ }
230
+ }
231
+
232
+ /**
233
+ * Tests {@link ReportGenerator#saveImage(BufferedImage, String)} with invalid string input and a valid image input
234
+ * @throws IllegalArgumentException the illegal argument exception
235
+ * @throws IOException Signals that an I/O exception has occurred.
236
+ */
237
+ @ Test
238
+ public void testSaveImage_InvalidInput () throws IllegalArgumentException , IOException {
239
+ try {
240
+ final ReportGenerator reportGenerator = new ReportGenerator ("target/test-classes/" );
241
+ final CarSnapshot carSnapshot = new CarSnapshot ("snapshots/test_001.jpg" );
242
+ final BufferedImage image = carSnapshot .renderGraph ();
243
+ reportGenerator .saveImage (image , "target/test-classes/txt" );
244
+ } catch (final Exception e ) {
245
+ assertEquals ("Unsupported file format" , e .getMessage ());
246
+ }
247
+ }
248
+ }
0 commit comments