1   /* Copyright 2002-2025 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  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.Test;
21  import org.orekit.errors.OrekitException;
22  
23  import java.io.File;
24  import java.io.FileNotFoundException;
25  import java.net.URISyntaxException;
26  import java.util.regex.Pattern;
27  
28  public class FilesListCrawlerTest extends AbstractListCrawlerTest<File> {
29  
30      protected File input(String resource) {
31          try {
32              return new File(FilesListCrawlerTest.class.getClassLoader().getResource(resource).toURI().getPath());
33          } catch (URISyntaxException ue) {
34              Assertions.fail(ue.getLocalizedMessage());
35              return null;
36          }
37      }
38  
39      protected FilesListCrawler build(String... inputs) {
40          File[] converted = new File[inputs.length];
41          for (int i = 0; i < inputs.length; ++i) {
42              converted[i] = input(inputs[i]);
43          }
44          return new FilesListCrawler(converted);
45      }
46  
47      @Test
48      public void noElement() {
49          try {
50              File existing   = new File(input("regular-data").getPath());
51              File inexistent = new File(existing.getParent(), "inexistant-directory");
52              new FilesListCrawler(inexistent).feed(Pattern.compile(".*"), new CountingLoader(),
53                                                    DataContext.getDefault().getDataProvidersManager());
54              Assertions.fail("an exception should have been thrown");
55          } catch (OrekitException oe) {
56              Assertions.assertTrue(oe.getCause() instanceof FileNotFoundException);
57              Assertions.assertTrue(oe.getLocalizedMessage().contains("inexistant-directory"));
58          }
59     }
60  
61  }