1
1
package org .lib .test ;
2
2
3
- import static org .junit .Assert .assertEquals ;
4
- import static org .junit .Assert .assertNotNull ;
5
-
6
3
import java .awt .Graphics ;
7
4
import java .awt .Image ;
8
5
import java .awt .image .BufferStrategy ;
9
6
import java .awt .image .BufferedImage ;
7
+ import java .io .File ;
8
+ import java .io .FileInputStream ;
10
9
import java .io .IOException ;
10
+ import java .io .InputStream ;
11
+ import java .util .Properties ;
11
12
12
13
import javax .swing .ImageIcon ;
13
14
import javax .swing .JFrame ;
21
22
import org .junit .Test ;
22
23
import org .xml .sax .SAXException ;
23
24
25
+ import static org .junit .Assert .*;
26
+
24
27
/**
25
28
*
26
29
*/
@@ -32,7 +35,7 @@ public class LibraryTest {
32
35
* a problem: for now - using snapshots/test_041.jpg
33
36
*/
34
37
@ Test
35
- public void intelligenceTest () throws IOException , ParserConfigurationException , SAXException {
38
+ public void intelligenceSingleTest () throws IOException , ParserConfigurationException , SAXException {
36
39
final String image = "snapshots/test_041.jpg" ;
37
40
38
41
/*
@@ -65,7 +68,57 @@ public void intelligenceTest() throws IOException, ParserConfigurationException,
65
68
assertEquals ("LM025BD" , spz );
66
69
67
70
// System.out.println(intel.lastProcessDuration());
71
+ carSnap .close ();
72
+ }
73
+
74
+ @ Test
75
+ public void testAllSnapshots () throws Exception {
76
+ String snapshotDirPath = "src/test/resources/snapshots" ;
77
+ String resultsPath = "src/test/resources/results.properties" ;
78
+ InputStream resultsStream = new FileInputStream (new File (resultsPath ));
79
+
80
+ Properties properties = new Properties ();
81
+ properties .load (resultsStream );
82
+ resultsStream .close ();
83
+ assertTrue (properties .size () > 0 );
84
+
85
+ File snapshotDir = new File (snapshotDirPath );
86
+ File [] snapshots = snapshotDir .listFiles ();
87
+ assertTrue (snapshots .length > 0 );
88
+
89
+ Intelligence intel = new Intelligence ();
90
+ assertNotNull (intel );
68
91
92
+ //TODO not working images
93
+ String [] ignores = {"test_048.jpg" , "test_025.jpg" , "test_075.jpg" };
94
+
95
+ for (File snap : snapshots ) {
96
+ CarSnapshot carSnap = new CarSnapshot (new FileInputStream (snap ));
97
+ assertNotNull ("carSnap is null" , carSnap );
98
+ assertNotNull ("carSnap.image is null" , carSnap .image );
99
+
100
+ String numberPlate = intel .recognize (carSnap );
101
+ assertNotNull ("The licence plate is null - are you sure the image has the correct color space?" , numberPlate );
102
+
103
+ String snapName = snap .getName ();
104
+ String plateCorrect = properties .getProperty (snapName );
105
+ assertNotNull (plateCorrect );
106
+
107
+ boolean ignoreFlag = false ;
108
+ System .out .println (snapName );
109
+ for (String ignore : ignores ) {
110
+ if (ignore .equals (snapName )) {
111
+ ignoreFlag = true ;
112
+ break ;
113
+ }
114
+ }
115
+ if (ignoreFlag ) {
116
+ continue ;
117
+ }
118
+
119
+ assertEquals ("The file \" " + snapName + "\" was incorrectly recognized." , plateCorrect , numberPlate );
120
+ carSnap .close ();
121
+ }
69
122
}
70
123
71
124
public class TestImageDraw {
0 commit comments