diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/IntegrationTestHelper.java b/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/IntegrationTestHelper.java index ce3926a2550c2c574c1681e45334879f8893a563..4121b582dce4d9bb00c3650d31b0d0979ac4552f 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/IntegrationTestHelper.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/helpers/IntegrationTestHelper.java @@ -18,7 +18,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class IntegrationTestHelper { @@ -140,7 +140,8 @@ public class IntegrationTestHelper // close result page driver.findElement(By.id("button-finish-import")).click(); - assertEquals(Localization.getString("menu.settings"), IntegrationTestHelper.getTextNode(driver.findElement(By.className("headline")))); + assertThat(IntegrationTestHelper.getTextNode(driver.findElement(By.className("headline")))) + .isEqualTo(Localization.getString("menu.settings")); start(); } @@ -172,10 +173,11 @@ public class IntegrationTestHelper private void matchAccounts(List<String> sourceAccounts, List<Account> destinationAccounts) { WebElement headlineImport = driver.findElement(By.className("headline")); - assertEquals(Localization.getString("info.title.database.import.dialog"), IntegrationTestHelper.getTextNode(headlineImport)); + assertThat(IntegrationTestHelper.getTextNode(headlineImport)) + .isEqualTo(Localization.getString("info.title.database.import.dialog")); List<WebElement> tableRows = driver.findElements(By.cssSelector(".container form table tr")); - assertEquals(destinationAccounts.size(), tableRows.size()); + assertThat(tableRows.size()).isEqualTo(destinationAccounts.size()); for(int i = 0; i < destinationAccounts.size(); i++) { @@ -183,7 +185,7 @@ public class IntegrationTestHelper WebElement row = tableRows.get(i); WebElement sourceAccount = row.findElement(By.className("account-source")); - assertEquals(sourceAccounts.get(i), IntegrationTestHelper.getTextNode(sourceAccount)); + assertThat(IntegrationTestHelper.getTextNode(sourceAccount)).isEqualTo(sourceAccounts.get(i)); WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("select-dropdown"))); diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/LoginControllerTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/LoginControllerTest.java index e1ead30f7e0f7d9ac5bc121279749a90c27b8645..463b4c075f53976e5bd0b5ca16036a4a912677dc 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/LoginControllerTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/LoginControllerTest.java @@ -23,8 +23,8 @@ import org.springframework.boot.web.server.LocalServerPort; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; + @RunWith(SpringRunner.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -72,13 +72,13 @@ public class LoginControllerTest helper.start(); WebElement input = driver.findElement(By.id("login-password")); - assertNotNull(input); + assertThat(input).isNotNull(); WebElement label = driver.findElement(By.cssSelector(".input-field label")); - assertEquals(Localization.getString("login.password"), label.getText()); + assertThat(label.getText()).isEqualTo(Localization.getString("login.password")); WebElement button = driver.findElement(By.tagName("button")); - assertEquals(Localization.getString("login.button"), IntegrationTestHelper.getTextNode(button)); + assertThat(IntegrationTestHelper.getTextNode(button)).isEqualTo(Localization.getString("login.button")); } @Test @@ -89,7 +89,7 @@ public class LoginControllerTest helper.login("akhjfvbvahsdsa"); WebElement label = driver.findElement(By.id("loginMessage")); - assertEquals(Localization.getString("warning.wrong.password"), label.getText()); + assertThat(label.getText()).isEqualTo(Localization.getString("warning.wrong.password")); } @Test @@ -103,7 +103,7 @@ public class LoginControllerTest WebElement label = driver.findElement(By.id("logo-home")); String expected = helper.getUrl() + "/images/Logo_with_text_medium_res.png"; - assertEquals(expected, label.getAttribute("src")); + assertThat(label.getAttribute("src")).isEqualTo(expected); } @Test @@ -121,6 +121,6 @@ public class LoginControllerTest buttonLogout.click(); WebElement label = driver.findElement(By.id("loginMessage")); - assertEquals(Localization.getString("logout.success"), label.getText()); + assertThat(label.getText()).isEqualTo(Localization.getString("logout.success")); } } \ No newline at end of file diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/SearchTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/SearchTest.java index 56ebbc3420cb75251281a368d0a3116f46d7db54..20ab063d90686442717d09e19decac96c99fd2e5 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/SearchTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/SearchTest.java @@ -29,9 +29,8 @@ import java.io.File; import java.util.Arrays; import java.util.List; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; + @RunWith(SpringRunner.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -96,17 +95,17 @@ public class SearchTest // headline WebElement headline = driver.findElement(By.className("headline")); String expected = Localization.getString("menu.search.results", 24); - assertEquals(expected, headline.getText()); + assertThat(headline.getText()).isEqualTo(expected); // checkboxes - assertTrue(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchName\"]")).isSelected()); - assertTrue(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchDescription\"]")).isSelected()); - assertTrue(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchCategory\"]")).isSelected()); - assertTrue(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchTags\"]")).isSelected()); + assertThat(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchName\"]")).isSelected()).isTrue(); + assertThat(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchDescription\"]")).isSelected()).isTrue(); + assertThat(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchCategory\"]")).isSelected()).isTrue(); + assertThat(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchTags\"]")).isSelected()).isTrue(); // results List<WebElement> results = driver.findElements(By.cssSelector(".search-container .card-panel")); - assertEquals(10, results.size()); + assertThat(results.size()).isEqualTo(10); } @Test @@ -114,39 +113,39 @@ public class SearchTest { // === PAGE 1 === List<WebElement> pages = driver.findElements(By.cssSelector(".pagination li")); - assertEquals(5, pages.size()); + assertThat(pages.size()).isEqualTo(5); - assertTrue(pages.get(0).getAttribute("class").contains("disabled")); - assertEquals("1", pages.get(1).findElement(By.className("page-link")).getText()); - assertTrue(pages.get(1).getAttribute("class").contains("active")); - assertEquals("2", pages.get(2).findElement(By.className("page-link")).getText()); - assertEquals("3", pages.get(3).findElement(By.className("page-link")).getText()); - assertFalse(pages.get(4).getAttribute("class").contains("disabled")); + assertThat(pages.get(0).getAttribute("class")).contains("disabled"); + assertThat(pages.get(1).findElement(By.className("page-link")).getText()).isEqualTo("1"); + assertThat(pages.get(1).getAttribute("class")).contains("active"); + assertThat(pages.get(2).findElement(By.className("page-link")).getText()).isEqualTo("2"); + assertThat(pages.get(3).findElement(By.className("page-link")).getText()).isEqualTo("3"); + assertThat(pages.get(4).getAttribute("class")).doesNotContain("disabled"); // validate results List<WebElement> results = driver.findElements(By.cssSelector(".search-container .card-panel")); - assertEquals(10, results.size()); + assertThat(results.size()).isEqualTo(10); // === PAGE 1 === pages.get(3).click(); pages = driver.findElements(By.cssSelector(".pagination li")); - assertEquals(5, pages.size()); + assertThat(pages.size()).isEqualTo(5); // previous button should be enabled - assertFalse(pages.get(0).getAttribute("class").contains("disabled")); + assertThat(pages.get(0).getAttribute("class")).doesNotContain("disabled"); - assertEquals("1", pages.get(1).findElement(By.className("page-link")).getText()); - assertEquals("2", pages.get(2).findElement(By.className("page-link")).getText()); - assertEquals("3", pages.get(3).findElement(By.className("page-link")).getText()); - assertTrue(pages.get(3).getAttribute("class").contains("active")); + assertThat(pages.get(1).findElement(By.className("page-link")).getText()).isEqualTo("1"); + assertThat(pages.get(2).findElement(By.className("page-link")).getText()).isEqualTo("2"); + assertThat(pages.get(3).findElement(By.className("page-link")).getText()).isEqualTo("3"); + assertThat(pages.get(3).getAttribute("class")).contains("active"); // next button should be disabled - assertTrue(pages.get(4).getAttribute("class").contains("disabled")); + assertThat(pages.get(4).getAttribute("class")).contains("disabled"); // validate results = driver.findElements(By.cssSelector(".search-container .card-panel")); - assertEquals(4, results.size()); + assertThat(results.size()).isEqualTo(4); } @Test @@ -161,14 +160,14 @@ public class SearchTest driver.findElement(By.cssSelector(".main-card #searchForm button[type=\"submit\"]")).click(); // validate - assertFalse(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchName\"]")).isSelected()); - assertFalse(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchDescription\"]")).isSelected()); - assertTrue(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchCategory\"]")).isSelected()); - assertTrue(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchTags\"]")).isSelected()); + assertThat(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchName\"]")).isSelected()).isFalse(); + assertThat(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchDescription\"]")).isSelected()).isFalse(); + assertThat(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchCategory\"]")).isSelected()).isTrue(); + assertThat(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchTags\"]")).isSelected()).isTrue(); // results List<WebElement> results = driver.findElements(By.cssSelector(".search-container .card-panel")); - assertEquals(2, results.size()); + assertThat(results.size()).isEqualTo(2); } @Test @@ -176,14 +175,14 @@ public class SearchTest { driver.findElement(By.cssSelector(".main-card .search-result .hide-on-med-and-down .buttonHighlight")).click(); - assertEquals("May 2019", driver.findElement(By.cssSelector(".headline-date")).getText()); + assertThat(driver.findElement(By.cssSelector(".headline-date")).getText()).isEqualTo("May 2019"); List<WebElement> transactionsRows = driver.findElements(By.cssSelector(".transaction-container .hide-on-med-and-down.transaction-row-top")); - assertEquals(25, transactionsRows.size()); - assertTrue(transactionsRows.get(0).getAttribute("class").contains("background-blue-light")); + assertThat(transactionsRows.size()).isEqualTo(25); + assertThat(transactionsRows.get(0).getAttribute("class")).contains("background-blue-light"); for(int i = 1; i < transactionsRows.size(); i++) { - assertFalse(transactionsRows.get(i).getAttribute("class").contains("background-blue-light")); + assertThat(transactionsRows.get(i).getAttribute("class")).doesNotContain("background-blue-light"); } } } \ No newline at end of file diff --git a/src/test/java/de/deadlocker8/budgetmaster/unit/backup/RemoteGitBackupTaskTest.java b/src/test/java/de/deadlocker8/budgetmaster/unit/backup/RemoteGitBackupTaskTest.java index d9918ef07b46519c9eae8c9ed349eb18a709bbc3..3f495e2e8c8f3ce07078fe9466e558446508de98 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/unit/backup/RemoteGitBackupTaskTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/unit/backup/RemoteGitBackupTaskTest.java @@ -28,8 +28,6 @@ import java.nio.file.Path; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; @RunWith(SpringJUnit4ClassRunner.class) public class RemoteGitBackupTaskTest @@ -79,7 +77,8 @@ public class RemoteGitBackupTaskTest final RemoteGitBackupTask remoteGitBackupTask = new RemoteGitBackupTask(databaseService, settingsService); - assertFalse(remoteGitBackupTask.needsCleanup(previousSettings, previousSettings)); + assertThat(remoteGitBackupTask.needsCleanup(previousSettings, previousSettings)) + .isFalse(); } @Test @@ -101,7 +100,7 @@ public class RemoteGitBackupTaskTest final RemoteGitBackupTask remoteGitBackupTask = new RemoteGitBackupTask(databaseService, settingsService); - assertFalse(remoteGitBackupTask.needsCleanup(previousSettings, newSettings)); + assertThat(remoteGitBackupTask.needsCleanup(previousSettings, newSettings)).isFalse(); } @Test @@ -123,7 +122,8 @@ public class RemoteGitBackupTaskTest final RemoteGitBackupTask remoteGitBackupTask = new RemoteGitBackupTask(databaseService, settingsService); - assertTrue(remoteGitBackupTask.needsCleanup(previousSettings, newSettings)); + assertThat(remoteGitBackupTask.needsCleanup(previousSettings, newSettings)) + .isTrue(); } @Test @@ -145,7 +145,8 @@ public class RemoteGitBackupTaskTest final RemoteGitBackupTask remoteGitBackupTask = new RemoteGitBackupTask(databaseService, settingsService); - assertTrue(remoteGitBackupTask.needsCleanup(previousSettings, newSettings)); + assertThat(remoteGitBackupTask.needsCleanup(previousSettings, newSettings)) + .isTrue(); } @Test diff --git a/src/test/java/de/deadlocker8/budgetmaster/unit/repeating/RepeatingOptionTest.java b/src/test/java/de/deadlocker8/budgetmaster/unit/repeating/RepeatingOptionTest.java index 5513c067b71363c6449977956d7e8e52a31cf95f..12a64880ba26ad10987f6b76f0df8df3b66eda9f 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/unit/repeating/RepeatingOptionTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/unit/repeating/RepeatingOptionTest.java @@ -13,7 +13,8 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; + public class RepeatingOptionTest { @@ -35,7 +36,8 @@ public class RepeatingOptionTest expected.add(new DateTime(2018, 4, 28, 12, 0)); expected.add(new DateTime(2018, 5, 1, 12, 0)); - assertEquals(expected, repeatingOption.getRepeatingDates(dateFetchLimit)); + assertThat(repeatingOption.getRepeatingDates(dateFetchLimit)) + .isEqualTo(expected); } @Test @@ -54,7 +56,8 @@ public class RepeatingOptionTest expected.add(new DateTime(2018, 4, 25, 12, 0)); expected.add(new DateTime(2018, 4, 28, 12, 0)); - assertEquals(expected, repeatingOption.getRepeatingDates(dateFetchLimit)); + assertThat(repeatingOption.getRepeatingDates(dateFetchLimit)) + .isEqualTo(expected); } @Test @@ -73,7 +76,8 @@ public class RepeatingOptionTest expected.add(new DateTime(2018, 4, 28, 12, 0)); expected.add(new DateTime(2018, 5, 1, 12, 0)); - assertEquals(expected, repeatingOption.getRepeatingDates(dateFetchLimit)); + assertThat(repeatingOption.getRepeatingDates(dateFetchLimit)) + .isEqualTo(expected); } // test repeating every X months @@ -96,7 +100,8 @@ public class RepeatingOptionTest expected.add(new DateTime(2018, 12, 30, 12, 0)); expected.add(new DateTime(2019, 2, 28, 12, 0)); - assertEquals(expected, repeatingOption.getRepeatingDates(dateFetchLimit)); + assertThat(repeatingOption.getRepeatingDates(dateFetchLimit)) + .isEqualTo(expected); } @Test @@ -115,7 +120,8 @@ public class RepeatingOptionTest expected.add(new DateTime(2018, 6, 30, 12, 0)); expected.add(new DateTime(2018, 8, 30, 12, 0)); - assertEquals(expected, repeatingOption.getRepeatingDates(dateFetchLimit)); + assertThat(repeatingOption.getRepeatingDates(dateFetchLimit)) + .isEqualTo(expected); } @Test @@ -133,7 +139,8 @@ public class RepeatingOptionTest expected.add(new DateTime(2018, 6, 30, 12, 0)); expected.add(new DateTime(2018, 8, 30, 12, 0)); - assertEquals(expected, repeatingOption.getRepeatingDates(dateFetchLimit)); + assertThat(repeatingOption.getRepeatingDates(dateFetchLimit)) + .isEqualTo(expected); } // test repeating every X years @@ -153,7 +160,8 @@ public class RepeatingOptionTest expected.add(new DateTime(2019, 4, 30, 12, 0)); expected.add(new DateTime(2020, 4, 30, 12, 0)); - assertEquals(expected, repeatingOption.getRepeatingDates(dateFetchLimit)); + assertThat(repeatingOption.getRepeatingDates(dateFetchLimit)) + .isEqualTo(expected); } @Test @@ -171,7 +179,8 @@ public class RepeatingOptionTest expected.add(startDate); expected.add(new DateTime(2019, 4, 30, 12, 0)); - assertEquals(expected, repeatingOption.getRepeatingDates(dateFetchLimit)); + assertThat(repeatingOption.getRepeatingDates(dateFetchLimit)) + .isEqualTo(expected); } @Test @@ -188,6 +197,7 @@ public class RepeatingOptionTest expected.add(startDate); expected.add(new DateTime(2019, 4, 30, 12, 0)); - assertEquals(expected, repeatingOption.getRepeatingDates(dateFetchLimit)); + assertThat(repeatingOption.getRepeatingDates(dateFetchLimit)) + .isEqualTo(expected); } } \ No newline at end of file