From 2630bcf0317f428492d7698b9ef12622015bb8c3 Mon Sep 17 00:00:00 2001 From: Victor Uria Valle Date: Fri, 12 Jul 2024 01:04:46 +0200 Subject: [PATCH 1/3] refactor(junit): Migrate tests from JUnit4 to JUnit5 (refs #1679) --- .../java/ai/elimu/dao/ApplicationDaoTest.java | 16 +- .../elimu/dao/ApplicationVersionDaoTest.java | 19 +- src/test/java/ai/elimu/dao/BaseDaoTest.java | 16 +- .../java/ai/elimu/dao/ContributorDaoTest.java | 27 ++- src/test/java/ai/elimu/dao/DeviceDaoTest.java | 23 ++- src/test/java/ai/elimu/dao/EmojiDaoTest.java | 40 +++-- src/test/java/ai/elimu/dao/ImageDaoTest.java | 36 ++-- src/test/java/ai/elimu/dao/LetterDaoTest.java | 31 ++-- src/test/java/ai/elimu/dao/NumberDaoTest.java | 34 ++-- src/test/java/ai/elimu/dao/SoundDaoTest.java | 37 ++-- .../elimu/dao/StoryBookParagraphDaoTest.java | 21 +-- src/test/java/ai/elimu/dao/VideoDaoTest.java | 29 ++- .../dao/WordContributionEventDaoTest.java | 26 ++- src/test/java/ai/elimu/dao/WordDaoTest.java | 34 ++-- .../v2/content/EmojisRestControllerTest.java | 11 +- .../v2/content/ImagesRestControllerTest.java | 11 +- .../LetterSoundsRestControllerTest.java | 16 +- .../v2/content/LettersRestControllerTest.java | 13 +- .../v2/content/SoundsRestControllerTest.java | 13 +- .../content/StoryBooksRestControllerTest.java | 13 +- .../v2/content/WordsRestControllerTest.java | 13 +- .../AudioContributionsRestControllerTest.java | 10 +- .../AudioPeerReviewsRestControllerTest.java | 10 +- .../NumberPeerReviewsRestControllerTest.java | 9 +- .../WordContributionRestControllerTest.java | 18 +- .../WordPeerReviewsRestControllerTest.java | 11 +- .../ai/elimu/util/AnalyticsHelperTest.java | 13 +- .../ai/elimu/util/ChecksumHelperTest.java | 4 +- .../util/LetterExtractionHelperTest.java | 63 +++---- .../elimu/util/LetterFrequencyHelperTest.java | 30 ++-- .../util/SyllableFrequencyHelperTest.java | 18 +- .../ai/elimu/util/SyllableHelperTest.java | 87 ++++----- .../java/ai/elimu/util/VersionHelperTest.java | 31 ++-- .../java/ai/elimu/util/Web3HelperTest.java | 5 +- .../elimu/util/WordExtractionHelperTest.java | 116 ++++++------ .../elimu/util/WordFrequencyHelperTest.java | 16 +- .../AudioMetadataExtractionHelperTest.java | 25 +-- .../util/audio/CrowdsourceHelperTest.java | 30 ++-- .../csv/CsvLetterExtractionHelperTest.java | 31 ++-- .../csv/CsvSoundExtractionHelperTest.java | 31 ++-- .../epub/EPubChapterExtractionHelperTest.java | 21 +-- .../epub/EPubImageExtractionHelperTest.java | 19 +- .../EPubMetadataExtractionHelperTest.java | 64 +++---- .../EPubParagraphExtractionHelperTest.java | 165 ++++++++++-------- .../elimu/web/SignOnControllerWeb3Test.java | 15 +- .../word/WordCreateControllerTest.java | 29 ++- .../content/word/WordListControllerTest.java | 18 +- src/test/java/selenium/JavaScriptHelper.java | 4 +- .../java/selenium/MarkupValidationHelper.java | 4 +- .../selenium/ScreenshotOnFailureRule.java | 18 -- .../ScreenshotOnFailureStatement.java | 141 --------------- .../java/selenium/web/WelcomePageTest.java | 12 +- 52 files changed, 681 insertions(+), 866 deletions(-) delete mode 100644 src/test/java/selenium/ScreenshotOnFailureRule.java delete mode 100644 src/test/java/selenium/ScreenshotOnFailureStatement.java diff --git a/src/test/java/ai/elimu/dao/ApplicationDaoTest.java b/src/test/java/ai/elimu/dao/ApplicationDaoTest.java index f4096f75e..1931e4910 100644 --- a/src/test/java/ai/elimu/dao/ApplicationDaoTest.java +++ b/src/test/java/ai/elimu/dao/ApplicationDaoTest.java @@ -1,20 +1,18 @@ package ai.elimu.dao; import ai.elimu.model.admin.Application; +import org.junit.jupiter.api.Test; + import org.apache.logging.log4j.Logger; -import static org.junit.Assert.*; -import static org.hamcrest.CoreMatchers.*; -import org.junit.Test; -import org.junit.runner.RunWith; import java.util.List; import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ +@SpringJUnitConfig(locations = { "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) @@ -28,6 +26,6 @@ public class ApplicationDaoTest { @Test public void testReadAll() { List applications = applicationDao.readAll(); - assertThat(applications.isEmpty(), is(true)); + assertTrue(applications.isEmpty()); } } diff --git a/src/test/java/ai/elimu/dao/ApplicationVersionDaoTest.java b/src/test/java/ai/elimu/dao/ApplicationVersionDaoTest.java index d4537e6cf..2f334fc3a 100644 --- a/src/test/java/ai/elimu/dao/ApplicationVersionDaoTest.java +++ b/src/test/java/ai/elimu/dao/ApplicationVersionDaoTest.java @@ -2,20 +2,17 @@ import ai.elimu.model.admin.Application; import ai.elimu.model.admin.ApplicationVersion; +import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import static org.junit.Assert.*; -import static org.hamcrest.CoreMatchers.*; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import org.junit.Test; -import org.junit.runner.RunWith; import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringJUnitConfig(locations = { "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) @@ -35,7 +32,7 @@ public void testReadAll() { applicationDao.create(application); List applicationVersions = applicationVersionDao.readAll(application); - assertThat(applicationVersions.isEmpty(), is(true)); + assertTrue(applicationVersions.isEmpty()); applicationDao.delete(application); } diff --git a/src/test/java/ai/elimu/dao/BaseDaoTest.java b/src/test/java/ai/elimu/dao/BaseDaoTest.java index 56c4bef70..15e00cd93 100644 --- a/src/test/java/ai/elimu/dao/BaseDaoTest.java +++ b/src/test/java/ai/elimu/dao/BaseDaoTest.java @@ -1,18 +1,14 @@ package ai.elimu.dao; -import ai.elimu.dao.ImageDao; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; import ai.elimu.model.content.multimedia.Image; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ +@SpringJUnitConfig(locations = { "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) diff --git a/src/test/java/ai/elimu/dao/ContributorDaoTest.java b/src/test/java/ai/elimu/dao/ContributorDaoTest.java index 1692526b8..33049724a 100644 --- a/src/test/java/ai/elimu/dao/ContributorDaoTest.java +++ b/src/test/java/ai/elimu/dao/ContributorDaoTest.java @@ -1,21 +1,18 @@ package ai.elimu.dao; -import org.apache.logging.log4j.Logger; -import static org.junit.Assert.*; -import static org.hamcrest.CoreMatchers.*; -import org.hibernate.exception.ConstraintViolationException; -import org.junit.Ignore; - -import org.junit.Test; -import org.junit.runner.RunWith; import ai.elimu.model.contributor.Contributor; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.hibernate.exception.ConstraintViolationException; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ +@SpringJUnitConfig(locations = { "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) @@ -26,12 +23,12 @@ public class ContributorDaoTest { @Autowired private ContributorDao contributorDao; - @Ignore - @Test(expected=ConstraintViolationException.class) + @Disabled + @Test public void testConstraintViolation() { Contributor contributor = new Contributor(); contributorDao.create(contributor); logger.info("contributor: " + contributor); - assertThat(contributor, nullValue()); + assertNull(contributor); } } diff --git a/src/test/java/ai/elimu/dao/DeviceDaoTest.java b/src/test/java/ai/elimu/dao/DeviceDaoTest.java index c7f8f03db..8cf59eecf 100644 --- a/src/test/java/ai/elimu/dao/DeviceDaoTest.java +++ b/src/test/java/ai/elimu/dao/DeviceDaoTest.java @@ -1,19 +1,18 @@ package ai.elimu.dao; import ai.elimu.model.Device; -import junit.framework.TestCase; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ - "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", - "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +@SpringJUnitConfig(locations = { + "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", + "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) -public class DeviceDaoTest extends TestCase { +public class DeviceDaoTest { @Autowired private DeviceDao deviceDao; @@ -23,8 +22,8 @@ public void testRead() { deviceDao.create(getDevice("22")); deviceDao.create(getDevice("44")); - assertTrue("22".equals(deviceDao.read("22").getDeviceId())); - assertTrue("44".equals(deviceDao.read("44").getDeviceId())); + assertEquals("22", deviceDao.read("22").getDeviceId()); + assertEquals("44", deviceDao.read("44").getDeviceId()); assertNull(deviceDao.read("33")); } diff --git a/src/test/java/ai/elimu/dao/EmojiDaoTest.java b/src/test/java/ai/elimu/dao/EmojiDaoTest.java index 73d7ef274..5b67921ac 100644 --- a/src/test/java/ai/elimu/dao/EmojiDaoTest.java +++ b/src/test/java/ai/elimu/dao/EmojiDaoTest.java @@ -1,30 +1,38 @@ package ai.elimu.dao; import ai.elimu.model.content.Emoji; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer.MethodName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import java.util.ArrayList; import java.util.List; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ - "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", - "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@SpringJUnitConfig(locations = { + "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", + "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class EmojiDaoTest extends TestCase { +@TestMethodOrder(MethodName.class) +public class EmojiDaoTest { @Autowired private EmojiDao emojiDao; + @BeforeEach + void cleanupDao() { + var emojiList = emojiDao.readAll(); + for (var emoji : emojiList) { + emojiDao.delete(emoji); + } + } + + @Test public void testReadAllOrdered() { List expectedEmojis = new ArrayList<>(); expectedEmojis.add(getEmoji("A1F6")); @@ -41,7 +49,7 @@ public void testReadAllOrdered() { List actualEmojis = emojiDao.readAllOrdered(); - Assert.assertArrayEquals( + assertArrayEquals( expectedEmojis.stream().map(Emoji::getGlyph).toArray(), actualEmojis.stream().map(Emoji::getGlyph).toArray() ); @@ -50,7 +58,7 @@ public void testReadAllOrdered() { @Test public void testReadByGlyph() { emojiDao.create(getEmoji("F1F6")); - assertTrue("F1F6".equals(emojiDao.readByGlyph("F1F6").getGlyph())); + assertEquals("F1F6", emojiDao.readByGlyph("F1F6").getGlyph()); } private Emoji getEmoji(String glyph) { diff --git a/src/test/java/ai/elimu/dao/ImageDaoTest.java b/src/test/java/ai/elimu/dao/ImageDaoTest.java index 026434f2c..50f8c425e 100644 --- a/src/test/java/ai/elimu/dao/ImageDaoTest.java +++ b/src/test/java/ai/elimu/dao/ImageDaoTest.java @@ -1,23 +1,21 @@ package ai.elimu.dao; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.apache.logging.log4j.Logger; -import static org.junit.Assert.*; -import static org.hamcrest.CoreMatchers.*; - -import org.junit.Test; -import org.junit.runner.RunWith; import ai.elimu.model.content.Word; import ai.elimu.model.content.multimedia.Image; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ +@SpringJUnitConfig(locations = { "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) @@ -42,7 +40,7 @@ public void testReadAllLabeled() { wordDao.create(wordCat); List images = imageDao.readAllLabeled(wordCat); - assertThat(images.size(), is(0)); + assertTrue(images.isEmpty()); Set words = new HashSet<>(); words.add(wordCat); @@ -53,18 +51,18 @@ public void testReadAllLabeled() { imageDao.create(image); images = imageDao.readAllLabeled(wordDog); - assertThat(images.size(), is(0)); + assertTrue(images.isEmpty()); images = imageDao.readAllLabeled(wordCat); - assertThat(images.size(), is(1)); - assertThat(images.get(0).getWords().size(), is(1)); + assertEquals(1, images.size()); + assertEquals(1, images.get(0).getWords().size()); words.add(wordDog); image.setWords(words); imageDao.update(image); images = imageDao.readAllLabeled(wordCat); - assertThat(images.size(), is(1)); - assertThat(images.get(0).getWords().size(), is(2)); + assertEquals(1, images.size()); + assertEquals(2, images.get(0).getWords().size()); } } diff --git a/src/test/java/ai/elimu/dao/LetterDaoTest.java b/src/test/java/ai/elimu/dao/LetterDaoTest.java index 8b1f2afb5..ba4c65108 100644 --- a/src/test/java/ai/elimu/dao/LetterDaoTest.java +++ b/src/test/java/ai/elimu/dao/LetterDaoTest.java @@ -1,26 +1,25 @@ package ai.elimu.dao; import ai.elimu.model.content.Letter; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.MethodOrderer.MethodName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import java.util.ArrayList; import java.util.List; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ - "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", - "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringJUnitConfig(locations = { + "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", + "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class LetterDaoTest extends TestCase { +@TestMethodOrder(MethodName.class) +public class LetterDaoTest { @Autowired private LetterDao letterDao; @@ -40,7 +39,7 @@ public void testReadAllOrdered() { List lettersActual = letterDao.readAllOrdered(); - Assert.assertArrayEquals( + assertArrayEquals( lettersExpected.stream().map(Letter::getText).toArray(), lettersActual.stream().map(Letter::getText).toArray() ); @@ -61,7 +60,7 @@ public void testReadAllOrderedByUsage() { List lettersActual = letterDao.readAllOrderedByUsage(); - Assert.assertArrayEquals( + assertArrayEquals( lettersExpected.stream().map(Letter::getText).toArray(), lettersActual.stream().filter(i -> i.getUsageCount() != 0).map(Letter::getText).toArray() ); diff --git a/src/test/java/ai/elimu/dao/NumberDaoTest.java b/src/test/java/ai/elimu/dao/NumberDaoTest.java index 230192f04..3474e85b2 100644 --- a/src/test/java/ai/elimu/dao/NumberDaoTest.java +++ b/src/test/java/ai/elimu/dao/NumberDaoTest.java @@ -1,22 +1,22 @@ package ai.elimu.dao; -import java.util.ArrayList; -import java.util.List; -import static org.junit.Assert.*; -import static org.hamcrest.CoreMatchers.*; - -import org.junit.Test; -import org.junit.runner.RunWith; import ai.elimu.model.content.Number; import ai.elimu.model.content.Word; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ +@SpringJUnitConfig(locations = { "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) @@ -49,10 +49,10 @@ public void testCreate_multipleWords() { number24.setWords(numberWords); numberDao.create(number24); - assertThat(numberDao.read(number24.getId()).getWords().isEmpty(), is(false)); - assertThat(numberDao.read(number24.getId()).getWords().size(), is(2)); - assertThat(numberDao.read(number24.getId()).getWords().get(0).getText(), is("twenty")); - assertThat(numberDao.read(number24.getId()).getWords().get(1).getText(), is("four")); + assertFalse(numberDao.read(number24.getId()).getWords().isEmpty()); + assertEquals(2, numberDao.read(number24.getId()).getWords().size()); + assertEquals("twenty", numberDao.read(number24.getId()).getWords().get(0).getText()); + assertEquals("four", numberDao.read(number24.getId()).getWords().get(1).getText()); } @Test @@ -64,8 +64,8 @@ public void testReadAllOrdered() { numberDao.create(getNumber(90)); List allNumbers = numberDao.readAllOrdered(); - assertThat(allNumbers.isEmpty(), is(false)); - assertThat(allNumbers.size() >= 5, is(true)); + assertFalse(allNumbers.isEmpty()); + assertTrue(allNumbers.size() >= 5); Number previousNumber = null; for (Number number: allNumbers) { logger.info("number.getValue(): " + number.getValue()); diff --git a/src/test/java/ai/elimu/dao/SoundDaoTest.java b/src/test/java/ai/elimu/dao/SoundDaoTest.java index 12a24b11f..717f187ef 100644 --- a/src/test/java/ai/elimu/dao/SoundDaoTest.java +++ b/src/test/java/ai/elimu/dao/SoundDaoTest.java @@ -1,28 +1,25 @@ package ai.elimu.dao; -import static org.junit.Assert.*; -import static org.hamcrest.CoreMatchers.*; - -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; import ai.elimu.model.content.Sound; import ai.elimu.model.v2.enums.content.sound.SoundType; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.MethodOrderer.MethodName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import java.util.ArrayList; import java.util.List; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringJUnitConfig(locations = { "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(MethodName.class) public class SoundDaoTest { @Autowired @@ -45,7 +42,7 @@ public void testAllOrderedRead() { List actualSounds = soundDao.readAllOrdered(); - Assert.assertArrayEquals( + Assertions.assertArrayEquals( expectedSounds.stream().map(Sound::getValueIpa).toArray(), actualSounds.stream().filter(i -> i.getValueIpa().length() == 1).map(Sound::getValueIpa).toArray() ); @@ -62,7 +59,7 @@ public void readAllOrderedByIpaValueCharacterLength() { List actualSounds = soundDao.readAllOrderedByIpaValueCharacterLength(); - Assert.assertArrayEquals( + Assertions.assertArrayEquals( expectedSounds.stream().map(Sound::getValueIpa).toArray(), actualSounds.stream().map(Sound::getValueIpa).toArray() ); @@ -85,7 +82,7 @@ public void testReadAllOrderedByUsage() { List actualSounds = soundDao.readAllOrderedByUsage(); - Assert.assertArrayEquals( + Assertions.assertArrayEquals( expectedSounds.stream().map(Sound::getUsageCount).toArray(), actualSounds.stream().filter(i -> i.getUsageCount() != 0).map(Sound::getUsageCount).toArray() ); @@ -97,7 +94,7 @@ public void testStoreSoundType() { sound.setSoundType(SoundType.VOWEL); soundDao.create(sound); - assertThat(soundDao.readByValueSampa("E").getSoundType(), is(SoundType.VOWEL)); + assertEquals(SoundType.VOWEL, soundDao.readByValueSampa("E").getSoundType()); assertTrue("ɛ".equals(soundDao.readByValueIpa("ɛ").getValueIpa())); } @@ -105,9 +102,9 @@ public void testStoreSoundType() { public void testLowerCaseVsUpperCase() { soundDao.create(getSound("t", "t")); soundDao.create(getSound("θ", "T")); - - assertThat(soundDao.readByValueSampa("t").getValueSampa(), is("t")); - assertThat(soundDao.readByValueSampa("T").getValueSampa(), is("T")); + + assertEquals("t", soundDao.readByValueSampa("t").getValueSampa()); + assertEquals("T", soundDao.readByValueSampa("T").getValueSampa()); } private Sound getSound(String ipa, String sampa) { diff --git a/src/test/java/ai/elimu/dao/StoryBookParagraphDaoTest.java b/src/test/java/ai/elimu/dao/StoryBookParagraphDaoTest.java index f0b18c73c..77fc76626 100644 --- a/src/test/java/ai/elimu/dao/StoryBookParagraphDaoTest.java +++ b/src/test/java/ai/elimu/dao/StoryBookParagraphDaoTest.java @@ -1,20 +1,15 @@ package ai.elimu.dao; -import ai.elimu.model.content.Sound; import ai.elimu.model.content.StoryBookParagraph; -import ai.elimu.model.v2.enums.content.sound.SoundType; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + import java.util.List; -import static org.junit.Assert.*; -import static org.hamcrest.CoreMatchers.*; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ +@SpringJUnitConfig(locations = { "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) @@ -27,10 +22,10 @@ public class StoryBookParagraphDaoTest { public void testReadAllContainingWord_apostrophe() { String wordText = "its"; List storyBookParagraphs = storyBookParagraphDao.readAllContainingWord(wordText); - assertThat(storyBookParagraphs.size(), is(0)); + assertTrue(storyBookParagraphs.isEmpty()); wordText = "it's"; storyBookParagraphs = storyBookParagraphDao.readAllContainingWord(wordText); - assertThat(storyBookParagraphs.size(), is(0)); + assertTrue(storyBookParagraphs.isEmpty()); } } diff --git a/src/test/java/ai/elimu/dao/VideoDaoTest.java b/src/test/java/ai/elimu/dao/VideoDaoTest.java index 735970db7..e430c9dda 100644 --- a/src/test/java/ai/elimu/dao/VideoDaoTest.java +++ b/src/test/java/ai/elimu/dao/VideoDaoTest.java @@ -1,26 +1,25 @@ package ai.elimu.dao; import ai.elimu.model.content.multimedia.Video; -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.MethodOrderer.MethodName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import java.util.ArrayList; import java.util.List; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations={ - "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", - "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringJUnitConfig(locations = { + "file:src/main/webapp/WEB-INF/spring/applicationContext.xml", + "file:src/main/webapp/WEB-INF/spring/applicationContext-jpa.xml" }) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class VideoDaoTest extends TestCase { +@TestMethodOrder(MethodName.class) +public class VideoDaoTest { @Autowired private VideoDao videoDao; @@ -38,7 +37,7 @@ public void testReadAllOrdered() { List