Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1c85cb0a03b7959507c2c86015d199cb6fc30379 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/******************************************************************************
 *  Copyright (c) 2011 GitHub Inc.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *    Kevin Sawicki (GitHub Inc.) - initial API and implementation
 *****************************************************************************/
package org.eclipse.egit.github.core.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.egit.github.core.RepositoryId;
import org.junit.Test;

/**
 * Unit tests of {@link RepositoryId}
 */
public class RepositoryIdTest {

	/**
	 * Create with null id string
	 */
	@Test
	public void createFromNullString() {
		assertNull(RepositoryId.createFromId(null));
	}

	/**
	 * Create with empty id string
	 */
	@Test
	public void createFromEmptyString() {
		assertNull(RepositoryId.createFromId(""));
	}

	/**
	 * Create from valid id string
	 */
	@Test
	public void createFromString() {
		RepositoryId id = RepositoryId.createFromId("a/b");
		assertNotNull(id);
		assertEquals("a", id.getOwner());
		assertEquals("b", id.getName());
	}

	/**
	 * Create from null URL
	 */
	@Test
	public void createFromNullUrl() {
		assertNull(RepositoryId.createFromUrl((URL) null));
	}

	/**
	 * Create from null URL
	 */
	@Test
	public void createFromNullStringUrl() {
		assertNull(RepositoryId.createFromUrl((String) null));
	}

	/**
	 * Create from malformed string URL
	 *
	 * @throws MalformedURLException
	 */
	@Test
	public void createFromMalformedStringUrl() throws MalformedURLException {
		assertNull(RepositoryId.createFromUrl("http://:http//"));
	}

	/**
	 * From from invalid URL
	 *
	 * @throws MalformedURLException
	 */
	@Test
	public void createFromInvalidUrl1() throws MalformedURLException {
		assertNull(RepositoryId.createFromUrl(new URL("http://github.com")));
	}

	/**
	 * From from invalid URL
	 *
	 * @throws MalformedURLException
	 */
	@Test
	public void createFromInvalidUrl2() throws MalformedURLException {
		assertNull(RepositoryId.createFromUrl(new URL("http://github.com/")));
	}

	/**
	 * From from invalid URL
	 *
	 * @throws MalformedURLException
	 */
	@Test
	public void createFromInvalidUrl3() throws MalformedURLException {
		assertNull(RepositoryId.createFromUrl(new URL("http://github.com/a")));
	}

	/**
	 * From from invalid URL
	 *
	 * @throws MalformedURLException
	 */
	@Test
	public void createFromInvalidUrl4() throws MalformedURLException {
		assertNull(RepositoryId.createFromUrl(new URL("http://github.com/a/")));
	}

	/**
	 * From from valid URL
	 *
	 * @throws MalformedURLException
	 */
	@Test
	public void createFromStringUrl() throws MalformedURLException {
		RepositoryId id = RepositoryId
				.createFromUrl("http://github.com/user/project");
		assertNotNull(id);
		assertEquals("user", id.getOwner());
		assertEquals("project", id.getName());
	}

	/**
	 * From from valid URL
	 *
	 * @throws MalformedURLException
	 */
	@Test
	public void createFromUrl() throws MalformedURLException {
		RepositoryId id = RepositoryId.createFromUrl(new URL(
				"http://github.com/user/project"));
		assertNotNull(id);
		assertEquals("user", id.getOwner());
		assertEquals("project", id.getName());
	}

	/**
	 * Create with null owner
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createNullOwner() {
		RepositoryId.create(null, "my proj");
	}

	/**
	 * Create with empty owner
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createEmptyOwner() {
		RepositoryId.create("", "myproj");
	}

	/**
	 * Create with null name
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createNullName() {
		RepositoryId.create("user", null);
	}

	/**
	 * Create with empty name
	 */
	@Test(expected = IllegalArgumentException.class)
	public void createEmptyName() {
		RepositoryId.create("user", "");
	}

	/**
	 * Create from static method
	 */
	@Test
	public void create() {
		RepositoryId id = RepositoryId.create("own", "project");
		assertEquals("own", id.getOwner());
		assertEquals("project", id.getName());
	}

	/**
	 * Verify repository id equality
	 */
	@Test
	public void equality() {
		RepositoryId id1 = new RepositoryId("auser", "bproject");
		RepositoryId id2 = new RepositoryId("auser", "bproject");
		RepositoryId id3 = new RepositoryId("auser", "bproject2");
		assertTrue(id1.equals(id1));
		assertTrue(id1.equals(id2));
		assertFalse(id1.equals(id3));
		Object string = "content";
		assertFalse(id1.equals(string));
		assertEquals(id1.hashCode(), id2.hashCode());
		assertEquals(id1.toString(), id2.toString());
	}
}

Back to the top