Skip to content

Commit

Permalink
Merge pull request #66 from gonchik/java-8
Browse files Browse the repository at this point in the history
Java 8
  • Loading branch information
jhansche authored Jul 10, 2019
2 parents baf3741 + 89734c5 commit 00cc037
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ bin/
.classpath
.idea
*.iml

.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,7 @@ private void performConnectionTest(GerritConfiguration configuration, Map<String
try {
query.queryJava("limit:1", false, false, false);
map.put("testResult", Boolean.TRUE);
} catch (IOException e) {
e.printStackTrace();
map.put("testError", e.getMessage());
} catch (GerritQueryException e) {
} catch (IOException | GerritQueryException e) {
e.printStackTrace();
map.put("testError", e.getMessage());
}
Expand All @@ -227,24 +224,34 @@ private void setAllFields(final List<FileItem> items) {
final String fieldName = item.getFieldName();
allFields.add(fieldName);

if (GerritConfiguration.FIELD_HTTP_BASE_URL.equals(fieldName)) {
configurationManager.setHttpBaseUrl(item.getString());
} else if (GerritConfiguration.FIELD_HTTP_USERNAME.equals(fieldName)) {
configurationManager.setHttpUsername(item.getString());
} else if (GerritConfiguration.FIELD_HTTP_PASSWORD.equals(fieldName)) {
configurationManager.setHttpPassword(item.getString());
} else if (GerritConfiguration.FIELD_SSH_HOSTNAME.equals(fieldName)) {
configurationManager.setSshHostname(item.getString());
} else if (GerritConfiguration.FIELD_SSH_USERNAME.equals(fieldName)) {
configurationManager.setSshUsername(item.getString());
} else if (GerritConfiguration.FIELD_SSH_PORT.equals(fieldName)) {
configurationManager.setSshPort(Integer.parseInt(item.getString()));
} else if (GerritConfiguration.FIELD_QUERY_ISSUE.equals(fieldName)) {
configurationManager.setIssueSearchQuery(item.getString());
} else if (GerritConfiguration.FIELD_QUERY_PROJECT.equals(fieldName)) {
configurationManager.setProjectSearchQuery(item.getString());
} else if (GerritConfiguration.FIELD_KNOWN_GERRIT_PROJECTS.equals(fieldName)) {
idsOfSelectedGerritProjects.add(item.getString());
switch (fieldName) {
case GerritConfiguration.FIELD_HTTP_BASE_URL:
configurationManager.setHttpBaseUrl(item.getString());
break;
case GerritConfiguration.FIELD_HTTP_USERNAME:
configurationManager.setHttpUsername(item.getString());
break;
case GerritConfiguration.FIELD_HTTP_PASSWORD:
configurationManager.setHttpPassword(item.getString());
break;
case GerritConfiguration.FIELD_SSH_HOSTNAME:
configurationManager.setSshHostname(item.getString());
break;
case GerritConfiguration.FIELD_SSH_USERNAME:
configurationManager.setSshUsername(item.getString());
break;
case GerritConfiguration.FIELD_SSH_PORT:
configurationManager.setSshPort(Integer.parseInt(item.getString()));
break;
case GerritConfiguration.FIELD_QUERY_ISSUE:
configurationManager.setIssueSearchQuery(item.getString());
break;
case GerritConfiguration.FIELD_QUERY_PROJECT:
configurationManager.setProjectSearchQuery(item.getString());
break;
case GerritConfiguration.FIELD_KNOWN_GERRIT_PROJECTS:
idsOfSelectedGerritProjects.add(item.getString());
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,9 @@ private boolean runCommand(String command) throws IOException {

@SuppressWarnings("deprecation")
private String getCommand(GerritChange change, String args) {
StringBuilder sb = new StringBuilder(BASE_COMMAND);
sb.append(' ');
sb.append(change.getNumber()).append(',').append(change.getPatchSet().getNumber());

// TODO: escape args? Or build manually with String reviewType,int reviewScore,etc..?
sb.append(' ').append(args);
return sb.toString();
return String.format("%s %s,%s %s", BASE_COMMAND, change.getNumber(), change.getPatchSet().getNumber(), args);
}

private boolean runCommands(String[] commands) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static class TimedCache extends LinkedHashMap<String, List<GerritChange>
public TimedCache(final int capacity, final long expiration) {
super(capacity + 1, 1.0f, true);
this.capacity = capacity;
this.timestamps = new LinkedHashMap<String, Long>(capacity + 1, 1.0f, true);
this.timestamps = new LinkedHashMap<>(capacity + 1, 1.0f, true);
this.expiration = expiration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Set<String> getIssueKeys(Issue issue) {

@Override
public List<GerritChange> getReviewsForIssue(Issue issue) throws GerritQueryException {
List<GerritChange> gerritChanges = new ArrayList<GerritChange>();
List<GerritChange> gerritChanges = new ArrayList<>();

Set<String> allIssueKeys = getIssueKeys(issue);
for (String key : allIssueKeys) {
Expand Down Expand Up @@ -97,7 +97,7 @@ protected List<GerritChange> getReviewsFromGerrit(String searchQuery) throws Ger
throw new GerritQueryException("An error occurred while querying for reviews.", e);
}

changes = new ArrayList<GerritChange>(reviews.size());
changes = new ArrayList<>(reviews.size());

for (JSONObject obj : reviews) {
if (obj.has("type") && "stats".equalsIgnoreCase(obj.getString("type"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,13 @@ public List<GerritApproval> getApprovals() {
}

public Map<String, List<GerritApproval>> getApprovalsByLabel() {
Map<String, List<GerritApproval>> map = new HashMap<String, List<GerritApproval>>();
Map<String, List<GerritApproval>> map = new HashMap<>();
List<GerritApproval> l;

for (GerritApproval approval : approvals) {
String type = approval.getType();

l = map.get(type);

if (l == null) {
l = new ArrayList<GerritApproval>();
map.put(type, l);
}
l = map.computeIfAbsent(type, k -> new ArrayList<>());

l.add(approval);
}
Expand All @@ -83,7 +78,7 @@ public Map<String, List<GerritApproval>> getApprovalsByLabel() {
}

public List<GerritApproval> getApprovalsForLabel(String label) {
List<GerritApproval> filtered = new ArrayList<GerritApproval>();
List<GerritApproval> filtered = new ArrayList<>();

if (approvals != null) {
for (GerritApproval approval : approvals) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public GetActionsReply getActions(GetActionsRequest request) {

if (configuration.getSshHostname() == null || configuration.getSshUsername() == null || configuration.getSshPrivateKey() == null) {
// Show not-configured error.
issueActions = new ArrayList<IssueAction>();
issueActions = new ArrayList<>();
issueActions.add(new GenericMessageAction("Configure Gerrit in Administration interface first."));
} else {
// List of items we will be showing in the tab panel.
Expand Down Expand Up @@ -107,7 +107,7 @@ public ShowPanelReply showPanel(ShowPanelRequest arg0) {
private List<IssueAction> getActions(Issue issue) {
log.debug("Getting actions for issue: {0}", issue.getKey());

List<IssueAction> issueActions = new ArrayList<IssueAction>();
List<IssueAction> issueActions = new ArrayList<>();
List<GerritChange> reviews;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public SubtaskReviewsTabPanel(GerritConfiguration configuration,
@Override
public GetActionsReply getActions(GetActionsRequest request) {
Collection<Issue> subtasks = request.issue().getSubTaskObjects();
List<IssueAction> actions = new ArrayList<IssueAction>();
List<IssueAction> actions = new ArrayList<>();
List<GerritChange> changes;

for (Issue subtask : subtasks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public GerritReviewsIssueAgilePanel(IssueReviewsManager reviewsManager) {

@Override
public Map<String, Object> getContextMap(ApplicationUser user, JiraHelper jiraHelper) {
HashMap<String, Object> contextMap = new HashMap<String, Object>();
HashMap<String, Object> contextMap = new HashMap<>();

Issue currentIssue = (Issue) jiraHelper.getContextParams().get(KEY_ISSUE);

try {
List<GerritChange> changes = reviewsManager.getReviewsForIssue(currentIssue);
contextMap.put(KEY_CHANGES, changes);
contextMap.put("atl.gh.issue.details.tab.count", Long.valueOf(changes.size()));
contextMap.put("atl.gh.issue.details.tab.count", (long) changes.size());
} catch (GerritQueryException e) {
contextMap.put(KEY_ERROR, e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Map<String, Object> getContextMap(Map<String, Object> context) {
}
}

List<GerritChange> changes = new ArrayList<GerritChange>();
List<GerritChange> changes = new ArrayList<>();

try {
if (IssueTypeOptionsProvider.wantsIssue(gerritIssueType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public GerritReviewsIssueSidePanel(IssueReviewsManager reviewsManager) {

@Override
public Map<String, Object> getContextMap(ApplicationUser user, JiraHelper jiraHelper) {
HashMap<String, Object> contextMap = new HashMap<String, Object>();
HashMap<String, Object> contextMap = new HashMap<>();

Issue currentIssue = (Issue) jiraHelper.getContextParams().get(KEY_ISSUE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ public boolean shouldDisplay(Map<String, Object> map) {

private boolean isGerritProject(final Issue issue) {

if (issue.getProjectId() == null)
return false;
return issue.getProjectId() != null
&& !isEmpty(gerritConfiguration.getIdsOfKnownGerritProjects())
&& gerritConfiguration.getIdsOfKnownGerritProjects().contains(issue.getProjectId().toString());

return ! isEmpty(gerritConfiguration.getIdsOfKnownGerritProjects()) &&
gerritConfiguration.getIdsOfKnownGerritProjects().contains(issue.getProjectId().toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void setUp() {

// issue key history
when(mockJiraIssueManager.getIssueByKeyIgnoreCase(Mockito.anyString())).thenReturn(mockIssue);
Set<String> allIssueKeys = new HashSet<String>();
Set<String> allIssueKeys = new HashSet<>();
allIssueKeys.add(ISSUE_KEY_OLD);
allIssueKeys.add(ISSUE_KEY_NEW);
when(mockJiraIssueManager.getAllIssueKeys(mockIssue.getId())).thenReturn(allIssueKeys);
Expand All @@ -81,7 +81,7 @@ public void setUp() {
issueReviewsManager = new IssueReviewsImpl(configuration, mockJiraIssueManager) {
@Override protected List<GerritChange> getReviewsFromGerrit(String searchQuery) throws GerritQueryException
{
List<GerritChange> reviews = new ArrayList<GerritChange>();
List<GerritChange> reviews = new ArrayList<>();

if (searchQuery.contains(ISSUE_KEY_OLD)) {
GerritChange oldChangeMock = mock(GerritChange.class);
Expand All @@ -105,7 +105,7 @@ public void testGetReviewsForIssue() throws Exception {
List<GerritChange> reviewsForIssue = issueReviewsManager.getReviewsForIssue(mockIssue);
assertEquals(2, reviewsForIssue.size());

Set<String> reviewSubjects = new HashSet<String>();
Set<String> reviewSubjects = new HashSet<>();
for (GerritChange review : reviewsForIssue) {
reviewSubjects.add(review.getSubject());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class GerritReviewIssueActionTest {
private static final String TEST_FORMATTED_LAST_UPDATED = "Today 11:16 PM";
private static final String TEST_ISO_LAST_UPDATED = "2012-06-17T23:16:00-0400";

private static final ArrayList<GerritApproval> TEST_APPROVALS = new ArrayList<GerritApproval>();
private static final ArrayList<GerritApproval> TEST_APPROVALS = new ArrayList<>();
private static final GerritApproval APPROVAL_NEGATIVE = new GerritApproval();
private static final GerritApproval APPROVAL_POSITIVE = new GerritApproval();
private static final GerritApproval APPROVAL_POSITIVE_2 = new GerritApproval();
Expand Down Expand Up @@ -143,7 +143,7 @@ public void testMostSignificantScore() {
// null input = null output
assertNull(action.getMostSignificantScore(null));

List<GerritApproval> approvals = new ArrayList<GerritApproval>();
List<GerritApproval> approvals = new ArrayList<>();
// empty input = null output
assertNull(action.getMostSignificantScore(approvals));

Expand Down Expand Up @@ -173,7 +173,7 @@ public void testMostSignificantScore() {

@Test
public void testPopulateVelocityParams() {
HashMap<String, Object> velocityParams = new HashMap<String, Object>();
HashMap<String, Object> velocityParams = new HashMap<>();
@SuppressWarnings("rawtypes")
Map expected = setUpExpectedVelocityParams();
action.populateVelocityParams(velocityParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void testGetTimePerformed() {
*/
@Test
public void testPopulateVelocityParamsMap_nullChanges() {
Map<String, Object> params = new HashMap<String, Object>();
Map<String, Object> params = new HashMap<>();
SubtaskReviewsIssueAction obj = new SubtaskReviewsIssueAction(descriptor, subtask, null);

obj.populateVelocityParams(params);
Expand All @@ -117,7 +117,7 @@ public void testPopulateVelocityParamsMap_nullChanges() {
@SuppressWarnings("rawtypes")
@Test
public void testPopulateVelocityParamsMap() {
Map<String, Object> params = new HashMap<String, Object>();
Map<String, Object> params = new HashMap<>();
List changes = EasyList.build(change1, change2);

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void setUpConfiguration() {
}

private List<Issue> setUpSubtasks() {
List<Issue> issues = new ArrayList<Issue>();
List<Issue> issues = new ArrayList<>();

subtask1 = mock(Issue.class);
subtask2 = mock(Issue.class);
Expand Down Expand Up @@ -134,7 +134,7 @@ public void testShowPanelShowPanelRequest_nullSubtasks() {
*/
@Test
public void testShowPanelShowPanelRequest_noSubtasks() {
when(issue.getSubTaskObjects()).thenReturn(new ArrayList<Issue>());
when(issue.getSubTaskObjects()).thenReturn(new ArrayList<>());

SubtaskReviewsTabPanel obj = new SubtaskReviewsTabPanel(configuration, reviewsManager);
// Returns false because the configuration is empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void shouldDisplayWithAlwaysFlag() throws GerritQueryException {
when(gerritConfiguration.getIdsOfKnownGerritProjects()).thenReturn(projects.stream().map(p -> p.getId()
.toString()).collect(Collectors.toList()));

assertTrue(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", (Object) issue)));
assertTrue(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", issue)));
}

@Test
Expand All @@ -89,7 +89,7 @@ public void shouldDisplayEmptyWhiteList(){
when(gerritConfiguration.getShowsEmptyPanel()).thenReturn(false);
when(gerritConfiguration.getIdsOfKnownGerritProjects()).thenReturn(Lists.newArrayList());

assertFalse(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", (Object) issue)));
assertFalse(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", issue)));
}

@Test
Expand All @@ -98,15 +98,15 @@ public void shouldDisplayProjectIsOnWhiteList() throws Exception {
when(issueReviewsManager.getReviewsForIssue(any(Issue.class))).thenReturn(singletonList(new GerritChange()));
when(gerritConfiguration.getIdsOfKnownGerritProjects()).thenReturn(projects.stream().map(p -> p.getId()
.toString()).collect(Collectors.toList()));
assertTrue(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", (Object) issue)));
assertTrue(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", issue)));
}

@Test
public void shouldDisplayProjectIsNotOnWhiteList() {
when(gerritConfiguration.getShowsEmptyPanel()).thenReturn(false);
when(gerritConfiguration.getIdsOfKnownGerritProjects()).thenReturn(projects.stream().filter(project -> ! project
.getId().equals(1L)).map(project -> project.getId().toString()).collect(Collectors.toList()));
assertFalse(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", (Object) issue)));
assertFalse(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", issue)));
}

@Test
Expand All @@ -118,10 +118,10 @@ public void shouldDisplayNoConnectionToGerrit() throws GerritQueryException {
when(issueReviewsManager.getReviewsForIssue(any(Issue.class))).thenThrow(new GerritQueryException());

when(gerritConfiguration.getShowsEmptyPanel()).thenReturn(true);
assertTrue(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", (Object) issue)));
assertTrue(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", issue)));

when(gerritConfiguration.getShowsEmptyPanel()).thenReturn(false);
assertFalse(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", (Object) issue)));
assertFalse(showReviewsWebPanelCondition.shouldDisplay(singletonMap("issue", issue)));
}

@Test
Expand Down

0 comments on commit 00cc037

Please sign in to comment.