Skip to content

Commit 60af971

Browse files
committed
Fixed some static warnings in AbstractIT and AbstractOnServerIT
- UserAccountManagerImpl#getAccountByName() is never null because since #13074 it rather returns an anonymous account. To detect an account lookup failure, the type needs to be compared - The getMaterialSchemesProvider() object returned null for most functions, even though they were annotated with @nonnull. Extracted the only actually used function getMaterialSchemesForCurrentUser() Signed-off-by: Philipp Hasper <[email protected]>
1 parent 774d8c5 commit 60af971

File tree

3 files changed

+14
-47
lines changed

3 files changed

+14
-47
lines changed

app/src/androidTest/java/com/owncloud/android/AbstractIT.java

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import android.accounts.AuthenticatorException;
1313
import android.accounts.OperationCanceledException;
1414
import android.app.Activity;
15-
import android.content.ActivityNotFoundException;
1615
import android.content.Context;
1716
import android.content.res.Configuration;
1817
import android.content.res.Resources;
@@ -56,7 +55,6 @@
5655
import com.owncloud.android.operations.CreateFolderOperation;
5756
import com.owncloud.android.operations.UploadFileOperation;
5857
import com.owncloud.android.utils.FileStorageUtils;
59-
import com.owncloud.android.utils.theme.MaterialSchemesProvider;
6058

6159
import org.apache.commons.io.FileUtils;
6260
import org.junit.After;
@@ -431,7 +429,7 @@ public boolean isPowerSavingEnabled() {
431429

432430
newUpload.setRemoteFolderToBeCreated();
433431

434-
RemoteOperationResult result = newUpload.execute(client);
432+
var result = newUpload.execute(client);
435433
assertTrue(result.getLogMessage(), result.isSuccess());
436434
}
437435

@@ -536,8 +534,8 @@ protected static Account createAccount(String name) {
536534
platformAccountManager.setUserData(temp, KEY_USER_ID, name.substring(0, atPos));
537535

538536
Account account = UserAccountManagerImpl.fromContext(targetContext).getAccountByName(name);
539-
if (account == null) {
540-
throw new ActivityNotFoundException();
537+
if (Objects.equals(account.type, targetContext.getString(R.string.anonymous_account_type))) {
538+
throw new RuntimeException("Could not get account with name " + name);
541539
}
542540
return account;
543541
}
@@ -546,37 +544,7 @@ protected static boolean removeAccount(Account account) {
546544
return AccountManager.get(targetContext).removeAccountExplicitly(account);
547545
}
548546

549-
protected MaterialSchemesProvider getMaterialSchemesProvider() {
550-
return new MaterialSchemesProvider() {
551-
@NonNull
552-
@Override
553-
public MaterialSchemes getMaterialSchemesForUser(@NonNull User user) {
554-
return null;
555-
}
556-
557-
@NonNull
558-
@Override
559-
public MaterialSchemes getMaterialSchemesForCapability(@NonNull OCCapability capability) {
560-
return null;
561-
}
562-
563-
@NonNull
564-
@Override
565-
public MaterialSchemes getMaterialSchemesForCurrentUser() {
566-
return new MaterialSchemesImpl(R.color.primary, false);
567-
}
568-
569-
@NonNull
570-
@Override
571-
public MaterialSchemes getDefaultMaterialSchemes() {
572-
return null;
573-
}
574-
575-
@NonNull
576-
@Override
577-
public MaterialSchemes getMaterialSchemesForPrimaryBackground() {
578-
return null;
579-
}
580-
};
547+
protected MaterialSchemes getMaterialSchemesForCurrentUser() {
548+
return new MaterialSchemesImpl(R.color.primary, false);
581549
}
582550
}

app/src/androidTest/java/com/owncloud/android/AbstractOnServerIT.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.accounts.AccountManager;
1111
import android.accounts.AuthenticatorException;
1212
import android.accounts.OperationCanceledException;
13-
import android.content.ActivityNotFoundException;
1413
import android.net.Uri;
1514
import android.os.Bundle;
1615

@@ -29,7 +28,6 @@
2928
import com.owncloud.android.lib.common.OwnCloudClient;
3029
import com.owncloud.android.lib.common.OwnCloudClientFactory;
3130
import com.owncloud.android.lib.common.accounts.AccountUtils;
32-
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
3331
import com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation;
3432
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
3533
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
@@ -46,6 +44,7 @@
4644

4745
import java.io.File;
4846
import java.io.IOException;
47+
import java.util.Objects;
4948
import java.util.Optional;
5049

5150
import androidx.annotation.NonNull;
@@ -97,8 +96,8 @@ public static void beforeAll() {
9796
final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
9897
account = userAccountManager.getAccountByName(loginName + "@" + baseUrl);
9998

100-
if (account == null) {
101-
throw new ActivityNotFoundException();
99+
if (Objects.equals(account.type, targetContext.getString(R.string.anonymous_account_type))) {
100+
throw new RuntimeException("Could not get account with name " + loginName + "@" + baseUrl);
102101
}
103102

104103
Optional<User> optionalUser = userAccountManager.getUser(account.name);
@@ -134,13 +133,13 @@ private static boolean isFolder(RemoteFile file) {
134133
}
135134

136135
public static void deleteAllFilesOnServer() {
137-
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
138-
assertTrue(result.getLogMessage(), result.isSuccess());
136+
var result = new ReadFolderRemoteOperation("/").execute(client);
137+
assertTrue(result.getLogMessage(targetContext), result.isSuccess());
139138

140139
for (Object object : result.getData()) {
141140
RemoteFile remoteFile = (RemoteFile) object;
142141

143-
if (!remoteFile.getRemotePath().equals("/")) {
142+
if (!Objects.equals(remoteFile.getRemotePath(), "/")) {
144143
if (remoteFile.isEncrypted()) {
145144
ToggleEncryptionRemoteOperation operation = new ToggleEncryptionRemoteOperation(remoteFile.getLocalId(),
146145
remoteFile.getRemotePath(),
@@ -262,7 +261,7 @@ public boolean isPowerSavingEnabled() {
262261

263262
newUpload.setRemoteFolderToBeCreated();
264263

265-
RemoteOperationResult result = newUpload.execute(client);
264+
var result = newUpload.execute(client);
266265
assertTrue(result.getLogMessage(), result.isSuccess());
267266

268267
OCFile parentFolder = getStorageManager()
@@ -271,6 +270,7 @@ public boolean isPowerSavingEnabled() {
271270
OCFile uploadedFile = getStorageManager().
272271
getFileByDecryptedRemotePath(parentFolder.getDecryptedRemotePath() + uploadedFileName);
273272

273+
assertNotNull(uploadedFile);
274274
assertNotNull(uploadedFile.getRemoteId());
275275
assertNotNull(uploadedFile.getPermissions());
276276

app/src/androidTest/java/com/owncloud/android/ui/dialog/DialogFragmentIT.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,8 @@ class DialogFragmentIT : AbstractIT() {
504504
throw UnsupportedOperationException("Document scan is not available")
505505
}
506506

507-
val materialSchemesProvider = getMaterialSchemesProvider()
508507
val viewThemeUtils = ViewThemeUtils(
509-
materialSchemesProvider.getMaterialSchemesForCurrentUser(),
508+
materialSchemesForCurrentUser,
510509
ColorUtil(targetContext)
511510
)
512511

0 commit comments

Comments
 (0)