Skip to content

Commit

Permalink
Remove redundant lazy loading in AuthAccountTest
Browse files Browse the repository at this point in the history
  • Loading branch information
bivashy committed Sep 25, 2023
1 parent fdf120a commit c41c4db
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions core/src/test/java/com/bivashy/auth/account/AuthAccountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.bivashy.auth.api.bucket.CryptoProviderBucket;
import com.bivashy.auth.api.crypto.CryptoProvider;
import com.bivashy.auth.api.crypto.HashedPassword;
import com.bivashy.auth.api.database.AccountDatabase;
import com.bivashy.auth.api.link.LinkType;
import com.bivashy.auth.api.link.user.LinkUser;
import com.bivashy.auth.api.link.user.info.LinkUserIdentificator;
Expand All @@ -31,6 +30,7 @@

@ExtendWith(MockitoExtension.class)
public class AuthAccountTest {

private static final String ACCOUNT_ID = "player";
private static final IdentifierType ACCOUNT_ID_TYPE = IdentifierType.NAME;
private static final String ACCOUNT_NAME = "Player";
Expand All @@ -54,8 +54,8 @@ public void setup() {
account = factory.createAccount(ACCOUNT_ID, ACCOUNT_ID_TYPE, ACCOUNT_UUID, ACCOUNT_NAME, cryptoProvider, null, null);

CryptoProviderBucket cryptoProviderBucket = AuthPlugin.instance().getCryptoProviderBucket();
if (!cryptoProviderBucket.findCryptoProvider(cryptoProvider.getIdentifier()).isPresent())
cryptoProviderBucket.addCryptoProvider(cryptoProvider);
if (!cryptoProviderBucket.modifiable().hasByValue(CryptoProvider::getIdentifier, cryptoProvider.getIdentifier()))
cryptoProviderBucket.modifiable().remove(cryptoProvider);
}

@Test
Expand Down Expand Up @@ -201,7 +201,7 @@ public void shouldPassRegisterAuthenticationStep() {
assertTrue(currentAuthenticationStep.shouldSkip());

plugin.getAuthenticatingAccountBucket().removeAuthenticatingAccount(account);
deleteAccountFromDatabase(account).join();
deleteAccountFromDatabase(account);
}

@Test
Expand Down Expand Up @@ -230,18 +230,11 @@ public void shouldPassLoginAuthenticationStep() {
assertTrue(currentAuthenticationStep.shouldSkip());

plugin.getAuthenticatingAccountBucket().removeAuthenticatingAccount(account);
deleteAccountFromDatabase(account).join();
deleteAccountFromDatabase(account);
}

private CompletableFuture<Void> deleteAccountFromDatabase(Account account) {
return accountDatabase().thenCompose(database -> database.deleteAccount(account.getPlayerId()));
return AuthPlugin.instance().getAccountDatabase().deleteAccount(account.getPlayerId());
}

private CompletableFuture<AccountDatabase> accountDatabase() {
return CompletableFuture.supplyAsync(() -> {
AuthPlugin plugin = AuthPlugin.instance();
while (!plugin.getAccountDatabase().isEnabled()) {}
return plugin.getAccountDatabase();
});
}
}

0 comments on commit c41c4db

Please sign in to comment.