View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.util.graph.versions;
20  
21  import java.util.function.Predicate;
22  
23  import org.eclipse.aether.artifact.Artifact;
24  import org.eclipse.aether.collection.VersionFilter.VersionFilterContext;
25  import org.eclipse.aether.util.graph.version.PredicateVersionFilter;
26  import org.junit.jupiter.api.Test;
27  
28  import static org.junit.jupiter.api.Assertions.*;
29  
30  public class PredicateVersionFilterTest extends AbstractVersionFilterTest {
31  
32      @Test
33      void testFilterVersions() {
34          Predicate<Artifact> oddVersions = a -> Integer.parseInt(a.getVersion()) % 2 != 0;
35          PredicateVersionFilter filter = new PredicateVersionFilter(oddVersions);
36          VersionFilterContext ctx = newContext("g:a:[1,9]", "1", "2", "3", "4", "5", "6", "7", "8", "9");
37          filter.filterVersions(ctx);
38          assertVersions(ctx, "1", "3", "5", "7", "9");
39      }
40  
41      @Test
42      void testDeriveChildFilter() {
43          PredicateVersionFilter filter = new PredicateVersionFilter(a -> true);
44          assertSame(filter, derive(filter, "g:a:1"));
45      }
46  
47      @Test
48      void testEquals() {
49          Predicate<Artifact> falsePredicate = a -> false;
50          Predicate<Artifact> truePredicate = a -> true;
51          PredicateVersionFilter filter1 = new PredicateVersionFilter(falsePredicate);
52          PredicateVersionFilter filter2 = new PredicateVersionFilter(falsePredicate);
53          PredicateVersionFilter filter3 = new PredicateVersionFilter(truePredicate);
54          assertNotEquals(null, filter1);
55          assertEquals(filter1, filter2);
56          assertNotEquals(filter2, filter3);
57          assertEquals(filter1, new PredicateVersionFilter(falsePredicate));
58      }
59  }