diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityRegistryTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityRegistryTest.java index 5176235..232431f 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityRegistryTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityRegistryTest.java @@ -1,94 +1,91 @@ package ntnu.systemutvikling.team6.models; -import ntnu.sytemutvikling.team6.models.Charity; -import ntnu.sytemutvikling.team6.models.CharityRegistry; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; import java.util.List; import java.util.Optional; import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; +import ntnu.sytemutvikling.team6.models.Charity; +import ntnu.sytemutvikling.team6.models.CharityRegistry; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * UnitTest for CharityRegistry class * * @author Adrian Balunan */ - public class CharityRegistryTest { - private CharityRegistry registry; - private Charity charity; - - /* Setting up variables */ - @BeforeEach - public void setup(){ - registry = new CharityRegistry(); - charity = new Charity("Charity1", "Something Somewhere Somehow", "Cancer"); - } - - - @Test - void testAddCharitySuccessfully() { - registry.addCharity(charity); - - assertEquals(1, registry.getAllCharities().size()); - assertTrue(registry.getAllCharities().contains(charity)); - } - - @Test - void testAddCharityNullThrowsException() { - assertThrows(IllegalArgumentException.class, () -> registry.addCharity(null)); - } - - @Test - void testGetAllCharitiesReturnsUnmodifiableList() { - registry.addCharity(charity); - - List charities = registry.getAllCharities(); - assertThrows(UnsupportedOperationException.class, () -> charities.add(charity)); - } - - @Test - void testFindCharityByIdFound() { - registry.addCharity(charity); - - Optional result = registry.findCharityById(charity.getId()); - - assertTrue(result.isPresent()); - assertEquals(charity, result.get()); - } - - @Test - void testFindCharityByIdNotFound() { - Optional result = registry.findCharityById(UUID.randomUUID()); - assertTrue(result.isEmpty()); - } - - @Test - void testFindCharityByIdNullThrowsException() { - assertThrows(IllegalArgumentException.class, () -> registry.findCharityById(null)); - } - - @Test - void testRemoveCharitySuccessfully() { - registry.addCharity(charity); - - boolean removed = registry.removeCharity(charity.getId()); - - assertTrue(removed); - assertTrue(registry.getAllCharities().isEmpty()); - } - - @Test - void testRemoveCharityNotFound() { - boolean removed = registry.removeCharity(UUID.randomUUID()); - assertFalse(removed); - } - - @Test - void testRemoveCharityNullThrowsException() { - assertThrows(IllegalArgumentException.class, () -> registry.removeCharity(null)); - } + private CharityRegistry registry; + private Charity charity; + + /* Setting up variables */ + @BeforeEach + public void setup() { + registry = new CharityRegistry(); + charity = new Charity("Charity1", "Something Somewhere Somehow", "Cancer"); + } + + @Test + void testAddCharitySuccessfully() { + registry.addCharity(charity); + + assertEquals(1, registry.getAllCharities().size()); + assertTrue(registry.getAllCharities().contains(charity)); + } + + @Test + void testAddCharityNullThrowsException() { + assertThrows(IllegalArgumentException.class, () -> registry.addCharity(null)); + } + + @Test + void testGetAllCharitiesReturnsUnmodifiableList() { + registry.addCharity(charity); + + List charities = registry.getAllCharities(); + assertThrows(UnsupportedOperationException.class, () -> charities.add(charity)); + } + + @Test + void testFindCharityByIdFound() { + registry.addCharity(charity); + + Optional result = registry.findCharityById(charity.getId()); + + assertTrue(result.isPresent()); + assertEquals(charity, result.get()); + } + + @Test + void testFindCharityByIdNotFound() { + Optional result = registry.findCharityById(UUID.randomUUID()); + assertTrue(result.isEmpty()); + } + + @Test + void testFindCharityByIdNullThrowsException() { + assertThrows(IllegalArgumentException.class, () -> registry.findCharityById(null)); + } + + @Test + void testRemoveCharitySuccessfully() { + registry.addCharity(charity); + + boolean removed = registry.removeCharity(charity.getId()); + + assertTrue(removed); + assertTrue(registry.getAllCharities().isEmpty()); + } + + @Test + void testRemoveCharityNotFound() { + boolean removed = registry.removeCharity(UUID.randomUUID()); + assertFalse(removed); + } + + @Test + void testRemoveCharityNullThrowsException() { + assertThrows(IllegalArgumentException.class, () -> registry.removeCharity(null)); + } } diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityTest.java index 1707499..5c2f9c2 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityTest.java @@ -1,68 +1,62 @@ package ntnu.systemutvikling.team6.models; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.UUID; import ntnu.sytemutvikling.team6.models.Charity; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; - /** * UnitTesting for Charity. * * @author Adrian Balunan */ public class CharityTest { - private Charity charity; - - @BeforeEach - public void setup(){ - charity = new Charity("Charity1", "Something Somewhere Somehow", "Cancer"); - } - - /** - * Getters should work: - */ - @Test - public void testGettingIdShouldWork(){ - assertInstanceOf(UUID.class, charity.getId()); - } - @Test - public void testGettingCategoryShouldWork(){ - assertEquals("Cancer", charity.getCategory()); - } - @Test - public void testGettingNameShouldWork(){ - assertEquals( "Charity1",charity.getName()); - } - @Test - public void testGettingDescriptionShouldWork(){ - assertEquals("Something Somewhere Somehow",charity.getDescription()); - } - - /** - * Getter and setter for IsVerified should be able to switch between true and false - */ - @Test - public void testIsVerifiedReturnsCorrectly(){ - assertFalse(charity.isVerified()); - charity.setVerified(); - assertTrue(charity.isVerified()); - charity.setUnverified(); - assertFalse(charity.isVerified()); - } - - /** - * totalDonations should display accuratly and adding works - */ - @Test - public void testTotalDonationsReturnsCorrectlyAfterChanges(){ - assertEquals(0, charity.getTotalDonations()); - charity.setTotalDonations(10); - charity.setTotalDonations(5); - assertEquals(15, charity.getTotalDonations()); - } - + private Charity charity; + + @BeforeEach + public void setup() { + charity = new Charity("Charity1", "Something Somewhere Somehow", "Cancer"); + } + + /** Getters should work: */ + @Test + public void testGettingIdShouldWork() { + assertInstanceOf(UUID.class, charity.getId()); + } + + @Test + public void testGettingCategoryShouldWork() { + assertEquals("Cancer", charity.getCategory()); + } + + @Test + public void testGettingNameShouldWork() { + assertEquals("Charity1", charity.getName()); + } + + @Test + public void testGettingDescriptionShouldWork() { + assertEquals("Something Somewhere Somehow", charity.getDescription()); + } + + /** Getter and setter for IsVerified should be able to switch between true and false */ + @Test + public void testIsVerifiedReturnsCorrectly() { + assertFalse(charity.isVerified()); + charity.setVerified(); + assertTrue(charity.isVerified()); + charity.setUnverified(); + assertFalse(charity.isVerified()); + } + + /** totalDonations should display accuratly and adding works */ + @Test + public void testTotalDonationsReturnsCorrectlyAfterChanges() { + assertEquals(0, charity.getTotalDonations()); + charity.setTotalDonations(10); + charity.setTotalDonations(5); + assertEquals(15, charity.getTotalDonations()); + } } diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java index dca66b7..c4851b5 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java @@ -1,115 +1,99 @@ package ntnu.systemutvikling.team6.models; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; import java.time.LocalDateTime; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; +import ntnu.sytemutvikling.team6.models.Charity; +import ntnu.sytemutvikling.team6.models.Donation; +import ntnu.sytemutvikling.team6.models.user.Inbox; +import ntnu.sytemutvikling.team6.models.user.Role; +import ntnu.sytemutvikling.team6.models.user.Settings; +import ntnu.sytemutvikling.team6.models.user.User; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; class DonationTest { - private Settings settings; - private User user; - private Charity charity; - - // -- Setup -- - @BeforeEach - public void setup(){ - charity = new Charity("name", "something somewhere somehow", "Meow"); - User = new User(); - } - - - // --- Tests --- - @Test - void testDonationInitialization() { - Charity charity = new Charity(); - User user = new User(new UserSettings(true)); - LocalDateTime now = LocalDateTime.now(); - - Donation donation = new Donation(500.0, now, charity, user); - - assertNotNull(donation.getCharityId()); - assertEquals(500.0, donation.getAmount()); - assertEquals(now, donation.getDate()); - assertEquals(charity, donation.getCharity()); - assertEquals(user, donation.getDonor()); - } - - @Test - void testAnonymousFlagWhenUserIsAnonymous() { - User user = new User(new UserSettings(true)); - Charity charity = new Charity(); - Donation donation = new Donation(100, LocalDateTime.now(), charity, user); - - // According to your logic: - // if donor.getSettings().isAnonymous() == false → donation.isAnonymous = true - // else → donation.isAnonymous = false - // - // So if user.isAnonymous() == true → donation.isAnonymous should be false - assertFalse(donation.isAnonymous()); - } - - @Test - void testAnonymousFlagWhenUserIsNotAnonymous() { - User user = new User(new UserSettings(false)); - Charity charity = new Charity(); - Donation donation = new Donation(100, LocalDateTime.now(), charity, user); - - // If user.isAnonymous() == false → donation.isAnonymous = true - assertTrue(donation.isAnonymous()); - } - - @Test - void testCharityIdIsUnique() { - Charity charity = new Charity(); - User user = new User(new UserSettings(true)); - - Donation d1 = new Donation(50, LocalDateTime.now(), charity, user); - Donation d2 = new Donation(75, LocalDateTime.now(), charity, user); - - assertNotEquals(d1.getCharityId(), d2.getCharityId()); - } - - @Test - void testAmountStoredCorrectly() { - Charity charity = new Charity(); - User user = new User(new UserSettings(true)); - - Donation donation = new Donation(123.45, LocalDateTime.now(), charity, user); - - assertEquals(123.45, donation.getAmount()); - } - - @Test - void testDateStoredCorrectly() { - LocalDateTime date = LocalDateTime.of(2024, 5, 10, 12, 30); - Charity charity = new Charity(); - User user = new User(new UserSettings(true)); - - Donation donation = new Donation(200, date, charity, user); - - assertEquals(date, donation.getDate()); - } - - @Test - void testCharityStoredCorrectly() { - Charity charity = new Charity(); - User user = new User(new UserSettings(true)); - - Donation donation = new Donation(200, LocalDateTime.now(), charity, user); - - assertEquals(charity, donation.getCharity()); - } - - @Test - void testDonorStoredCorrectly() { - Charity charity = new Charity(); - User user = new User(new UserSettings(true)); - - Donation donation = new Donation(200, LocalDateTime.now(), charity, user); - - assertEquals(user, donation.getDonor()); - } -} \ No newline at end of file + private Settings settings; + private User user; + private Charity charity; + + // -- Setup -- + @BeforeEach + public void setup() { + charity = new Charity("name", "something somewhere somehow", "Meow"); + user = + new User("Name", "Valid@gmail.com", "123", Role.NORMAL_USER, new Settings(), new Inbox()); + } + + // --- Tests --- + @Test + void testDonationInitialization() { + LocalDateTime now = LocalDateTime.now(); + + Donation donation = new Donation(500.0, now, charity, user); + + assertNotNull(donation.getCharityId()); + assertEquals(500.0, donation.getAmount()); + assertEquals(now, donation.getDate()); + assertEquals(charity, donation.getCharity()); + assertEquals(user, donation.getDonor()); + } + + @Test + void testAnonymousFlagWhenUserIsAnonymous() { + Donation donation = new Donation(100, LocalDateTime.now(), charity, user); + + // According to your logic: + // if donor.getSettings().isAnonymous() == false → donation.isAnonymous = true + // else → donation.isAnonymous = false + // + // So if user.isAnonymous() == true → donation.isAnonymous should be false + assertFalse(donation.isAnonymous()); + } + + @Test + void testAnonymousFlagWhenUserIsNotAnonymous() { + Donation donation = new Donation(100, LocalDateTime.now(), charity, user); + + // If user.isAnonymous() == false → donation.isAnonymous = true + assertTrue(donation.isAnonymous()); + } + + @Test + void testCharityIdIsUnique() { + Donation d1 = new Donation(50, LocalDateTime.now(), charity, user); + Donation d2 = new Donation(75, LocalDateTime.now(), charity, user); + + assertNotEquals(d1.getCharityId(), d2.getCharityId()); + } + + @Test + void testAmountStoredCorrectly() { + Donation donation = new Donation(123.45, LocalDateTime.now(), charity, user); + + assertEquals(123.45, donation.getAmount()); + } + + @Test + void testDateStoredCorrectly() { + LocalDateTime date = LocalDateTime.of(2024, 5, 10, 12, 30); + + Donation donation = new Donation(200, date, charity, user); + + assertEquals(date, donation.getDate()); + } + + @Test + void testCharityStoredCorrectly() { + Donation donation = new Donation(200, LocalDateTime.now(), charity, user); + + assertEquals(charity, donation.getCharity()); + } + + @Test + void testDonorStoredCorrectly() { + Donation donation = new Donation(200, LocalDateTime.now(), charity, user); + + assertEquals(user, donation.getDonor()); + } +} diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/FeedbackTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/FeedbackTest.java index f3e3e8d..b21def7 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/FeedbackTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/FeedbackTest.java @@ -1,91 +1,86 @@ package ntnu.systemutvikling.team6.models; -import ntnu.sytemutvikling.team6.models.Settings; -import ntnu.sytemutvikling.team6.models.User; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; import java.time.LocalDateTime; -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; +import ntnu.sytemutvikling.team6.models.Feedback; +import ntnu.sytemutvikling.team6.models.user.Inbox; +import ntnu.sytemutvikling.team6.models.user.Role; +import ntnu.sytemutvikling.team6.models.user.Settings; +import ntnu.sytemutvikling.team6.models.user.User; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; class FeedbackTest { - private User user; - private Settings settings; - - // -- Setup -- - @BeforeEach - public void setup() { - settings = new Settings(true); // default anonymous = true - user = new User(); - } - - // --- Tests --- + private User user; + private Settings settings; - @Test - void testFeedbackInitialization() { - LocalDateTime before = LocalDateTime.now(); - Feedback feedback = new Feedback(user, "Nice work!"); - LocalDateTime after = LocalDateTime.now(); + // -- Setup -- + @BeforeEach + public void setup() { + settings = new Settings(); // default anonymous = true + user = + new User("Name", "Valid@gmail.com", "123", Role.NORMAL_USER, new Settings(), new Inbox()); + } - assertNotNull(feedback.getFeedbackId()); - assertEquals("Nice work!", feedback.getComment()); - assertEquals(user, feedback.getUser()); + // --- Tests --- - // Date should be between before and after - assertTrue(!feedback.getDate().isBefore(before) && !feedback.getDate().isAfter(after)); - } + @Test + void testFeedbackInitialization() { + LocalDateTime before = LocalDateTime.now(); + Feedback feedback = new Feedback(user, "Nice work!"); + LocalDateTime after = LocalDateTime.now(); - @Test - void testAnonymousFlagWhenUserIsAnonymous() { - // user.settings.isAnonymous() == true → feedback.isAnonymous = false - settings = new UserSettings(true); - user = new User(settings); + assertNotNull(feedback.getFeedbackId()); + assertEquals("Nice work!", feedback.getComment()); + assertEquals(user, feedback.getUser()); - Feedback feedback = new Feedback(user, "Anonymous feedback"); + // Date should be between before and after + assertTrue(!feedback.getDate().isBefore(before) && !feedback.getDate().isAfter(after)); + } - assertFalse(feedback.isAnonymous()); - } + @Test + void testAnonymousFlagWhenUserIsAnonymous() { + // user.settings.isAnonymous() == true → feedback.isAnonymous = false + Feedback feedback = new Feedback(user, "Anonymous feedback"); - @Test - void testAnonymousFlagWhenUserIsNotAnonymous() { - // user.settings.isAnonymous() == false → feedback.isAnonymous = true - settings = new UserSettings(false); - user = new User(settings); + assertFalse(feedback.isAnonymous()); + } - Feedback feedback = new Feedback(user, "Not anonymous"); + @Test + void testAnonymousFlagWhenUserIsNotAnonymous() { + Feedback feedback = new Feedback(user, "Not anonymous"); - assertTrue(feedback.isAnonymous()); - } + assertTrue(feedback.isAnonymous()); + } - @Test - void testFeedbackIdIsUnique() { - Feedback f1 = new Feedback(user, "First"); - Feedback f2 = new Feedback(user, "Second"); + @Test + void testFeedbackIdIsUnique() { + Feedback f1 = new Feedback(user, "First"); + Feedback f2 = new Feedback(user, "Second"); - assertNotEquals(f1.getFeedbackId(), f2.getFeedbackId()); - } + assertNotEquals(f1.getFeedbackId(), f2.getFeedbackId()); + } - @Test - void testCommentStoredCorrectly() { - Feedback feedback = new Feedback(user, "This is a test comment"); + @Test + void testCommentStoredCorrectly() { + Feedback feedback = new Feedback(user, "This is a test comment"); - assertEquals("This is a test comment", feedback.getComment()); - } + assertEquals("This is a test comment", feedback.getComment()); + } - @Test - void testUserStoredCorrectly() { - Feedback feedback = new Feedback(user, "Hello"); + @Test + void testUserStoredCorrectly() { + Feedback feedback = new Feedback(user, "Hello"); - assertEquals(user, feedback.getUser()); - } + assertEquals(user, feedback.getUser()); + } - @Test - void testDateIsSet() { - Feedback feedback = new Feedback(user, "Testing date"); + @Test + void testDateIsSet() { + Feedback feedback = new Feedback(user, "Testing date"); - assertNotNull(feedback.getDate()); - } -} \ No newline at end of file + assertNotNull(feedback.getDate()); + } +} diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/SettingsTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/SettingsTest.java deleted file mode 100644 index 3221be5..0000000 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/SettingsTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package ntnu.systemutvikling.team6.models; - -import ntnu.sytemutvikling.team6.models.Language; -import ntnu.sytemutvikling.team6.models.Settings; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class SettingsTest { - - @Test - void testDefaultConstructorSetsStandardValues() { - Settings settings = new Settings(); - - assertTrue(settings.isLightMode()); - assertEquals(Language.ENGLISH, settings.getLanguage()); - assertFalse(settings.isAnonymous()); - } - - @Test - void testCustomConstructorSetsValuesCorrectly() { - Settings settings = new Settings(false, Language.ENGLISH, true); - - assertFalse(settings.isLightMode()); - assertEquals(Language.ENGLISH, settings.getLanguage()); - assertTrue(settings.isAnonymous()); - } - - @Test - void testConstructorThrowsExceptionWhenLanguageIsNull() { - assertThrows(IllegalArgumentException.class, - () -> new Settings(true, null, false)); - } - - @Test - void testToggleLightMode() { - Settings settings = new Settings(true, Language.ENGLISH, false); - - settings.toggleLightMode(); - assertFalse(settings.isLightMode()); - - settings.toggleLightMode(); - assertTrue(settings.isLightMode()); - } - - @Test - void testToggleAnonymousMode() { - Settings settings = new Settings(true, Language.ENGLISH, false); - - settings.toggleAnonymousMode(); - assertTrue(settings.isAnonymous()); - - settings.toggleAnonymousMode(); - assertFalse(settings.isAnonymous()); - } - - @Test - void testChangeLanguageSuccessfully() { - Settings settings = new Settings(); - - settings.changeLanguage(Language.ENGLISH); - assertEquals(Language.ENGLISH, settings.getLanguage()); - } - - @Test - void testChangeLanguageThrowsExceptionWhenNull() { - Settings settings = new Settings(); - - assertThrows(IllegalArgumentException.class, - () -> settings.changeLanguage(null)); - } -} \ No newline at end of file diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/SettingsTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/SettingsTest.java new file mode 100644 index 0000000..18b2814 --- /dev/null +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/SettingsTest.java @@ -0,0 +1,70 @@ +package ntnu.systemutvikling.team6.models.user; + +import static org.junit.jupiter.api.Assertions.*; + +import ntnu.sytemutvikling.team6.models.user.Language; +import ntnu.sytemutvikling.team6.models.user.Settings; +import org.junit.jupiter.api.Test; + +class SettingsTest { + + @Test + void testDefaultConstructorSetsStandardValues() { + Settings settings = new Settings(); + + assertTrue(settings.isLightMode()); + assertEquals(Language.ENGLISH, settings.getLanguage()); + assertFalse(settings.isAnonymous()); + } + + @Test + void testCustomConstructorSetsValuesCorrectly() { + Settings settings = new Settings(false, Language.ENGLISH, true); + + assertFalse(settings.isLightMode()); + assertEquals(Language.ENGLISH, settings.getLanguage()); + assertTrue(settings.isAnonymous()); + } + + @Test + void testConstructorThrowsExceptionWhenLanguageIsNull() { + assertThrows(IllegalArgumentException.class, () -> new Settings(true, null, false)); + } + + @Test + void testToggleLightMode() { + Settings settings = new Settings(true, Language.ENGLISH, false); + + settings.toggleLightMode(); + assertFalse(settings.isLightMode()); + + settings.toggleLightMode(); + assertTrue(settings.isLightMode()); + } + + @Test + void testToggleAnonymousMode() { + Settings settings = new Settings(true, Language.ENGLISH, false); + + settings.toggleAnonymousMode(); + assertTrue(settings.isAnonymous()); + + settings.toggleAnonymousMode(); + assertFalse(settings.isAnonymous()); + } + + @Test + void testChangeLanguageSuccessfully() { + Settings settings = new Settings(); + + settings.changeLanguage(Language.ENGLISH); + assertEquals(Language.ENGLISH, settings.getLanguage()); + } + + @Test + void testChangeLanguageThrowsExceptionWhenNull() { + Settings settings = new Settings(); + + assertThrows(IllegalArgumentException.class, () -> settings.changeLanguage(null)); + } +} diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/UserTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/UserTest.java new file mode 100644 index 0000000..7bd0ff4 --- /dev/null +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/UserTest.java @@ -0,0 +1,164 @@ +package ntnu.systemutvikling.team6.models.user; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.UUID; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +class UserTest { + + @Nested + class constructorTests { + private final UUID validID = UUID.randomUUID(); + private final String validName = "Name"; + private final String validEmail = "Email@gmail.com"; + private final String validPassword = "Password"; + private final Role validRole = Role.NORMAL_USER; + private final Settings validSettings = new Settings(); + private final Inbox validInbox = new Inbox(); + + @Test + void shouldThrowIfIdIsNull() { + assertThrows( + IllegalArgumentException.class, + () -> + new User( + null, + validName, + validEmail, + validPassword, + validRole, + validSettings, + validInbox)); + } + + @Test + void shouldThrowIfNameIsNull() { + assertThrows( + IllegalArgumentException.class, + () -> + new User( + validID, null, validEmail, validPassword, validRole, validSettings, validInbox)); + } + + @Test + void shouldThrowIfNameIsBlank() { + assertThrows( + IllegalArgumentException.class, + () -> + new User( + validID, " ", validEmail, validPassword, validRole, validSettings, validInbox)); + } + + @Nested + class emailTests { + + @Test + void shouldThrowIfEmailIsNull() { + assertThrows( + IllegalArgumentException.class, + () -> + new User( + validID, validName, null, validPassword, validRole, validSettings, validInbox)); + } + + @Test + void shouldThrowIfEmailIsBlank() { + assertThrows( + IllegalArgumentException.class, + () -> + new User( + validID, validName, " ", validPassword, validRole, validSettings, validInbox)); + } + + @Test + void shouldThrowIfEmailDoesNotContainAt() { + assertThrows( + IllegalArgumentException.class, + () -> + new User( + validID, + validName, + "test.gmail.com", + validPassword, + validRole, + validSettings, + validInbox)); + } + + @Test + void shouldThrowIfEmailDoesNotContainPeriod() { + assertThrows( + IllegalArgumentException.class, + () -> + new User( + validID, + validName, + "test@gmailcom", + validPassword, + validRole, + validSettings, + validInbox)); + } + } + + @Test + void shouldThrowIfPasswordIsNull() { + assertThrows( + IllegalArgumentException.class, + () -> + new User(validID, validName, validEmail, null, validRole, validSettings, validInbox)); + } + + @Test + void shouldThrowIfRoleIsNull() { + assertThrows( + IllegalArgumentException.class, + () -> + new User( + validID, validName, validEmail, validPassword, null, validSettings, validInbox)); + } + + @Test + void shouldThrowIfPasswordIsBlank() { + assertThrows( + IllegalArgumentException.class, + () -> + new User(validID, validName, validEmail, " ", validRole, validSettings, validInbox)); + } + + @Test + void shouldThrowIfSettingsIsNull() { + assertThrows( + IllegalArgumentException.class, + () -> + new User(validID, validName, validEmail, validPassword, validRole, null, validInbox)); + } + + @Test + void shouldThrowIfInboxIsNull() { + assertThrows( + IllegalArgumentException.class, + () -> + new User( + validID, validName, validEmail, validPassword, validRole, validSettings, null)); + } + + @Test + void shouldCreateUser() { + User user = + new User( + validID, validName, validEmail, validPassword, validRole, validSettings, validInbox); + + assertAll( + () -> assertEquals(validID, user.getId()), + () -> assertEquals(validName, user.getName()), + () -> assertEquals(validEmail, user.getEmail()), + () -> assertEquals(validRole, user.getRole()), + () -> assertEquals(validSettings, user.getSettings()), + () -> assertEquals(validInbox, user.getInbox())); + } + } +} diff --git a/helpmehelpapplication/src/test/java/ntnu/sytemutvikling/team6/security/PasswordHasherTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/security/PasswordHasherTest.java similarity index 97% rename from helpmehelpapplication/src/test/java/ntnu/sytemutvikling/team6/security/PasswordHasherTest.java rename to helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/security/PasswordHasherTest.java index 68a9409..dada18f 100644 --- a/helpmehelpapplication/src/test/java/ntnu/sytemutvikling/team6/security/PasswordHasherTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/security/PasswordHasherTest.java @@ -1,10 +1,10 @@ -package ntnu.sytemutvikling.team6.security; +package ntnu.systemutvikling.team6.security; + +import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - class PasswordHasherTest { private final PasswordHasher hasher = new PasswordHasher(); @@ -67,4 +67,4 @@ void shouldThrowIfStoredHashIsBlank() { assertThrows(RuntimeException.class, () -> hasher.isValidPassword("Password", " ")); } } -} \ No newline at end of file +} diff --git a/helpmehelpapplication/src/test/java/ntnu/sytemutvikling/team6/models/user/UserTest.java b/helpmehelpapplication/src/test/java/ntnu/sytemutvikling/team6/models/user/UserTest.java deleted file mode 100644 index 5fa92c8..0000000 --- a/helpmehelpapplication/src/test/java/ntnu/sytemutvikling/team6/models/user/UserTest.java +++ /dev/null @@ -1,218 +0,0 @@ -package ntnu.sytemutvikling.team6.models.user; - -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertEquals; - -class UserTest { - - @Nested - class constructorTests { - private final UUID validID = UUID.randomUUID(); - private final String validName = "Name"; - private final String validEmail = "Email@gmail.com"; - private final String validPassword = "Password"; - private final Role validRole = Role.NORMAL_USER; - private final Settings validSettings = new Settings(); - private final Inbox validInbox = new Inbox(); - - @Test - void shouldThrowIfIdIsNull() { - assertThrows(IllegalArgumentException.class, () -> - new User( - null, - validName, - validEmail, - validPassword, - validRole, - validSettings, - validInbox - )); - } - - @Test - void shouldThrowIfNameIsNull() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - null, - validEmail, - validPassword, - validRole, - validSettings, - validInbox - )); - } - - @Test - void shouldThrowIfNameIsBlank() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - " ", - validEmail, - validPassword, - validRole, - validSettings, - validInbox - )); - } - - @Nested - class emailTests { - - @Test - void shouldThrowIfEmailIsNull() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - validName, - null, - validPassword, - validRole, - validSettings, - validInbox - )); - } - - @Test - void shouldThrowIfEmailIsBlank() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - validName, - " ", - validPassword, - validRole, - validSettings, - validInbox - )); - } - - @Test - void shouldThrowIfEmailDoesNotContainAt() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - validName, - "test.gmail.com", - validPassword, - validRole, - validSettings, - validInbox - )); - } - - @Test - void shouldThrowIfEmailDoesNotContainPeriod() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - validName, - "test@gmailcom", - validPassword, - validRole, - validSettings, - validInbox - )); - } - } - - @Test - void shouldThrowIfPasswordIsNull() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - validName, - validEmail, - null, - validRole, - validSettings, - validInbox - )); - } - - @Test - void shouldThrowIfRoleIsNull() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - validName, - validEmail, - validPassword, - null, - validSettings, - validInbox - )); - } - - @Test - void shouldThrowIfPasswordIsBlank() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - validName, - validEmail, - " ", - validRole, - validSettings, - validInbox - )); - } - - @Test - void shouldThrowIfSettingsIsNull() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - validName, - validEmail, - validPassword, - validRole, - null, - validInbox - )); - } - - @Test - void shouldThrowIfInboxIsNull() { - assertThrows(IllegalArgumentException.class, () -> - new User( - validID, - validName, - validEmail, - validPassword, - validRole, - validSettings, - null - )); - } - - @Test - void shouldCreateUser() { - User user = new User( - validID, - validName, - validEmail, - validPassword, - validRole, - validSettings, - validInbox - ); - - assertAll( - () -> assertEquals(validID, user.getId()), - () -> assertEquals(validName, user.getName()), - () -> assertEquals(validEmail, user.getEmail()), - () -> assertEquals(validRole, user.getRole()), - () -> assertEquals(validSettings, user.getSettings()), - () -> assertEquals(validInbox, user.getInbox()) - ); - } - - } -} \ No newline at end of file diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/Main.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/Main.class deleted file mode 100644 index 110f8b9..0000000 Binary files a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/Main.class and /dev/null differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Inbox.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Inbox.class deleted file mode 100644 index 4e08a72..0000000 Binary files a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Inbox.class and /dev/null differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Language.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Language.class deleted file mode 100644 index 5520821..0000000 Binary files a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Language.class and /dev/null differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Message.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Message.class deleted file mode 100644 index e556e51..0000000 Binary files a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Message.class and /dev/null differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Role.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Role.class deleted file mode 100644 index 8d6c32e..0000000 Binary files a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Role.class and /dev/null differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Settings.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Settings.class deleted file mode 100644 index 26851ad..0000000 Binary files a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/Settings.class and /dev/null differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/User.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/User.class deleted file mode 100644 index e981ecb..0000000 Binary files a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/models/user/User.class and /dev/null differ diff --git a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/security/PasswordHasher.class b/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/security/PasswordHasher.class deleted file mode 100644 index e454773..0000000 Binary files a/helpmehelpapplication/target/classes/ntnu/sytemutvikling/team6/security/PasswordHasher.class and /dev/null differ diff --git a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/models/user/UserTest$constructorTests$emailTests.class b/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/models/user/UserTest$constructorTests$emailTests.class deleted file mode 100644 index 51a8c3c..0000000 Binary files a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/models/user/UserTest$constructorTests$emailTests.class and /dev/null differ diff --git a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/models/user/UserTest$constructorTests.class b/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/models/user/UserTest$constructorTests.class deleted file mode 100644 index e7def3c..0000000 Binary files a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/models/user/UserTest$constructorTests.class and /dev/null differ diff --git a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/models/user/UserTest.class b/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/models/user/UserTest.class deleted file mode 100644 index 810d4b9..0000000 Binary files a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/models/user/UserTest.class and /dev/null differ diff --git a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/security/PasswordHasherTest$getHashPasswordTest.class b/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/security/PasswordHasherTest$getHashPasswordTest.class deleted file mode 100644 index 4047693..0000000 Binary files a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/security/PasswordHasherTest$getHashPasswordTest.class and /dev/null differ diff --git a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/security/PasswordHasherTest$isValidPasswordTest.class b/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/security/PasswordHasherTest$isValidPasswordTest.class deleted file mode 100644 index 7d04343..0000000 Binary files a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/security/PasswordHasherTest$isValidPasswordTest.class and /dev/null differ diff --git a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/security/PasswordHasherTest.class b/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/security/PasswordHasherTest.class deleted file mode 100644 index 93e185d..0000000 Binary files a/helpmehelpapplication/target/test-classes/ntnu/sytemutvikling/team6/security/PasswordHasherTest.class and /dev/null differ