Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE-104 Refactor WebconnectionException to kotlin #4956

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -28,8 +28,8 @@
import org.catrobat.catroid.testsuites.annotations.Cat;
import org.catrobat.catroid.web.CatrobatWebClient;
import org.catrobat.catroid.web.ServerCalls;
import org.catrobat.catroid.web.WebConnectionException;
import org.catrobat.catroid.web.WebScratchProgramException;
import org.catrobat.catroid.web.WebconnectionException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -44,7 +44,7 @@
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

import static org.catrobat.catroid.web.WebconnectionException.ERROR_EMPTY_PROJECT_DATA;
import static org.catrobat.catroid.web.WebConnectionException.ERROR_EMPTY_PROJECT_DATA;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void tearDown() throws Exception {
}

@Test
public void testScratchSearchWithEmptyQueryParam() throws WebconnectionException, InterruptedIOException {
public void testScratchSearchWithEmptyQueryParam() throws WebConnectionException, InterruptedIOException {
ScratchSearchResult searchResult = new ServerCalls(CatrobatWebClient.INSTANCE.getClient()).scratchSearch("", 20, 0);
List<ScratchProgramData> programDataList = searchResult.getProgramDataList();

Expand Down Expand Up @@ -106,7 +106,7 @@ private void checkScratchProgramData(ScratchProgramData programData) {
}

@Test
public void testScratchSearchWithQueryParam() throws WebconnectionException, InterruptedIOException {
public void testScratchSearchWithQueryParam() throws WebConnectionException, InterruptedIOException {
ScratchSearchResult searchResult = new ServerCalls(CatrobatWebClient.INSTANCE.getClient()).scratchSearch("test", 20, 0);
List<ScratchProgramData> programDataList = searchResult.getProgramDataList();

Expand All @@ -123,7 +123,7 @@ public void testScratchSearchWithQueryParam() throws WebconnectionException, Int
}

@Test
public void testScratchSearchMaxNumberOfItemsParam() throws WebconnectionException, InterruptedIOException {
public void testScratchSearchMaxNumberOfItemsParam() throws WebConnectionException, InterruptedIOException {
final int maxNumberOfItems = 10;

ScratchSearchResult searchResult = new ServerCalls(CatrobatWebClient.INSTANCE.getClient()).scratchSearch("test", maxNumberOfItems, 0);
Expand All @@ -143,7 +143,7 @@ public void testScratchSearchMaxNumberOfItemsParam() throws WebconnectionExcepti
}

@Test
public void testScratchSearchPagination() throws WebconnectionException, InterruptedIOException {
public void testScratchSearchPagination() throws WebConnectionException, InterruptedIOException {
for (int pageIndex = 1; pageIndex < 3; pageIndex++) {
ScratchSearchResult searchResult = new ServerCalls(CatrobatWebClient.INSTANCE.getClient()).scratchSearch("test", 20, pageIndex);
List<ScratchProgramData> programDataList = searchResult.getProgramDataList();
Expand All @@ -162,7 +162,7 @@ public void testScratchSearchPagination() throws WebconnectionException, Interru
}

@Test
public void testFetchDefaultScratchPrograms() throws InterruptedIOException, WebconnectionException {
public void testFetchDefaultScratchPrograms() throws InterruptedIOException, WebConnectionException {
ScratchSearchResult searchResult = new ServerCalls(CatrobatWebClient.INSTANCE.getClient()).fetchDefaultScratchPrograms();
List<ScratchProgramData> programDataList = searchResult.getProgramDataList();

Expand All @@ -179,9 +179,8 @@ public void testFetchDefaultScratchPrograms() throws InterruptedIOException, Web

@Test
public void testFetchScratchProgramDetails() throws
WebconnectionException,
WebScratchProgramException,
InterruptedIOException {
WebConnectionException,
WebScratchProgramException {

long expectedProgramID = 10205819;
String expectedProgramTitle = "Dancin' in the Castle";
Expand All @@ -192,7 +191,7 @@ public void testFetchScratchProgramDetails() throws
assertEquals(programData.getId(), expectedProgramID);
assertEquals(programData.getTitle(), expectedProgramTitle);
assertEquals(programData.getOwner(), expectedProgramOwner);
} catch (WebconnectionException e) {
} catch (WebConnectionException e) {
if (e.getStatusCode() != ERROR_EMPTY_PROJECT_DATA) {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -34,7 +34,7 @@
import org.catrobat.catroid.web.CatrobatWebClient;
import org.catrobat.catroid.web.ServerAuthenticator;
import org.catrobat.catroid.web.ServerAuthenticator.TaskListener;
import org.catrobat.catroid.web.WebconnectionException;
import org.catrobat.catroid.web.WebConnectionException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -98,7 +98,7 @@ public void tearDown() throws Exception {

@Test
@Flaky
public void testRegistrationOk() throws WebconnectionException {
public void testRegistrationOk() throws WebConnectionException {
authenticator.performCatrobatRegister(testEmail, "de", "at");
verify(listenerMock, never()).onError(anyInt(), anyString());
verify(listenerMock, atLeastOnce()).onSuccess();
Expand Down Expand Up @@ -188,7 +188,7 @@ public void testCheckTokenWrong() {
boolean tokenOk = new CatrobatServerCalls().checkToken(wrongToken, username, BASE_URL_TEST_HTTPS);

assertFalse(tokenOk);
} catch (WebconnectionException e) {
} catch (WebConnectionException e) {
assertEquals(STATUS_CODE_TOKEN_FAILED, e.getStatusCode());
assertNotNull(e.getMessage());
assertThat(e.getMessage().length(), is(greaterThan(0)));
Expand All @@ -197,7 +197,7 @@ public void testCheckTokenWrong() {

@Test
@Flaky
public void testCheckTokenOk() throws WebconnectionException {
public void testCheckTokenOk() throws WebConnectionException {
authenticator.performCatrobatRegister(testEmail, "de", "at");
verify(listenerMock, never()).onError(anyInt(), anyString());
verify(listenerMock, atLeastOnce()).onSuccess();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -26,7 +26,7 @@
import android.util.Log;

import org.catrobat.catroid.web.CatrobatServerCalls;
import org.catrobat.catroid.web.WebconnectionException;
import org.catrobat.catroid.web.WebConnectionException;

public class CheckEmailAvailableTask extends AsyncTask<String, Void, Boolean> {
private static final String TAG = CheckEmailAvailableTask.class.getSimpleName();
Expand All @@ -52,7 +52,7 @@ protected Boolean doInBackground(String... params) {
try {
emailAvailable = new CatrobatServerCalls().isEMailAvailable(email);
return true;
} catch (WebconnectionException webconnectionException) {
} catch (WebConnectionException webconnectionException) {
Log.e(TAG, Log.getStackTraceString(webconnectionException));
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -30,7 +30,7 @@
import org.catrobat.catroid.R;
import org.catrobat.catroid.utils.Utils;
import org.catrobat.catroid.web.CatrobatServerCalls;
import org.catrobat.catroid.web.WebconnectionException;
import org.catrobat.catroid.web.WebConnectionException;

import androidx.appcompat.app.AlertDialog;

Expand All @@ -44,7 +44,7 @@ public class CheckOAuthTokenTask extends AsyncTask<String, Void, Boolean> {

private Boolean tokenAvailable;

private WebconnectionException exception;
private WebConnectionException exception;

private OnCheckOAuthTokenCompleteListener onCheckOAuthTokenCompleteListener;

Expand Down Expand Up @@ -73,13 +73,13 @@ protected void onPreExecute() {
protected Boolean doInBackground(String... params) {
try {
if (!Utils.isNetworkAvailable(activity)) {
exception = new WebconnectionException(WebconnectionException.ERROR_NETWORK, "Network not available!");
exception = new WebConnectionException(WebConnectionException.ERROR_NETWORK, "Network not available!");
return false;
}

tokenAvailable = new CatrobatServerCalls().checkOAuthToken(id, provider, activity);
return true;
} catch (WebconnectionException webconnectionException) {
} catch (WebConnectionException webconnectionException) {
Log.e(TAG, Log.getStackTraceString(webconnectionException));
exception = webconnectionException;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -27,7 +27,7 @@

import org.catrobat.catroid.common.FlavoredConstants;
import org.catrobat.catroid.web.CatrobatServerCalls;
import org.catrobat.catroid.web.WebconnectionException;
import org.catrobat.catroid.web.WebConnectionException;

public class CheckTokenTask extends AsyncTask<String, Void, Boolean[]> {

Expand All @@ -42,7 +42,7 @@ public CheckTokenTask(TokenCheckListener onCheckTokenCompleteListener) {
protected Boolean[] doInBackground(String... arg0) {
try {
return new Boolean[]{new CatrobatServerCalls().checkToken(arg0[0], arg0[1], FlavoredConstants.BASE_URL_HTTPS), false};
} catch (WebconnectionException e) {
} catch (WebConnectionException e) {
Log.e(TAG, Log.getStackTraceString(e));
return new Boolean[]{false, true};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -26,7 +26,7 @@
import android.util.Log;

import org.catrobat.catroid.web.CatrobatServerCalls;
import org.catrobat.catroid.web.WebconnectionException;
import org.catrobat.catroid.web.WebConnectionException;

public class CheckUserNameAvailableTask extends AsyncTask<Void, Void, Boolean> {
private static final String TAG = CheckUserNameAvailableTask.class.getSimpleName();
Expand All @@ -49,7 +49,7 @@ protected Boolean doInBackground(Void... params) {
try {
userNameAvailable = new CatrobatServerCalls().isUserNameAvailable(username);
return true;
} catch (WebconnectionException webconnectionException) {
} catch (WebConnectionException webconnectionException) {
Log.e(TAG, Log.getStackTraceString(webconnectionException));
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -29,7 +29,7 @@
import org.catrobat.catroid.R;
import org.catrobat.catroid.utils.Utils;
import org.catrobat.catroid.web.CatrobatServerCalls;
import org.catrobat.catroid.web.WebconnectionException;
import org.catrobat.catroid.web.WebConnectionException;

import androidx.appcompat.app.AlertDialog;

Expand All @@ -38,7 +38,7 @@ public class DeleteTestUserTask extends AsyncTask<Void, Void, Boolean> {

private Context context;

private WebconnectionException exception;
private WebConnectionException exception;

private OnDeleteTestUserCompleteListener onDeleteTestUserCompleteListener;

Expand All @@ -54,12 +54,12 @@ public void setOnDeleteTestUserCompleteListener(OnDeleteTestUserCompleteListener
protected Boolean doInBackground(Void... params) {
try {
if (!Utils.isNetworkAvailable(context)) {
exception = new WebconnectionException(WebconnectionException.ERROR_NETWORK, "Network not available!");
exception = new WebConnectionException(WebConnectionException.ERROR_NETWORK, "Network not available!");
return false;
}

return new CatrobatServerCalls().deleteTestUserAccountsOnServer();
} catch (WebconnectionException webconnectionException) {
} catch (WebConnectionException webconnectionException) {
Log.e(TAG, Log.getStackTraceString(webconnectionException));
exception = webconnectionException;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -35,8 +35,8 @@
import org.catrobat.catroid.common.ScratchProgramData;
import org.catrobat.catroid.utils.ToastUtil;
import org.catrobat.catroid.web.ScratchDataFetcher;
import org.catrobat.catroid.web.WebConnectionException;
import org.catrobat.catroid.web.WebScratchProgramException;
import org.catrobat.catroid.web.WebconnectionException;

import java.io.InterruptedIOException;

Expand Down Expand Up @@ -121,7 +121,7 @@ public void run() {
});

return null;
} catch (WebconnectionException e) {
} catch (WebConnectionException e) {
Log.e(TAG, e.getMessage() + "\n" + e.getStackTrace());
delay = minTimeout + (int) (minTimeout * Math.random() * (attempt + 1));
Log.i(TAG, "Retry #" + (attempt + 1) + " to fetch scratch project list scheduled in "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -32,7 +32,7 @@
import org.catrobat.catroid.utils.Utils;
import org.catrobat.catroid.web.CatrobatWebClient;
import org.catrobat.catroid.web.ServerCalls;
import org.catrobat.catroid.web.WebconnectionException;
import org.catrobat.catroid.web.WebConnectionException;

import androidx.appcompat.app.AlertDialog;

Expand All @@ -50,7 +50,7 @@ public class GoogleExchangeCodeTask extends AsyncTask<Void, Void, Boolean> {
private final String idToken;
private String message;
private OnGoogleExchangeCodeCompleteListener onGoogleExchangeCodeCompleteListener;
private WebconnectionException exception;
private WebConnectionException exception;
private boolean tokenExchanged;

public GoogleExchangeCodeTask(Activity activity, String code, String mail, String username, String id, String
Expand Down Expand Up @@ -83,13 +83,13 @@ protected void onPreExecute() {
protected Boolean doInBackground(Void... arg0) {
try {
if (!Utils.isNetworkAvailable(context)) {
exception = new WebconnectionException(WebconnectionException.ERROR_NETWORK, "Network not available!");
exception = new WebConnectionException(WebConnectionException.ERROR_NETWORK, "Network not available!");
return false;
}

tokenExchanged = new ServerCalls(CatrobatWebClient.INSTANCE.getClient()).googleExchangeCode(code, id, username, mail, locale, idToken);
return true;
} catch (WebconnectionException webconnectionException) {
} catch (WebConnectionException webconnectionException) {
Log.e(TAG, Log.getStackTraceString(webconnectionException));
message = webconnectionException.getMessage();
}
Expand Down
Loading