Restructure code to make it less triage-specific
This commit is contained in:
71
src/test/java/io/spring/issuebot/RepositoryMonitorTests.java
Normal file
71
src/test/java/io/spring/issuebot/RepositoryMonitorTests.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.issuebot;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.spring.issuebot.github.GitHubOperations;
|
||||
import io.spring.issuebot.github.Issue;
|
||||
import io.spring.issuebot.github.Page;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Tests for {@link RepositoryMonitor}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class RepositoryMonitorTests {
|
||||
|
||||
private final GitHubOperations gitHub = mock(GitHubOperations.class);
|
||||
|
||||
private final IssueListener issueListenerOne = mock(IssueListener.class);
|
||||
|
||||
private final IssueListener issueListenerTwo = mock(IssueListener.class);
|
||||
|
||||
private final RepositoryMonitor repositoryMonitor = new RepositoryMonitor(this.gitHub,
|
||||
new MonitoredRepository("test", "test"),
|
||||
Arrays.asList(this.issueListenerOne, this.issueListenerTwo));
|
||||
|
||||
@Test
|
||||
public void repositoryWithNoIssues() {
|
||||
given(this.gitHub.getIssues("test", "test")).willReturn(null);
|
||||
this.repositoryMonitor.monitor();
|
||||
verifyNoMoreInteractions(this.issueListenerOne, this.issueListenerTwo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositoryWithOpenIssues() {
|
||||
@SuppressWarnings("unchecked")
|
||||
Page<Issue> page = mock(Page.class);
|
||||
Issue issueOne = new Issue(null, null, null, null, null);
|
||||
Issue issueTwo = new Issue(null, null, null, null, null);
|
||||
given(page.getContent()).willReturn(Arrays.asList(issueOne, issueTwo));
|
||||
given(this.gitHub.getIssues("test", "test")).willReturn(page);
|
||||
this.repositoryMonitor.monitor();
|
||||
verify(this.issueListenerOne).onOpenIssue(issueOne);
|
||||
verify(this.issueListenerOne).onOpenIssue(issueTwo);
|
||||
verify(this.issueListenerTwo).onOpenIssue(issueOne);
|
||||
verify(this.issueListenerTwo).onOpenIssue(issueTwo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,12 +33,6 @@ import org.springframework.test.web.client.response.DefaultResponseCreator;
|
||||
import org.springframework.util.Base64Utils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import io.spring.issuebot.github.Comment;
|
||||
import io.spring.issuebot.github.GitHubTemplate;
|
||||
import io.spring.issuebot.github.Issue;
|
||||
import io.spring.issuebot.github.Page;
|
||||
import io.spring.issuebot.github.RegexLinkParser;
|
||||
|
||||
import static org.hamcrest.Matchers.equalToIgnoringCase;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
@@ -20,9 +20,6 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.spring.issuebot.github.LinkParser;
|
||||
import io.spring.issuebot.github.RegexLinkParser;
|
||||
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.issuebot.triage.filter;
|
||||
package io.spring.issuebot.triage;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -33,16 +33,13 @@ public class LabelApplyingTriageListenerTests {
|
||||
|
||||
private GitHubOperations gitHub = mock(GitHubOperations.class);
|
||||
|
||||
private final MonitoredRepository repository = new MonitoredRepository();
|
||||
|
||||
private final LabelApplyingTriageListener listener = new LabelApplyingTriageListener(
|
||||
this.gitHub);
|
||||
this.gitHub, "test");
|
||||
|
||||
@Test
|
||||
public void requiresTriage() {
|
||||
Issue issue = new Issue(null, null, null, null, null);
|
||||
this.repository.setLabel("test");
|
||||
this.listener.requiresTriage(issue, this.repository);
|
||||
this.listener.requiresTriage(issue);
|
||||
verify(this.gitHub).addLabel(issue, "test");
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.issuebot.triage.filter;
|
||||
package io.spring.issuebot.triage;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.issuebot.triage.filter;
|
||||
package io.spring.issuebot.triage;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.issuebot.triage.filter;
|
||||
package io.spring.issuebot.triage;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.issuebot.triage;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.spring.issuebot.github.GitHubOperations;
|
||||
import io.spring.issuebot.github.Issue;
|
||||
import io.spring.issuebot.github.Page;
|
||||
import io.spring.issuebot.triage.filter.TriageFilter;
|
||||
import io.spring.issuebot.triage.filter.TriageFilters;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Tests for {@link RepositoryMonitor}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class RepositoryMonitorTests {
|
||||
|
||||
private final GitHubOperations gitHub = mock(GitHubOperations.class);
|
||||
|
||||
private final TriageFilters triageFilters = mock(TriageFilters.class);
|
||||
|
||||
private final TriageFilter triageFilter = mock(TriageFilter.class);
|
||||
|
||||
private final TriageListener listener = mock(TriageListener.class);
|
||||
|
||||
@Test
|
||||
public void repositoryWithNoIssues() {
|
||||
MonitoredRepository repository = new MonitoredRepository();
|
||||
repository.setOrganization("test");
|
||||
repository.setName("test");
|
||||
RepositoryMonitor repositoryMonitor = new RepositoryMonitor(this.gitHub,
|
||||
this.triageFilters, this.listener, Arrays.asList(repository));
|
||||
given(this.triageFilters.filterForRepository(repository))
|
||||
.willReturn(this.triageFilter);
|
||||
given(this.gitHub.getIssues("test", "test")).willReturn(null);
|
||||
|
||||
repositoryMonitor.monitor();
|
||||
|
||||
verifyNoMoreInteractions(this.listener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositoryWithIssueRequiringTriage() {
|
||||
MonitoredRepository repository = new MonitoredRepository();
|
||||
repository.setOrganization("test");
|
||||
repository.setName("test");
|
||||
RepositoryMonitor repositoryMonitor = new RepositoryMonitor(this.gitHub,
|
||||
this.triageFilters, this.listener, Arrays.asList(repository));
|
||||
given(this.triageFilters.filterForRepository(repository))
|
||||
.willReturn(this.triageFilter);
|
||||
@SuppressWarnings("unchecked")
|
||||
Page<Issue> page = mock(Page.class);
|
||||
Issue issue = new Issue(null, null, null, null, null);
|
||||
given(page.getContent()).willReturn(Arrays.asList(issue));
|
||||
given(this.gitHub.getIssues("test", "test")).willReturn(page);
|
||||
given(this.triageFilter.triaged(issue)).willReturn(false);
|
||||
|
||||
repositoryMonitor.monitor();
|
||||
|
||||
verify(this.listener).requiresTriage(issue, repository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositoryWithIssueThatHasAlreadyBeenTriaged() {
|
||||
MonitoredRepository repository = new MonitoredRepository();
|
||||
repository.setOrganization("test");
|
||||
repository.setName("test");
|
||||
RepositoryMonitor repositoryMonitor = new RepositoryMonitor(this.gitHub,
|
||||
this.triageFilters, this.listener, Arrays.asList(repository));
|
||||
given(this.triageFilters.filterForRepository(repository))
|
||||
.willReturn(this.triageFilter);
|
||||
@SuppressWarnings("unchecked")
|
||||
Page<Issue> page = mock(Page.class);
|
||||
Issue issue = new Issue(null, null, null, null, null);
|
||||
given(page.getContent()).willReturn(Arrays.asList(issue));
|
||||
given(this.gitHub.getIssues("test", "test")).willReturn(page);
|
||||
given(this.triageFilter.triaged(issue)).willReturn(true);
|
||||
|
||||
repositoryMonitor.monitor();
|
||||
|
||||
verifyNoMoreInteractions(this.listener);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.issuebot.triage;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.spring.issuebot.IssueListener;
|
||||
import io.spring.issuebot.github.Issue;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Tests for {@link TriageIssueListener}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class TriageIssueListenerTests {
|
||||
|
||||
private final TriageFilter triageFilterOne = mock(TriageFilter.class);
|
||||
|
||||
private final TriageFilter triageFilterTwo = mock(TriageFilter.class);
|
||||
|
||||
private final TriageListener listener = mock(TriageListener.class);
|
||||
|
||||
private final IssueListener issueListener = new TriageIssueListener(
|
||||
Arrays.asList(this.triageFilterOne, this.triageFilterTwo), this.listener);
|
||||
|
||||
@Test
|
||||
public void listenerIsCalledWhenIssueRequiresTriage() {
|
||||
Issue issue = new Issue(null, null, null, null, null);
|
||||
given(this.triageFilterOne.triaged(issue)).willReturn(false);
|
||||
given(this.triageFilterTwo.triaged(issue)).willReturn(false);
|
||||
this.issueListener.onOpenIssue(issue);
|
||||
verify(this.triageFilterOne).triaged(issue);
|
||||
verify(this.triageFilterTwo).triaged(issue);
|
||||
verify(this.listener).requiresTriage(issue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listenerIsNotCalledWhenIssueHasAlreadyBeenTriaged() {
|
||||
Issue issue = new Issue(null, null, null, null, null);
|
||||
given(this.triageFilterOne.triaged(issue)).willReturn(true);
|
||||
this.issueListener.onOpenIssue(issue);
|
||||
verify(this.triageFilterOne).triaged(issue);
|
||||
verifyNoMoreInteractions(this.triageFilterTwo, this.listener);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.issuebot.triage.filter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import io.spring.issuebot.github.Issue;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
/**
|
||||
* Tests for {@link DelegatingTriageFilter}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class DelegatingTriageFilterTests {
|
||||
|
||||
private TriageFilter delegate1 = mock(TriageFilter.class);
|
||||
|
||||
private TriageFilter delegate2 = mock(TriageFilter.class);
|
||||
|
||||
private TriageFilter delegate3 = mock(TriageFilter.class);
|
||||
|
||||
private TriageFilter filter = new DelegatingTriageFilter(
|
||||
Arrays.asList(this.delegate1, this.delegate2, this.delegate3));
|
||||
|
||||
@Test
|
||||
public void notTriagedWhenAllDelegatesReturnFalse() {
|
||||
Issue issue = new Issue(null, null, null, null, null);
|
||||
assertThat(this.filter.triaged(issue), is(false));
|
||||
verify(this.delegate1).triaged(issue);
|
||||
verify(this.delegate2).triaged(issue);
|
||||
verify(this.delegate3).triaged(issue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void triagedAsSoonAsADelegateReturnsTrue() {
|
||||
Issue issue = new Issue(null, null, null, null, null);
|
||||
given(this.delegate2.triaged(issue)).willReturn(true);
|
||||
assertThat(this.filter.triaged(issue), is(true));
|
||||
verify(this.delegate1).triaged(issue);
|
||||
verify(this.delegate2).triaged(issue);
|
||||
verifyNoMoreInteractions(this.delegate3);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user