001package org.eclipse.aether.util.artifact; 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.artifact.Artifact; 025import org.eclipse.aether.artifact.DefaultArtifact; 026import org.junit.Test; 027 028/** 029 */ 030public class ArtifactIdUtilsTest 031{ 032 033 @Test 034 public void testToIdArtifact() 035 { 036 Artifact artifact = null; 037 assertSame( null, ArtifactIdUtils.toId( artifact ) ); 038 039 artifact = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); 040 assertEquals( "gid:aid:ext:1.0-20110205.132618-23", ArtifactIdUtils.toId( artifact ) ); 041 042 artifact = new DefaultArtifact( "gid", "aid", "cls", "ext", "1.0-20110205.132618-23" ); 043 assertEquals( "gid:aid:ext:cls:1.0-20110205.132618-23", ArtifactIdUtils.toId( artifact ) ); 044 } 045 046 @Test 047 public void testToIdStrings() 048 { 049 assertEquals( ":::", ArtifactIdUtils.toId( null, null, null, null, null ) ); 050 051 assertEquals( "gid:aid:ext:1", ArtifactIdUtils.toId( "gid", "aid", "ext", "", "1" ) ); 052 053 assertEquals( "gid:aid:ext:cls:1", ArtifactIdUtils.toId( "gid", "aid", "ext", "cls", "1" ) ); 054 } 055 056 @Test 057 public void testToBaseIdArtifact() 058 { 059 Artifact artifact = null; 060 assertSame( null, ArtifactIdUtils.toBaseId( artifact ) ); 061 062 artifact = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); 063 assertEquals( "gid:aid:ext:1.0-SNAPSHOT", ArtifactIdUtils.toBaseId( artifact ) ); 064 065 artifact = new DefaultArtifact( "gid", "aid", "cls", "ext", "1.0-20110205.132618-23" ); 066 assertEquals( "gid:aid:ext:cls:1.0-SNAPSHOT", ArtifactIdUtils.toBaseId( artifact ) ); 067 } 068 069 @Test 070 public void testToVersionlessIdArtifact() 071 { 072 Artifact artifact = null; 073 assertSame( null, ArtifactIdUtils.toId( artifact ) ); 074 075 artifact = new DefaultArtifact( "gid", "aid", "ext", "1" ); 076 assertEquals( "gid:aid:ext", ArtifactIdUtils.toVersionlessId( artifact ) ); 077 078 artifact = new DefaultArtifact( "gid", "aid", "cls", "ext", "1" ); 079 assertEquals( "gid:aid:ext:cls", ArtifactIdUtils.toVersionlessId( artifact ) ); 080 } 081 082 @Test 083 public void testToVersionlessIdStrings() 084 { 085 assertEquals( "::", ArtifactIdUtils.toVersionlessId( null, null, null, null ) ); 086 087 assertEquals( "gid:aid:ext", ArtifactIdUtils.toVersionlessId( "gid", "aid", "ext", "" ) ); 088 089 assertEquals( "gid:aid:ext:cls", ArtifactIdUtils.toVersionlessId( "gid", "aid", "ext", "cls" ) ); 090 } 091 092 @Test 093 public void testEqualsId() 094 { 095 Artifact artifact1 = null; 096 Artifact artifact2 = null; 097 assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); 098 assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); 099 100 artifact1 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); 101 assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); 102 assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); 103 104 artifact2 = new DefaultArtifact( "gidX", "aid", "ext", "1.0-20110205.132618-23" ); 105 assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); 106 assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); 107 108 artifact2 = new DefaultArtifact( "gid", "aidX", "ext", "1.0-20110205.132618-23" ); 109 assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); 110 assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); 111 112 artifact2 = new DefaultArtifact( "gid", "aid", "extX", "1.0-20110205.132618-23" ); 113 assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); 114 assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); 115 116 artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-24" ); 117 assertFalse( ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); 118 assertFalse( ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); 119 120 artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); 121 assertTrue( ArtifactIdUtils.equalsId( artifact1, artifact2 ) ); 122 assertTrue( ArtifactIdUtils.equalsId( artifact2, artifact1 ) ); 123 124 assertTrue( ArtifactIdUtils.equalsId( artifact1, artifact1 ) ); 125 } 126 127 @Test 128 public void testEqualsBaseId() 129 { 130 Artifact artifact1 = null; 131 Artifact artifact2 = null; 132 assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); 133 assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); 134 135 artifact1 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); 136 assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); 137 assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); 138 139 artifact2 = new DefaultArtifact( "gidX", "aid", "ext", "1.0-20110205.132618-23" ); 140 assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); 141 assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); 142 143 artifact2 = new DefaultArtifact( "gid", "aidX", "ext", "1.0-20110205.132618-23" ); 144 assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); 145 assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); 146 147 artifact2 = new DefaultArtifact( "gid", "aid", "extX", "1.0-20110205.132618-23" ); 148 assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); 149 assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); 150 151 artifact2 = new DefaultArtifact( "gid", "aid", "ext", "X.0-20110205.132618-23" ); 152 assertFalse( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); 153 assertFalse( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); 154 155 artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-24" ); 156 assertTrue( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); 157 assertTrue( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); 158 159 artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); 160 assertTrue( ArtifactIdUtils.equalsBaseId( artifact1, artifact2 ) ); 161 assertTrue( ArtifactIdUtils.equalsBaseId( artifact2, artifact1 ) ); 162 163 assertTrue( ArtifactIdUtils.equalsBaseId( artifact1, artifact1 ) ); 164 } 165 166 @Test 167 public void testEqualsVersionlessId() 168 { 169 Artifact artifact1 = null; 170 Artifact artifact2 = null; 171 assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); 172 assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); 173 174 artifact1 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); 175 assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); 176 assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); 177 178 artifact2 = new DefaultArtifact( "gidX", "aid", "ext", "1.0-20110205.132618-23" ); 179 assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); 180 assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); 181 182 artifact2 = new DefaultArtifact( "gid", "aidX", "ext", "1.0-20110205.132618-23" ); 183 assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); 184 assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); 185 186 artifact2 = new DefaultArtifact( "gid", "aid", "extX", "1.0-20110205.132618-23" ); 187 assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); 188 assertFalse( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); 189 190 artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-24" ); 191 assertTrue( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); 192 assertTrue( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); 193 194 artifact2 = new DefaultArtifact( "gid", "aid", "ext", "1.0-20110205.132618-23" ); 195 assertTrue( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact2 ) ); 196 assertTrue( ArtifactIdUtils.equalsVersionlessId( artifact2, artifact1 ) ); 197 198 assertTrue( ArtifactIdUtils.equalsVersionlessId( artifact1, artifact1 ) ); 199 } 200 201}