-
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathMockOwner.java
More file actions
126 lines (103 loc) · 2.7 KB
/
MockOwner.java
File metadata and controls
126 lines (103 loc) · 2.7 KB
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
package jenkins.plugins.github.api.mock;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public abstract class MockOwner<T> extends MockObject {
private final Map<String, MockRepository> repositories = new HashMap<>();
private final String login;
private String name;
private String avatarUrl;
private String blog;
private String location;
private String email;
private Set<String> following = new HashSet<>();
MockOwner(MockGitHub app, String login) {
super(app);
this.login = login;
}
public Map<String, MockRepository> repositories() {
return repositories;
}
public T withPublicRepo(String name) {
return withRepo(name, false);
}
public T withPrivateRepo(String name) {
return withRepo(name, true);
}
public T withRepo(String name, boolean isPrivate) {
MockRepository repo = new MockRepository(app(), this, name).withPrivate(isPrivate);
repositories.put(name, repo);
return (T) this;
}
public String getLogin() {
return login;
}
public String getName() {
return name;
}
public T withName(String name) {
this.name = name;
touch();
return (T) this;
}
public abstract String getType();
public String getAvatarUrl() {
return avatarUrl;
}
public T withAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
touch();
return (T) this;
}
public String getBlog() {
return blog;
}
public T withBlog(String blog) {
this.blog = blog;
touch();
return (T) this;
}
public String getLocation() {
return location;
}
public T withLocation(String location) {
this.location = location;
touch();
return (T) this;
}
public String getEmail() {
return email;
}
public T withEmail(String email) {
this.email = email;
touch();
return (T) this;
}
public int getPublicRepos() {
int result = 0;
for (MockRepository r : repositories.values()) {
if (!r.isPrivate()) {
result++;
}
}
return result;
}
public int getFollowers() {
int count = 0;
for (MockOwner<?> owner : app().owners()) {
if (owner.following.contains(login)) {
count++;
}
}
return count;
}
public int getFollowing() {
return following.size();
}
public T withFollowing(Set<String> following) {
this.following = following;
touch();
return (T) this;
}
}