/** * Yobi, Project Hosting SW * * Copyright 2013 NAVER Corp. * http://yobi.io * * @Author kjkmadness * * 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 models; import static org.fest.assertions.Assertions.*; import java.text.ParseException; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateUtils; import org.junit.*; public class PullRequestEventTest extends ModelTest<PullRequestEventTest> { @Test public void getPullRequestCommits() throws Exception { // Given PullRequestCommit first = createPullRequestCommit("2013-12-01"); PullRequestCommit second = createPullRequestCommit("2013-12-02"); PullRequestCommit third = createPullRequestCommit("2013-12-03"); String[] ids = {first.id, second.id, third.id}; PullRequestEvent event = new PullRequestEvent(); event.newValue = StringUtils.join(ids, PullRequest.DELIMETER); // When List<PullRequestCommit> commits = event.getPullRequestCommits(); // Then assertThat(commits.get(0).id).isEqualTo(third.id); assertThat(commits.get(1).id).isEqualTo(second.id); assertThat(commits.get(2).id).isEqualTo(first.id); } private PullRequestCommit createPullRequestCommit(String str) throws ParseException { PullRequestCommit commit = new PullRequestCommit(); commit.created = DateUtils.parseDate(str, "yyyy-MM-dd"); commit.save(); return commit; } }