1111import java .math .BigInteger ;
1212import java .net .InetAddress ;
1313import java .net .URI ;
14+ import java .net .URL ;
1415import java .net .URISyntaxException ;
1516import java .net .UnknownHostException ;
1617import java .util .HashMap ;
@@ -52,12 +53,23 @@ public void test() throws InvalidDatabaseException, IOException,
5253 }
5354
5455 @ Test
55- public void testNoIpV4SearchTree () throws IOException , URISyntaxException {
56+ public void testNoIpV4SearchTreeFile () throws IOException , URISyntaxException {
5657 URI file = ReaderTest .class .getResource (
5758 "/maxmind-db/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb" )
5859 .toURI ();
5960
6061 Reader reader = new Reader (new File (file ));
62+ testNoIpV4SearchTree (reader );
63+ }
64+ @ Test
65+ public void testNoIpV4SearchTreeURL () throws IOException , URISyntaxException {
66+ URL resource = ReaderTest .class .getResource (
67+ "/maxmind-db/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb" );
68+ Reader reader = new Reader (resource );
69+ testNoIpV4SearchTree (reader );
70+ }
71+ private void testNoIpV4SearchTree (Reader reader ) throws IOException , URISyntaxException {
72+
6173
6274 assertEquals ("::/64" , reader .get (InetAddress .getByName ("1.1.1.1" ))
6375 .textValue ());
@@ -66,11 +78,22 @@ public void testNoIpV4SearchTree() throws IOException, URISyntaxException {
6678 }
6779
6880 @ Test
69- public void testDecodingTypes () throws URISyntaxException , IOException {
81+ public void testDecodingTypesFile () throws URISyntaxException , IOException {
7082 URI file = ReaderTest .class .getResource (
7183 "/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb" ).toURI ();
7284
7385 Reader reader = new Reader (new File (file ));
86+ testDecodingTypes (reader );
87+ }
88+ @ Test
89+ public void testDecodingTypesURL () throws URISyntaxException , IOException {
90+ URL resource = ReaderTest .class .getResource (
91+ "/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb" );
92+
93+ Reader reader = new Reader (resource );
94+ testDecodingTypes (reader );
95+ }
96+ private void testDecodingTypes (Reader reader ) throws URISyntaxException , IOException {
7497 JsonNode record = reader .get (InetAddress .getByName ("::1.1.1.0" ));
7598
7699 assertEquals (true , record .get ("boolean" ).booleanValue ());
@@ -114,11 +137,22 @@ public void testDecodingTypes() throws URISyntaxException, IOException {
114137 }
115138
116139 @ Test
117- public void testZeros () throws URISyntaxException , IOException {
140+ public void testZerosFile () throws URISyntaxException , IOException {
118141 URI file = ReaderTest .class .getResource (
119142 "/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb" ).toURI ();
120143
121144 Reader reader = new Reader (new File (file ));
145+ testZeros (reader );
146+ }
147+ @ Test
148+ public void testZerosURL () throws URISyntaxException , IOException {
149+ URL resource = ReaderTest .class .getResource (
150+ "/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb" );
151+
152+ Reader reader = new Reader (resource );
153+ testZeros (reader );
154+ }
155+ private void testZeros (Reader reader ) throws URISyntaxException , IOException {
122156 JsonNode record = reader .get (InetAddress .getByName ("::" ));
123157
124158 assertEquals (false , record .get ("boolean" ).booleanValue ());
@@ -146,13 +180,25 @@ public void testZeros() throws URISyntaxException, IOException {
146180 public ExpectedException thrown = ExpectedException .none ();
147181
148182 @ Test
149- public void testBrokenDatabase () throws URISyntaxException , IOException {
183+ public void testBrokenDatabaseFile () throws URISyntaxException , IOException {
150184 URI file = ReaderTest .class
151185 .getResource (
152186 "/maxmind-db/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb" )
153187 .toURI ();
154188
155189 Reader reader = new Reader (new File (file ));
190+ testBrokenDatabase (reader );
191+ }
192+ @ Test
193+ public void testBrokenDatabaseURL () throws URISyntaxException , IOException {
194+ URL resource = ReaderTest .class
195+ .getResource (
196+ "/maxmind-db/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb" );
197+
198+ Reader reader = new Reader (resource );
199+ testBrokenDatabase (reader );
200+ }
201+ private void testBrokenDatabase (Reader reader ) throws URISyntaxException , IOException {
156202
157203 this .thrown .expect (InvalidDatabaseException .class );
158204 this .thrown
@@ -162,14 +208,28 @@ public void testBrokenDatabase() throws URISyntaxException, IOException {
162208 }
163209
164210 @ Test
165- public void testBrokenSearchTreePointer () throws URISyntaxException ,
211+ public void testBrokenSearchTreePointerFile () throws URISyntaxException ,
166212 IOException {
167213 URI file = ReaderTest .class
168214 .getResource (
169215 "/maxmind-db/test-data/MaxMind-DB-test-broken-pointers-24.mmdb" )
170216 .toURI ();
171217
172218 Reader reader = new Reader (new File (file ));
219+ testBrokenSearchTreePointer (reader );
220+ }
221+ @ Test
222+ public void testBrokenSearchTreePointerURL () throws URISyntaxException ,
223+ IOException {
224+ URL resource = ReaderTest .class
225+ .getResource (
226+ "/maxmind-db/test-data/MaxMind-DB-test-broken-pointers-24.mmdb" );
227+
228+ Reader reader = new Reader (resource );
229+ testBrokenSearchTreePointer (reader );
230+ }
231+ private void testBrokenSearchTreePointer (Reader reader ) throws URISyntaxException ,
232+ IOException {
173233
174234 this .thrown .expect (InvalidDatabaseException .class );
175235 this .thrown
@@ -179,14 +239,28 @@ public void testBrokenSearchTreePointer() throws URISyntaxException,
179239 }
180240
181241 @ Test
182- public void testBrokenDataPointer () throws UnknownHostException ,
242+ public void testBrokenDataPointerFile () throws UnknownHostException ,
183243 IOException , URISyntaxException {
184244 URI file = ReaderTest .class
185245 .getResource (
186246 "/maxmind-db/test-data/MaxMind-DB-test-broken-pointers-24.mmdb" )
187247 .toURI ();
188248
189249 Reader reader = new Reader (new File (file ));
250+ testBrokenDataPointer (reader );
251+ }
252+ @ Test
253+ public void testBrokenDataPointerURL () throws UnknownHostException ,
254+ IOException , URISyntaxException {
255+ URL resource = ReaderTest .class
256+ .getResource (
257+ "/maxmind-db/test-data/MaxMind-DB-test-broken-pointers-24.mmdb" );
258+
259+ Reader reader = new Reader (resource );
260+ testBrokenDataPointer (reader );
261+ }
262+ private void testBrokenDataPointer (Reader reader ) throws UnknownHostException ,
263+ IOException , URISyntaxException {
190264
191265 this .thrown .expect (InvalidDatabaseException .class );
192266 this .thrown
0 commit comments