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.eclipse.jgit.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertFalse;
15  import static org.junit.Assert.assertNotNull;
16  import static org.junit.Assert.assertNotSame;
17  import static org.junit.Assert.assertSame;
18  import static org.junit.Assert.assertTrue;
19  
20  import org.eclipse.jgit.junit.RepositoryTestCase;
21  import org.eclipse.jgit.treewalk.TreeWalk;
22  import org.junit.Test;
23  
24  public class NotTreeFilterTest extends RepositoryTestCase {
25  	@Test
26  	public void testWrap() throws Exception {
27  		try (TreeWalk tw = new TreeWalk(db)) {
28  			final TreeFilter a = TreeFilter.ALL;
29  			final TreeFilter n = NotTreeFilter.create(a);
30  			assertNotNull(n);
31  			assertTrue(a.include(tw));
32  			assertFalse(n.include(tw));
33  		}
34  	}
35  
36  	@Test
37  	public void testNegateIsUnwrap() throws Exception {
38  		final TreeFilter a = PathFilter.create("a/b");
39  		final TreeFilter n = NotTreeFilter.create(a);
40  		assertSame(a, n.negate());
41  	}
42  
43  	@Test
44  	public void testShouldBeRecursive_ALL() throws Exception {
45  		final TreeFilter a = TreeFilter.ALL;
46  		final TreeFilter n = NotTreeFilter.create(a);
47  		assertEquals(a.shouldBeRecursive(), n.shouldBeRecursive());
48  	}
49  
50  	@Test
51  	public void testShouldBeRecursive_PathFilter() throws Exception {
52  		final TreeFilter a = PathFilter.create("a/b");
53  		assertTrue(a.shouldBeRecursive());
54  		final TreeFilter n = NotTreeFilter.create(a);
55  		assertTrue(n.shouldBeRecursive());
56  	}
57  
58  	@Test
59  	public void testCloneIsDeepClone() throws Exception {
60  		final TreeFilter a = new AlwaysCloneTreeFilter();
61  		assertNotSame(a, a.clone());
62  		final TreeFilter n = NotTreeFilter.create(a);
63  		assertNotSame(n, n.clone());
64  	}
65  
66  	@Test
67  	public void testCloneIsSparseWhenPossible() throws Exception {
68  		final TreeFilter a = TreeFilter.ALL;
69  		assertSame(a, a.clone());
70  		final TreeFilter n = NotTreeFilter.create(a);
71  		assertSame(n, n.clone());
72  	}
73  }