2 * DictZip Library test.
4 * Copyright (C) 2016,2019 Hiroshi Miura
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Linking this library statically or dynamically with other modules is
21 * making a combined work based on this library. Thus, the terms and
22 * conditions of the GNU General Public License cover the whole
25 * As a special exception, the copyright holders of this library give you
26 * permission to link this library with independent modules to produce an
27 * executable, regardless of the license terms of these independent
28 * modules, and to copy and distribute the resulting executable under
29 * terms of your choice, provided that you also meet, for each linked
30 * independent module, the terms and conditions of the license of that
31 * module. An independent module is a module which is not derived from
32 * or based on this library. If you modify this library, you may extend
33 * this exception to your version of the library, but you are not
34 * obligated to do so. If you do not wish to do so, delete this
35 * exception statement from your version.
37 package tokyo.northside;
39 import org.junit.jupiter.api.Test;
42 import java.nio.file.Path;
43 import java.nio.file.Paths;
44 import java.util.Objects;
46 import static org.junit.jupiter.api.Assertions.assertFalse;
47 import static org.junit.jupiter.api.Assertions.assertTrue;
48 import static tokyo.northside.io.FileUtils2.contentEquals;
51 * Created by Hiroshi Miura on 16/04/09.
53 public class FileUtils2Test {
56 * Check equals two file contentss.
57 * @throws Exception when fails to open.
60 public void testContentEquals() throws Exception {
61 Path firstFile = Paths.get(
62 Objects.requireNonNull(this.getClass().getResource("/test_util.txt")).toURI());
63 Path secondFile = Paths.get(
64 Objects.requireNonNull(this.getClass().getResource("/test_util1.txt")).toURI());
65 assertTrue(contentEquals(firstFile, secondFile));
69 * Check equals two file paths which is canonical path.
70 * @throws Exception when fails to open.
73 public void testContentEqualsSameCanonicalPath() throws Exception {
74 Path firstFile = Paths.get(
75 Objects.requireNonNull(this.getClass().getResource("/test_util.txt")).toURI());
76 Path secondFile = Paths.get(
77 Objects.requireNonNull(this.getClass().getResource("/test_util.txt")).toURI());
78 assertTrue(contentEquals(firstFile, secondFile));
82 * Check not equals two file contents.
83 * @throws Exception when fails to open.
86 public void testContentEqualsFalse() throws Exception {
87 File firstFile = new File(
88 Objects.requireNonNull(this.getClass().getResource("/test_util.txt")).getFile());
89 File secondFile = new File(
90 Objects.requireNonNull(this.getClass().getResource("/test_util2.txt")).getFile());
91 assertFalse(contentEquals(firstFile, secondFile));
95 * Check equals tow files content with range.
96 * @throws Exception when fails to open.
99 public void testContentEqualsRange() throws Exception {
100 File firstFile = new File(this.getClass().getResource("/test_util.txt").getFile());
101 File secondFile = new File(this.getClass().getResource("/test_util2.txt").getFile());
102 assertTrue(contentEquals(firstFile, secondFile, 10, 64));
106 * Check not equals two file contents with range.
107 * @throws Exception when fails to open.
110 public void testContentEqualsRangeFalse() throws Exception {
111 File firstFile = new File(this.getClass().getResource("/test_util.txt").getFile());
112 File secondFile = new File(this.getClass().getResource("/test_util2.txt").getFile());
113 assertFalse(contentEquals(firstFile, secondFile, 0, 64));