From 4c019aef1571d78f5931b075caf8e9e993434773 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Fri, 26 Mar 2021 11:02:15 -0500 Subject: [PATCH] Migrate PendingAccountsTest to JUnit 5 --- .../tests/storage/PendingAccountsTest.java | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/PendingAccountsTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/PendingAccountsTest.java index 62e6a5a64..c36b9cc3e 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/PendingAccountsTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/PendingAccountsTest.java @@ -5,39 +5,38 @@ package org.whispersystems.textsecuregcm.tests.storage; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + import com.opentable.db.postgres.embedded.LiquibasePreparer; -import com.opentable.db.postgres.junit.EmbeddedPostgresRules; -import com.opentable.db.postgres.junit.PreparedDbRule; +import com.opentable.db.postgres.junit5.EmbeddedPostgresExtension; +import com.opentable.db.postgres.junit5.PreparedDbExtension; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Optional; import org.jdbi.v3.core.Jdbi; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.whispersystems.textsecuregcm.auth.StoredVerificationCode; import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration; import org.whispersystems.textsecuregcm.storage.FaultTolerantDatabase; import org.whispersystems.textsecuregcm.storage.PendingAccounts; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Optional; +class PendingAccountsTest { -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -public class PendingAccountsTest { - - @Rule - public PreparedDbRule db = EmbeddedPostgresRules.preparedDatabase(LiquibasePreparer.forClasspathLocation("accountsdb.xml")); + @RegisterExtension + static PreparedDbExtension db = EmbeddedPostgresExtension.preparedDatabase(LiquibasePreparer.forClasspathLocation("accountsdb.xml")); private PendingAccounts pendingAccounts; - @Before - public void setupAccountsDao() { + @BeforeEach + void setupAccountsDao() { this.pendingAccounts = new PendingAccounts(new FaultTolerantDatabase("pending_accounts-test", Jdbi.create(db.getTestDatabase()), new CircuitBreakerConfiguration())); } @Test - public void testStore() throws SQLException { + void testStore() throws SQLException { pendingAccounts.insert("+14151112222", "1234", 1111, null); PreparedStatement statement = db.getTestDatabase().getConnection().prepareStatement("SELECT * FROM pending_accounts WHERE number = ?"); @@ -57,7 +56,7 @@ public class PendingAccountsTest { } @Test - public void testStoreWithPushChallenge() throws SQLException { + void testStoreWithPushChallenge() throws SQLException { pendingAccounts.insert("+14151112222", null, 1111, "112233"); PreparedStatement statement = db.getTestDatabase().getConnection().prepareStatement("SELECT * FROM pending_accounts WHERE number = ?"); @@ -77,7 +76,7 @@ public class PendingAccountsTest { } @Test - public void testRetrieve() throws Exception { + void testRetrieve() throws Exception { pendingAccounts.insert("+14151112222", "4321", 2222, null); pendingAccounts.insert("+14151113333", "1212", 5555, null); @@ -92,7 +91,7 @@ public class PendingAccountsTest { } @Test - public void testRetrieveWithPushChallenge() throws Exception { + void testRetrieveWithPushChallenge() throws Exception { pendingAccounts.insert("+14151112222", "4321", 2222, "bar"); pendingAccounts.insert("+14151113333", "1212", 5555, "bang"); @@ -108,7 +107,7 @@ public class PendingAccountsTest { } @Test - public void testOverwrite() throws Exception { + void testOverwrite() throws Exception { pendingAccounts.insert("+14151112222", "4321", 2222, null); pendingAccounts.insert("+14151112222", "4444", 3333, null); @@ -120,7 +119,7 @@ public class PendingAccountsTest { } @Test - public void testOverwriteWithPushToken() throws Exception { + void testOverwriteWithPushToken() throws Exception { pendingAccounts.insert("+14151112222", "4321", 2222, "bar"); pendingAccounts.insert("+14151112222", "4444", 3333, "bang"); @@ -134,7 +133,7 @@ public class PendingAccountsTest { @Test - public void testVacuum() { + void testVacuum() { pendingAccounts.insert("+14151112222", "4321", 2222, null); pendingAccounts.insert("+14151112222", "4444", 3333, null); pendingAccounts.vacuum(); @@ -147,7 +146,7 @@ public class PendingAccountsTest { } @Test - public void testRemove() { + void testRemove() { pendingAccounts.insert("+14151112222", "4321", 2222, "bar"); pendingAccounts.insert("+14151113333", "1212", 5555, null);