View Javadoc
1   /*
2    * XML Format Maven Plugin (https://github.com/acegi/xml-format-maven-plugin)
3    *
4    * Copyright 2011-2025 Acegi Technology Pty Limited.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package au.com.acegi.xmlformat;
19  
20  import static au.com.acegi.xmlformat.IOUtil.hash;
21  import static au.com.acegi.xmlformat.TestUtil.getResource;
22  import static org.hamcrest.CoreMatchers.is;
23  import static org.hamcrest.MatcherAssert.assertThat;
24  
25  import java.io.IOException;
26  import java.io.InputStream;
27  
28  import org.junit.jupiter.api.Test;
29  
30  /**
31   * Tests {@link IOUtil}.
32   */
33  public class IOTest {
34  
35      @Test
36      void hash1() throws IOException {
37          testHash("/test1-in.xml", 459_402_491L);
38      }
39  
40      @Test
41      void hash2() throws IOException {
42          testHash("/test2-in.xml", 1_687_393_391L);
43      }
44  
45      @Test
46      void hashInvalid() throws IOException {
47          testHash("/invalid.xml", 2_274_913_643L);
48      }
49  
50      private void testHash(final String resource, final long expected) throws IOException {
51          try (InputStream in = getResource(resource)) {
52              final long hash = hash(in);
53              assertThat(hash, is(expected));
54          }
55      }
56  
57  }