2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2009 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.updatecenter.common;
22 import org.junit.Test;
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.Iterator;
27 import java.util.List;
29 import static org.hamcrest.core.Is.is;
30 import static org.junit.Assert.assertFalse;
31 import static org.junit.Assert.assertThat;
32 import static org.junit.Assert.assertTrue;
34 public class ArtifactTest {
37 public void compare() {
38 Artifact a = new FakeArtifact("a");
39 Artifact b = new FakeArtifact("b");
40 Artifact c = new Plugin("c");
42 List<Artifact> list = Arrays.asList(b, a, c);
43 Collections.sort(list);
44 assertThat(list.get(0), is(a));
45 assertThat(list.get(1), is(b));
46 assertThat(list.get(2), is(c));
50 public void sortReleases() {
51 FakeArtifact artifact = new FakeArtifact("fake");
52 artifact.addRelease(Version.create("2.0"));
53 artifact.addRelease(Version.create("1.1"));
54 artifact.addRelease(Version.create("1.5"));
56 Iterator<Release> it = artifact.getReleases().iterator();
57 assertThat(it.next().getVersion().getName(), is("1.1"));
58 assertThat(it.next().getVersion().getName(), is("1.5"));
59 assertThat(it.next().getVersion().getName(), is("2.0"));
63 public void equals() {
64 FakeArtifact foo = new FakeArtifact("foo");
65 assertTrue(foo.equals(new FakeArtifact("foo")));
66 assertTrue(foo.equals(foo));
67 assertFalse(foo.equals(new FakeArtifact("bar")));
71 class FakeArtifact extends Artifact {
73 protected FakeArtifact(String key) {