/*
 * Copyright (c) 2015 PocketHub
 *
 * 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 com.github.pockethub.android.util;

import com.meisolsson.githubsdk.model.Repository;
import com.meisolsson.githubsdk.model.User;

import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

public class ConvertUtilsTest {

	private static final String REPO_NAME_FIRST_PART = "first";
	private static final String REPO_NAME_SECOND_PART = "second";
	private static final String REPO_NAME = REPO_NAME_FIRST_PART + "/" + REPO_NAME_SECOND_PART;
	private static final String REPO_OWNER_LOGIN = "repo_owner_login";

	private Repository repo;

	@Before
	public void setup() {
		User user = User.builder()
				.login(REPO_OWNER_LOGIN)
				.build();

		repo = Repository.builder().
				name(REPO_NAME)
				.owner(user)
				.build();
	}

	@Test
	public void testOriginalRepoIsNotChanged() throws Exception {
		ConvertUtils.eventRepoToRepo(repo);
		assertThat(repo.owner().login(), equalTo(REPO_OWNER_LOGIN));
		assertThat(repo.name(), equalTo(REPO_NAME));
	}

	@Test
	public void testNewRepoIsCreated() throws Exception {
		Repository newRepo = ConvertUtils.eventRepoToRepo(repo);
		assertThat(newRepo.owner().login(), equalTo(REPO_NAME_FIRST_PART));
		assertThat(newRepo.name(), equalTo(REPO_NAME_SECOND_PART));
	}

}

@@ -635,16 +635,138 @@
 .util;%0A%0A
+import android.os.Parcel;%0Aimport android.support.annotation.Nullable;%0A%0Aimport com.meisolsson.githubsdk.model.GitHubEvent;%0A
 import c
@@ -1244,16 +1244,17 @@
 D_PART;%0A
+%0A
 %09private
@@ -1258,92 +1258,25 @@
 ate 
-static final String REPO_OWNER_LOGIN = %22repo_owner_login%22;%0A%0A%09private Repository repo
+GitHubEvent event
 ;%0A%0A%09
@@ -1310,153 +1310,896 @@
 ) %7B%0A
+%0A
 %09%09
-User user = User.builder()%0A%09%09%09%09.login(REPO_OWNER_LOGIN)%0A%09%09%09%09.build();%0A%0A%09%09repo = Repository.builder().%0A%09%09%09%09name(REPO_NAME)%0A%09%09%09%09.owner(user)%0A%09%09%09%09
+event = GitHubEvent.builder()%0A                .repo(new GitHubEvent.RepoIdentifier() %7B%0A                    @Nullable%0A                    @Override%0A                    public Long id() %7B%0A                        return null;%0A                    %7D%0A%0A                    @Nullable%0A                    @Override%0A                    public String url() %7B%0A                        return null;%0A                    %7D%0A%0A                    @Nullable%0A                    @Override%0A                    public String repoWithUserName() %7B%0A                        return REPO_NAME;%0A                    %7D%0A%0A                    @Override%0A                    public int describeContents() %7B%0A                        return 0;%0A                    %7D%0A%0A                    @Override%0A                    public void writeToParcel(Parcel parcel, int i) %7B%0A%0A                    %7D%0A                %7D)%0A                
 .bui
@@ -2301,36 +2301,44 @@
 eventRepoToRepo(
+event.
 repo
+()
 );%0A%09%09assertThat(
@@ -2341,77 +2341,34 @@
 hat(
-repo.owner().login(), equalTo(REPO_OWNER_LOGIN));%0A%09%09assertThat(repo.n
+event.repo().repoWithUserN
 ame(
@@ -2509,20 +2509,28 @@
 oToRepo(
+event.
 repo
+()
 );%0A%09%09ass

Fix unit tests