Skip to content
Snippets Groups Projects
Commit 35fe099d authored by Jawnnypoo's avatar Jawnnypoo
Browse files

Convert tests to Kotlin

parent 30b3e574
No related branches found
No related tags found
No related merge requests found
Showing
with 859 additions and 743 deletions
Loading
Loading
@@ -67,7 +67,7 @@ If you are making substantial changes, please refer to Commit 451's style [guide
License
--------
 
Copyright 2016 Commit 451
Copyright 2017 Commit 451
 
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Loading
Loading
Loading
Loading
@@ -30,14 +30,6 @@ open class App : Application() {
 
companion object {
 
/**
* Register our type converters on our singleton LoganSquare get. Needs to be set here
* since we are fetching accounts immediately with LoganSquare
*/
init {
LoganSquare.registerTypeConverter(Uri::class.java, UriTypeConverter())
}
var bus: EventBus = EventBus.getDefault()
lateinit private var instance: App
 
Loading
Loading
@@ -51,7 +43,7 @@ open class App : Application() {
}
 
lateinit var currentAccount: Account
lateinit var gitLab: GitLab
lateinit var gitLab: GitLabService
lateinit var gitLabRss: GitLabRss
lateinit var picasso: Picasso
 
Loading
Loading
@@ -65,6 +57,12 @@ open class App : Application() {
setupLeakCanary()
instance = this
 
/**
* Register our type converters on our singleton LoganSquare get. Needs to be set here
* since we are fetching accounts immediately with LoganSquare
*/
LoganSquare.registerTypeConverter(Uri::class.java, UriTypeConverter())
Prefs.init(this)
//So that we don't get weird half translations
forceLocale(Locale.ENGLISH)
Loading
Loading
This diff is collapsed.
Loading
Loading
@@ -9,22 +9,22 @@ import retrofit2.Retrofit
import retrofit2.converter.scalars.ScalarsConverterFactory
 
/**
* Pulls all the GitLab stuff from the API
* Pulls all the GitLabService stuff from the API
*/
object GitLabFactory {
 
/**
* Create a GitLab get with the current account passed.
* Create a GitLabService get with the current account passed.
* @param account the account to try and log in with
* *
* @return the GitLab get
* @return the GitLabService configured client
*/
fun create(account: Account, client: OkHttpClient): GitLab {
fun create(account: Account, client: OkHttpClient): GitLabService {
return create(account, client, false)
}
 
@VisibleForTesting
fun create(account: Account, client: OkHttpClient, dummyExecutor: Boolean): GitLab {
fun create(account: Account, client: OkHttpClient, dummyExecutor: Boolean): GitLabService {
val retrofitBuilder = Retrofit.Builder()
.baseUrl(account.serverUrl.toString())
.client(client)
Loading
Loading
@@ -36,7 +36,7 @@ object GitLabFactory {
//dumb, to prevent tests from failing }
}
}
return retrofitBuilder.build().create(GitLab::class.java)
return retrofitBuilder.build().create(GitLabService::class.java)
}
}
 
Loading
Loading
@@ -8,7 +8,7 @@ import retrofit2.Retrofit
import retrofit2.converter.simplexml.SimpleXmlConverterFactory
 
/**
* Creates RSS get for GitLab
* Creates RSS get for GitLabService
*/
object GitLabRssFactory {
 
Loading
Loading
This diff is collapsed.
package com.commit451.gitlab.extension
 
import android.net.Uri
import com.commit451.gitlab.api.GitLab
import com.commit451.gitlab.api.GitLabService
import com.commit451.gitlab.model.api.Build
import com.commit451.gitlab.model.api.Project
 
Loading
Loading
@@ -10,5 +10,5 @@ fun Build.getRawBuildUrl(baseUrl: Uri, project: Project): String {
}
 
fun Build.getDownloadBuildUrl(baseUrl: Uri, project: Project): String {
return baseUrl.toString() + GitLab.API_VERSION + "/projects/" + project.id + "/builds/" + id + "/artifacts"
return baseUrl.toString() + GitLabService.API_VERSION + "/projects/" + project.id + "/builds/" + id + "/artifacts"
}
Loading
Loading
@@ -16,7 +16,7 @@ import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.adapter.DividerItemDecoration
import com.commit451.gitlab.adapter.ProjectAdapter
import com.commit451.gitlab.api.GitLab
import com.commit451.gitlab.api.GitLabService
import com.commit451.gitlab.model.api.Group
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.navigation.Navigator
Loading
Loading
@@ -247,7 +247,7 @@ class ProjectsFragment : ButterKnifeFragment() {
loadData()
}
 
fun getGitLab(): GitLab {
fun getGitLab(): GitLabService {
if (listener != null) {
return listener!!.getGitLab()
} else {
Loading
Loading
@@ -258,6 +258,6 @@ class ProjectsFragment : ButterKnifeFragment() {
interface Listener {
fun onProjectClicked(project: Project)
 
fun getGitLab(): GitLab
fun getGitLab(): GitLabService
}
}
Loading
Loading
@@ -159,7 +159,7 @@ public class MergeRequest {
}
 
/**
* Get the changes. Only not null if this merge request was retrieved via {@link com.commit451.gitlab.api.GitLab#getMergeRequestChanges(long, long)}
* Get the changes. Only not null if this merge request was retrieved via {@link com.commit451.gitlab.api.GitLabService#getMergeRequestChanges(long, long)}
* @return the changes
*/
@Nullable
Loading
Loading
Loading
Loading
@@ -60,7 +60,7 @@ class DiffHeaderViewHolder(view: View) : RecyclerView.ViewHolder(view) {
}
 
/**
* This extracts the trailing part of the textTitle as it is displayed in the GitLab web interface
* This extracts the trailing part of the textTitle as it is displayed in the GitLabService web interface
* (the commit message also contains the commit textTitle)
*/
private fun extractMessage(title: String, message: String): String {
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ import butterknife.ButterKnife
import com.commit451.gitlab.R
import com.commit451.gitlab.activity.BaseActivity
import com.commit451.gitlab.adapter.ProjectPagerAdapter
import com.commit451.gitlab.api.GitLab
import com.commit451.gitlab.api.GitLabService
import com.commit451.gitlab.api.GitLabFactory
import com.commit451.gitlab.api.OkHttpClientFactory
import com.commit451.gitlab.fragment.ProjectsFragment
Loading
Loading
@@ -42,7 +42,7 @@ class ProjectFeedWidgetConfigureProjectActivity : BaseActivity(), ProjectsFragme
@BindView(R.id.pager)
lateinit var viewPager: ViewPager
 
lateinit var gitLabInstance: GitLab
lateinit var gitLabInstance: GitLabService
 
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Loading
Loading
@@ -63,7 +63,7 @@ class ProjectFeedWidgetConfigureProjectActivity : BaseActivity(), ProjectsFragme
finish()
}
 
override fun getGitLab(): GitLab {
override fun getGitLab(): GitLabService {
return gitLabInstance
}
}
package com.commit451.gitlab;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import com.bluelinelabs.logansquare.LoganSquare;
import com.commit451.gitlab.api.GitLab;
import com.commit451.gitlab.model.api.FileUploadResponse;
import com.commit451.gitlab.model.api.Group;
import com.commit451.gitlab.model.api.Issue;
import com.commit451.gitlab.model.api.Member;
import com.commit451.gitlab.model.api.MergeRequest;
import com.commit451.gitlab.model.api.Project;
import com.commit451.gitlab.model.api.RepositoryCommit;
import com.commit451.gitlab.model.api.RepositoryTreeObject;
import com.commit451.gitlab.model.api.UserFull;
import com.commit451.gitlab.util.FileUtil;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog;
import java.util.List;
import okhttp3.MultipartBody;
import retrofit2.Response;
import static org.junit.Assert.assertNotNull;
/**
* Tests account login and basic retrieval stuff
*/
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 23)
public class ApiTests {
private static final long FAKE_GROUP_PROJECT_ID = 376651;
private static Project fakeProject;
private static GitLab gitLab;
@BeforeClass
public static void setUp() throws Exception {
//for logging
ShadowLog.stream = System.out;
LoganSquare.registerTypeConverter(Uri.class, new NullTypeConverter());
gitLab = TestUtil.login();
Project projectResponse = gitLab
.getProject(String.valueOf(FAKE_GROUP_PROJECT_ID))
.blockingGet();
assertNotNull(projectResponse);
fakeProject = projectResponse;
}
@Test
public void getProjects() throws Exception {
Response<List<Project>> projectsResponse = gitLab
.getAllProjects()
.blockingGet();
TestUtil.assertRetrofitResponseSuccess(projectsResponse);
assertNotNull(projectsResponse.body());
}
@Test
public void getGroups() throws Exception {
Response<List<Group>> groupResponse = gitLab
.getGroups()
.blockingGet();
TestUtil.assertRetrofitResponseSuccess(groupResponse);
assertNotNull(groupResponse.body());
}
@Test
public void getGroupMembers() throws Exception {
//GitLab group id
long gitLabGroupId = 9970;
Response<List<Member>> groupResponse = gitLab
.getGroupMembers(gitLabGroupId)
.blockingGet();
TestUtil.assertRetrofitResponseSuccess(groupResponse);
assertNotNull(groupResponse.body());
}
@Test
public void getIssues() throws Exception {
String defaultState = RuntimeEnvironment.application.getResources().getString(R.string.issue_state_value_default);
Response<List<Issue>> issuesResponse = gitLab
.getIssues(fakeProject.getId(), defaultState)
.blockingGet();
TestUtil.assertRetrofitResponseSuccess(issuesResponse);
assertNotNull(issuesResponse.body());
}
@Test
public void getFiles() throws Exception {
String defaultBranch = "master";
String currentPath = "";
List<RepositoryTreeObject> treeResponse = gitLab
.getTree(fakeProject.getId(), defaultBranch, currentPath)
.blockingGet();
assertNotNull(treeResponse);
}
@Test
public void getCommits() throws Exception {
String defaultBranch = "master";
List<RepositoryCommit> commitsResponse = gitLab
.getCommits(fakeProject.getId(), defaultBranch, 0)
.blockingGet();
assertNotNull(commitsResponse);
}
@Test
public void getMergeRequests() throws Exception {
String defaultState = RuntimeEnvironment.application.getResources().getString(R.string.merge_request_state_value_default);
Response<List<MergeRequest>> mergeRequestResponse = gitLab
.getMergeRequests(fakeProject.getId(), defaultState)
.blockingGet();
TestUtil.assertRetrofitResponseSuccess(mergeRequestResponse);
assertNotNull(mergeRequestResponse.body());
}
@Test
public void getCurrentUser() throws Exception {
Response<UserFull> userFullResponse = gitLab
.getThisUser()
.blockingGet();
TestUtil.assertRetrofitResponseSuccess(userFullResponse);
assertNotNull(userFullResponse.body());
}
// @Test
public void uploadFile() throws Exception {
Bitmap bitmap = BitmapFactory.decodeResource(RuntimeEnvironment.application.getResources(), R.drawable.ic_fork);
MultipartBody.Part part = FileUtil.INSTANCE.toPart(bitmap, "fork.png");
FileUploadResponse uploadResponseResponse =
gitLab.uploadFile(fakeProject.getId(), part)
.blockingGet();
assertNotNull(uploadResponseResponse);
}
}
\ No newline at end of file
package com.commit451.gitlab
import android.graphics.BitmapFactory
import com.commit451.gitlab.api.GitLabService
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.util.FileUtil
import org.junit.Assert.assertNotNull
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.robolectric.shadows.ShadowLog
/**
* Tests account login and basic retrieval stuff
*/
@RunWith(RobolectricTestRunner::class)
@Config(constants = BuildConfig::class, sdk = intArrayOf(23))
class ApiTests {
companion object {
private val FAKE_GROUP_PROJECT_ID: Long = 376651
private var fakeProject: Project? = null
private var gitLab: GitLabService? = null
@JvmStatic
@BeforeClass
@Throws(Exception::class)
fun setUp() {
//for logging
ShadowLog.stream = System.out
//LoganSquare.registerTypeConverter(Uri::class.java, NullTypeConverter())
gitLab = TestUtil.login()
val projectResponse = gitLab!!
.getProject(FAKE_GROUP_PROJECT_ID.toString())
.blockingGet()
assertNotNull(projectResponse)
fakeProject = projectResponse
}
}
@Test
@Throws(Exception::class)
fun getProjects() {
val projectsResponse = gitLab!!
.getAllProjects()
.blockingGet()
TestUtil.assertRetrofitResponseSuccess(projectsResponse)
assertNotNull(projectsResponse.body())
}
@Test
@Throws(Exception::class)
fun getGroups() {
val groupResponse = gitLab!!
.getGroups()
.blockingGet()
TestUtil.assertRetrofitResponseSuccess(groupResponse)
assertNotNull(groupResponse.body())
}
@Test
@Throws(Exception::class)
fun getGroupMembers() {
//GitLabService group id
val gitLabGroupId: Long = 9970
val groupResponse = gitLab!!
.getGroupMembers(gitLabGroupId)
.blockingGet()
TestUtil.assertRetrofitResponseSuccess(groupResponse)
assertNotNull(groupResponse.body())
}
@Test
@Throws(Exception::class)
fun getIssues() {
val defaultState = RuntimeEnvironment.application.resources.getString(R.string.issue_state_value_default)
val issuesResponse = gitLab!!
.getIssues(fakeProject!!.id, defaultState)
.blockingGet()
TestUtil.assertRetrofitResponseSuccess(issuesResponse)
assertNotNull(issuesResponse.body())
}
@Test
@Throws(Exception::class)
fun getFiles() {
val defaultBranch = "master"
val currentPath = ""
val treeResponse = gitLab!!
.getTree(fakeProject!!.id, defaultBranch, currentPath)
.blockingGet()
assertNotNull(treeResponse)
}
@Test
@Throws(Exception::class)
fun getCommits() {
val defaultBranch = "master"
val commitsResponse = gitLab!!
.getCommits(fakeProject!!.id, defaultBranch, 0)
.blockingGet()
assertNotNull(commitsResponse)
}
@Test
@Throws(Exception::class)
fun getMergeRequests() {
val defaultState = RuntimeEnvironment.application.resources.getString(R.string.merge_request_state_value_default)
val mergeRequestResponse = gitLab!!
.getMergeRequests(fakeProject!!.id, defaultState)
.blockingGet()
TestUtil.assertRetrofitResponseSuccess(mergeRequestResponse)
assertNotNull(mergeRequestResponse.body())
}
@Test
@Throws(Exception::class)
fun getCurrentUser() {
val userFullResponse = gitLab!!
.getThisUser()
.blockingGet()
TestUtil.assertRetrofitResponseSuccess(userFullResponse)
assertNotNull(userFullResponse.body())
}
// @Test
@Throws(Exception::class)
fun uploadFile() {
val bitmap = BitmapFactory.decodeResource(RuntimeEnvironment.application.resources, R.drawable.ic_fork)
val part = FileUtil.toPart(bitmap, "fork.png")
val uploadResponseResponse = gitLab!!.uploadFile(fakeProject!!.id, part)
.blockingGet()
assertNotNull(uploadResponseResponse)
}
}
\ No newline at end of file
package com.commit451.gitlab;
import android.net.Uri;
import com.commit451.gitlab.navigation.RoutingNavigator;
/**
* Checks counting
*/
public class CountingRouter implements RoutingNavigator {
public int issueRouteCount = 0;
public int commitRouteCount = 0;
public int mergeRequestRouteCount = 0;
public int projectRouteCount = 0;
public int buildRouteCount = 0;
public int milestoneRouteCount;
public int unknownRountCount = 0;
@Override
public void onRouteToIssue(String projectNamespace, String projectName, String issueIid) {
issueRouteCount++;
}
@Override
public void onRouteToCommit(String projectNamespace, String projectName, String commitSha) {
commitRouteCount++;
}
@Override
public void onRouteToMergeRequest(String projectNamespace, String projectName, String mergeRequestId) {
mergeRequestRouteCount++;
}
@Override
public void onRouteToProject(String namespace, String projectId) {
projectRouteCount++;
}
@Override
public void onRouteToBuild(String projectNamespace, String projectName, String buildNumber) {
buildRouteCount++;
}
@Override
public void onRouteToMilestone(String projectNamespace, String projectName, String milestoneNumber) {
milestoneRouteCount++;
}
@Override
public void onRouteUnknown(Uri uri) {
unknownRountCount++;
}
}
package com.commit451.gitlab
import android.net.Uri
import com.commit451.gitlab.navigation.RoutingNavigator
/**
* Checks counting
*/
class CountingRouter : RoutingNavigator {
var issueRouteCount = 0
var commitRouteCount = 0
var mergeRequestRouteCount = 0
var projectRouteCount = 0
var buildRouteCount = 0
var milestoneRouteCount: Int = 0
var unknownRountCount = 0
override fun onRouteToIssue(projectNamespace: String, projectName: String, issueIid: String) {
issueRouteCount++
}
override fun onRouteToCommit(projectNamespace: String, projectName: String, commitSha: String) {
commitRouteCount++
}
override fun onRouteToMergeRequest(projectNamespace: String, projectName: String, mergeRequestId: String) {
mergeRequestRouteCount++
}
override fun onRouteToProject(namespace: String, projectId: String) {
projectRouteCount++
}
override fun onRouteToBuild(projectNamespace: String, projectName: String, buildNumber: String) {
buildRouteCount++
}
override fun onRouteToMilestone(projectNamespace: String, projectName: String, milestoneNumber: String) {
milestoneRouteCount++
}
override fun onRouteUnknown(uri: Uri?) {
unknownRountCount++
}
}
package com.commit451.gitlab;
package com.commit451.gitlab
 
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter
 
/**
* The worst type converter you will ever see. Only used in testing if Robolectric decides to break
* and not know what a {@link android.net.Uri} or other class is
* and not know what a [android.net.Uri] or other class is
*/
public class NullTypeConverter extends StringBasedTypeConverter {
class NullTypeConverter : StringBasedTypeConverter<Any>() {
 
@Override
public String convertToString(Object object) {
return null;
override fun convertToString(`object`: Any): String? {
return null
}
 
@Override
public Object getFromString(String string) {
return null;
override fun getFromString(string: String): Any? {
return null
}
}
package com.commit451.gitlab;
package com.commit451.gitlab
 
import android.net.Uri;
import com.commit451.gitlab.navigation.RoutingRouter;
import junit.framework.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog;
import android.net.Uri
import com.commit451.gitlab.navigation.RoutingRouter
import junit.framework.Assert
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.shadows.ShadowLog
 
/**
* Tests account login and basic retrieval stuff
*/
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class RoutingTests {
@RunWith(RobolectricTestRunner::class)
@Config(constants = BuildConfig::class, sdk = intArrayOf(21))
class RoutingTests {
companion object {
 
@BeforeClass
public static void setUp() throws Exception {
//for logging
ShadowLog.stream = System.out;
@BeforeClass
@Throws(Exception::class)
fun setUp() {
//for logging
ShadowLog.stream = System.out
}
}
 
@Test
public void routeIssues() throws Exception {
CountingRouter countingRouter = new CountingRouter();
RoutingRouter router = new RoutingRouter(countingRouter);
Uri issueUrl = Uri.parse("https://gitlab.com/Commit451/LabCoat/issues/153");
router.route(issueUrl);
Assert.assertEquals(1, countingRouter.issueRouteCount);
issueUrl = Uri.parse("gitlab.com/Commit451/LabCoat/issues");
router.route(issueUrl);
Assert.assertEquals(1, countingRouter.projectRouteCount);
issueUrl = Uri.parse("http://example.com/wehostourgitlabserverhere/Commit451/LabCoat/issues");
router.route(issueUrl);
Assert.assertEquals(2, countingRouter.projectRouteCount);
fun routeIssues() {
val countingRouter = CountingRouter()
val router = RoutingRouter(countingRouter)
var issueUrl = Uri.parse("https://gitlab.com/Commit451/LabCoat/issues/153")
router.route(issueUrl)
Assert.assertEquals(1, countingRouter.issueRouteCount)
issueUrl = Uri.parse("gitlab.com/Commit451/LabCoat/issues")
router.route(issueUrl)
Assert.assertEquals(1, countingRouter.projectRouteCount)
issueUrl = Uri.parse("http://example.com/wehostourgitlabserverhere/Commit451/LabCoat/issues")
router.route(issueUrl)
Assert.assertEquals(2, countingRouter.projectRouteCount)
}
 
@Test
public void routeCommits() throws Exception {
Uri commitUrl = Uri.parse("https://gitlab.com/Commit451/LabCoat/commit/434fb013607836620819fae09f23a72d88369d3d");
CountingRouter countingRouter = new CountingRouter();
RoutingRouter router = new RoutingRouter(countingRouter);
router.route(commitUrl);
Assert.assertEquals(1, countingRouter.commitRouteCount);
commitUrl = Uri.parse("http://gitlab.com/Commit451/LabCoat/commits");
router.route(commitUrl);
Assert.assertEquals(1, countingRouter.projectRouteCount);
fun routeCommits() {
var commitUrl = Uri.parse("https://gitlab.com/Commit451/LabCoat/commit/434fb013607836620819fae09f23a72d88369d3d")
val countingRouter = CountingRouter()
val router = RoutingRouter(countingRouter)
router.route(commitUrl)
Assert.assertEquals(1, countingRouter.commitRouteCount)
commitUrl = Uri.parse("http://gitlab.com/Commit451/LabCoat/commits")
router.route(commitUrl)
Assert.assertEquals(1, countingRouter.projectRouteCount)
//Test for subdomain
commitUrl = Uri.parse("http://example.com/wehostourgitlabserverhere/Commit451/LabCoat/commit/434fb013607836620819fae09f23a72d88369d3d");
router.route(commitUrl);
Assert.assertEquals(2, countingRouter.commitRouteCount);
commitUrl = Uri.parse("http://example.com/wehostourgitlabserverhere/Commit451/LabCoat/commit/434fb013607836620819fae09f23a72d88369d3d")
router.route(commitUrl)
Assert.assertEquals(2, countingRouter.commitRouteCount)
}
 
@Test
public void routeMergeRequests() throws Exception {
Uri mergeRequestUrl = Uri.parse("https://gitlab.com/Commit451/LabCoat/merge_requests/14");
CountingRouter countingRouter = new CountingRouter();
RoutingRouter router = new RoutingRouter(countingRouter);
router.route(mergeRequestUrl);
Assert.assertEquals(1, countingRouter.mergeRequestRouteCount);
mergeRequestUrl = Uri.parse("http://gitlab.com/Commit451/LabCoat/commits");
router.route(mergeRequestUrl);
Assert.assertEquals(1, countingRouter.projectRouteCount);
fun routeMergeRequests() {
var mergeRequestUrl = Uri.parse("https://gitlab.com/Commit451/LabCoat/merge_requests/14")
val countingRouter = CountingRouter()
val router = RoutingRouter(countingRouter)
router.route(mergeRequestUrl)
Assert.assertEquals(1, countingRouter.mergeRequestRouteCount)
mergeRequestUrl = Uri.parse("http://gitlab.com/Commit451/LabCoat/commits")
router.route(mergeRequestUrl)
Assert.assertEquals(1, countingRouter.projectRouteCount)
//Test for subdomain
mergeRequestUrl = Uri.parse("http://example.com/wehostourgitlabserverhere/Commit451/LabCoat/merge_requests/13");
router.route(mergeRequestUrl);
Assert.assertEquals(2, countingRouter.mergeRequestRouteCount);
mergeRequestUrl = Uri.parse("http://example.com/wehostourgitlabserverhere/Commit451/LabCoat/merge_requests/13")
router.route(mergeRequestUrl)
Assert.assertEquals(2, countingRouter.mergeRequestRouteCount)
}
}
\ No newline at end of file
package com.commit451.gitlab;
package com.commit451.gitlab
 
import org.robolectric.TestLifecycleApplication;
import org.robolectric.TestLifecycleApplication
 
import java.lang.reflect.Method;
import java.lang.reflect.Method
 
/**
* Test version of our Application class, used by Robolectric
*/
public class TestApp extends App implements TestLifecycleApplication {
class TestApp : App(), TestLifecycleApplication {
 
@Override
public void beforeTest(Method method) {
override fun beforeTest(method: Method) {
 
}
 
@Override
public void prepareTest(Object test) {
override fun prepareTest(test: Any) {
 
}
 
@Override
public void afterTest(Method method) {
override fun afterTest(method: Method) {
 
}
 
@Override
protected void setupCrashReporting() {
override fun setupCrashReporting() {
//Intentionally left blank
}
 
@Override
protected void setupLeakCanary() {
override fun setupLeakCanary() {
//Intentionally left blank
}
 
@Override
protected void setupMultidex() {
override fun setupMultidex() {
//Intentionally left blank
}
}
package com.commit451.gitlab;
import android.net.Uri;
import com.commit451.gitlab.api.GitLab;
import com.commit451.gitlab.api.GitLabFactory;
import com.commit451.gitlab.api.OkHttpClientFactory;
import com.commit451.gitlab.model.Account;
import com.commit451.gitlab.model.api.UserLogin;
import org.junit.Assert;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Response;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Util for testing
*/
public class TestUtil {
public static GitLab login() throws Exception {
//log in
Account account = new Account();
account.setServerUrl(Uri.parse("https://gitlab.com/"));
OkHttpClient.Builder gitlabClientBuilder = OkHttpClientFactory.INSTANCE.create(account);
if (BuildConfig.DEBUG) {
gitlabClientBuilder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
}
GitLab gitLab = GitLabFactory.INSTANCE.create(account, gitlabClientBuilder.build(), true);
Response<UserLogin> loginResponse = gitLab
.loginWithUsername("TestAllTheThings", "testing123")
.blockingGet();
assertTrue(loginResponse.isSuccessful());
assertNotNull(loginResponse.body().getPrivateToken());
//attach the newly retrieved private token
account.setPrivateToken(loginResponse.body().getPrivateToken());
return gitLab;
}
public static void assertRetrofitResponseSuccess(Response response) throws Exception {
if (!response.isSuccessful()) {
Assert.assertTrue(response.errorBody().string(), response.isSuccessful());
}
}
}
package com.commit451.gitlab
import android.net.Uri
import com.commit451.gitlab.api.GitLabService
import com.commit451.gitlab.api.GitLabFactory
import com.commit451.gitlab.api.OkHttpClientFactory
import com.commit451.gitlab.model.Account
import okhttp3.logging.HttpLoggingInterceptor
import org.junit.Assert
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import retrofit2.Response
/**
* Util for testing
*/
object TestUtil {
@Throws(Exception::class)
fun login(): GitLabService {
//log in
val account = Account()
account.serverUrl = Uri.parse("https://gitlab.com/")
val gitlabClientBuilder = OkHttpClientFactory.create(account)
if (BuildConfig.DEBUG) {
gitlabClientBuilder.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
}
val gitLab = GitLabFactory.create(account, gitlabClientBuilder.build(), true)
val loginResponse = gitLab
.loginWithUsername("TestAllTheThings", "testing123")
.blockingGet()
assertTrue(loginResponse.isSuccessful)
assertNotNull(loginResponse.body().privateToken)
//attach the newly retrieved private token
account.privateToken = loginResponse.body().privateToken
return gitLab
}
@Throws(Exception::class)
fun assertRetrofitResponseSuccess(response: Response<*>) {
if (!response.isSuccessful) {
Assert.assertTrue(response.errorBody().string(), response.isSuccessful)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment