1   /* Copyright 2002-2022 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.data;
18  
19  
20  import java.io.File;
21  import java.io.FileNotFoundException;
22  import java.net.URISyntaxException;
23  import java.util.regex.Pattern;
24  
25  import org.junit.Assert;
26  import org.junit.Test;
27  import org.orekit.errors.OrekitException;
28  
29  public class FilesListCrawlerTest extends AbstractListCrawlerTest<File> {
30  
31      protected File input(String resource) {
32          try {
33              return new File(FilesListCrawlerTest.class.getClassLoader().getResource(resource).toURI().getPath());
34          } catch (URISyntaxException ue) {
35              Assert.fail(ue.getLocalizedMessage());
36              return null;
37          }
38      }
39  
40      protected FilesListCrawler build(String... inputs) {
41          File[] converted = new File[inputs.length];
42          for (int i = 0; i < inputs.length; ++i) {
43              converted[i] = input(inputs[i]);
44          }
45          return new FilesListCrawler(converted);
46      }
47  
48      @Test
49      public void noElement() {
50          try {
51              File existing   = new File(input("regular-data").getPath());
52              File inexistent = new File(existing.getParent(), "inexistant-directory");
53              new FilesListCrawler(inexistent).feed(Pattern.compile(".*"), new CountingLoader(),
54                                                    DataContext.getDefault().getDataProvidersManager());
55              Assert.fail("an exception should have been thrown");
56          } catch (OrekitException oe) {
57              Assert.assertTrue(oe.getCause() instanceof FileNotFoundException);
58              Assert.assertTrue(oe.getLocalizedMessage().contains("inexistant-directory"));
59          }
60     }
61  
62  }