View Javadoc
1   /*
2    * Copyright (C) 2008, Google Inc. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  
11  package org.eclipse.jgit.treewalk.filter;
12  
13  import static org.junit.Assert.assertFalse;
14  import static org.junit.Assert.assertSame;
15  import static org.junit.Assert.assertTrue;
16  
17  import org.eclipse.jgit.junit.RepositoryTestCase;
18  import org.eclipse.jgit.treewalk.EmptyTreeIterator;
19  import org.eclipse.jgit.treewalk.TreeWalk;
20  import org.junit.Test;
21  
22  public class TreeFilterTest extends RepositoryTestCase {
23  	@Test
24  	public void testALL_IncludesAnything() throws Exception {
25  		try (TreeWalk tw = new TreeWalk(db)) {
26  			tw.addTree(new EmptyTreeIterator());
27  			assertTrue(TreeFilter.ALL.include(tw));
28  		}
29  	}
30  
31  	@Test
32  	public void testALL_ShouldNotBeRecursive() throws Exception {
33  		assertFalse(TreeFilter.ALL.shouldBeRecursive());
34  	}
35  
36  	@Test
37  	public void testALL_IdentityClone() throws Exception {
38  		assertSame(TreeFilter.ALL, TreeFilter.ALL.clone());
39  	}
40  
41  	@Test
42  	public void testNotALL_IncludesNothing() throws Exception {
43  		try (TreeWalk tw = new TreeWalk(db)) {
44  			tw.addTree(new EmptyTreeIterator());
45  			assertFalse(TreeFilter.ALL.negate().include(tw));
46  		}
47  	}
48  
49  	@Test
50  	public void testANY_DIFF_IncludesSingleTreeCase() throws Exception {
51  		try (TreeWalk tw = new TreeWalk(db)) {
52  			tw.addTree(new EmptyTreeIterator());
53  			assertTrue(TreeFilter.ANY_DIFF.include(tw));
54  		}
55  	}
56  
57  	@Test
58  	public void testANY_DIFF_ShouldNotBeRecursive() throws Exception {
59  		assertFalse(TreeFilter.ANY_DIFF.shouldBeRecursive());
60  	}
61  
62  	@Test
63  	public void testANY_DIFF_IdentityClone() throws Exception {
64  		assertSame(TreeFilter.ANY_DIFF, TreeFilter.ANY_DIFF.clone());
65  	}
66  }