001package org.eclipse.aether.util.graph.versions; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.junit.Assert.*; 023 024import org.eclipse.aether.collection.VersionFilter; 025import org.eclipse.aether.collection.VersionFilter.VersionFilterContext; 026import org.eclipse.aether.util.graph.version.ContextualSnapshotVersionFilter; 027import org.eclipse.aether.util.graph.version.SnapshotVersionFilter; 028import org.junit.Test; 029 030public class ContextualSnapshotVersionFilterTest 031 extends AbstractVersionFilterTest 032{ 033 034 @Test 035 public void testFilterVersions() 036 throws Exception 037 { 038 VersionFilter filter = new ContextualSnapshotVersionFilter(); 039 VersionFilterContext ctx = newContext( "g:a:[1,9]", "1", "2-SNAPSHOT" ); 040 filter.filterVersions( ctx ); 041 assertVersions( ctx, "1", "2-SNAPSHOT" ); 042 043 ctx = newContext( "g:a:[1,9]", "1", "2-SNAPSHOT" ); 044 derive( filter, "g:a:1" ).filterVersions( ctx ); 045 assertVersions( ctx, "1" ); 046 047 ctx = newContext( "g:a:[1,9]", "1", "2-SNAPSHOT" ); 048 session.setConfigProperty( ContextualSnapshotVersionFilter.CONFIG_PROP_ENABLE, "true" ); 049 derive( filter, "g:a:1-SNAPSHOT" ).filterVersions( ctx ); 050 assertVersions( ctx, "1" ); 051 } 052 053 @Test 054 public void testDeriveChildFilter() 055 { 056 ContextualSnapshotVersionFilter filter = new ContextualSnapshotVersionFilter(); 057 assertTrue( derive( filter, "g:a:1" ) instanceof SnapshotVersionFilter ); 058 assertSame( null, derive( filter, "g:a:1-SNAPSHOT" ) ); 059 session.setConfigProperty( ContextualSnapshotVersionFilter.CONFIG_PROP_ENABLE, "true" ); 060 assertTrue( derive( filter, "g:a:1-SNAPSHOT" ) instanceof SnapshotVersionFilter ); 061 } 062 063 @SuppressWarnings( "EqualsWithItself" ) 064 @Test 065 public void testEquals() 066 { 067 ContextualSnapshotVersionFilter filter = new ContextualSnapshotVersionFilter(); 068 assertFalse( filter.equals( null ) ); 069 assertTrue( filter.equals( filter ) ); 070 assertTrue( filter.equals( new ContextualSnapshotVersionFilter() ) ); 071 } 072 073}