Skip to content

Commit

Permalink
Updated CharityTest
Browse files Browse the repository at this point in the history
100% coverage.
  • Loading branch information
roaraf committed Apr 23, 2026
1 parent ed164d1 commit 7201f0e
Showing 1 changed file with 160 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

import static org.junit.jupiter.api.Assertions.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import ntnu.systemutvikling.team6.models.user.Inbox;
import ntnu.systemutvikling.team6.models.user.Role;
import ntnu.systemutvikling.team6.models.user.Settings;
import ntnu.systemutvikling.team6.models.user.User;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -50,4 +57,157 @@ public void testIsVerifiedReturnsCorrectly() {
charity.setVerified();
assertEquals("approved", charity.getStatus());
}

@Test
public void testDatabaseSelectConstructor() {
UUID uuid = UUID.randomUUID();
String orgNumber = "123";
boolean preApproved = true;
String status = "approved";
Charity selectCharity =
new Charity(
uuid.toString(),
orgNumber,
preApproved,
status);

assertEquals(uuid, selectCharity.getUUID());
assertEquals(orgNumber, selectCharity.getOrg_number());
assertEquals(preApproved, selectCharity.getPreApproved());
assertEquals(status, selectCharity.getStatus());
}

@Test
void testDatabaseConstructor() {
UUID uuid = UUID.randomUUID();
String orgNumber = "123";
String name = "testChair";
boolean preApproved = true;
String status = "approved";
String description = "describe";
String logoURL = "www.image.png";
String keyValues = "90,2;10,5;98,0";

byte[] logoBlob = new byte[] {1, 2, 3, 4, 5};

Charity databaseCharity =
new Charity(
uuid.toString(),
orgNumber,
name,
logoURL,
status,
preApproved,
description,
logoURL,
keyValues,
logoBlob
);

assertEquals(uuid, databaseCharity.getUUID());
assertEquals(orgNumber, databaseCharity.getOrg_number());
assertEquals(name, databaseCharity.getName());
assertEquals(logoURL, databaseCharity.getLogoURL());
assertEquals(status, databaseCharity.getStatus());
assertEquals(preApproved, databaseCharity.getPreApproved());
assertEquals(description, databaseCharity.getDescription());
assertEquals(keyValues, databaseCharity.getKeyValues());
assertEquals(logoBlob, databaseCharity.getLogoBlob());
}

@Test
void getAndSetFeedbackShouldBeCorrect() {
String validUsername = "username";
String validEmail = "Email@gmail.com";
String validPassword = "Password";
Role validRole = Role.NORMAL_USER;
Settings validSettings = new Settings();
Inbox validInbox = new Inbox();
User user =
new User(
validUsername,
validEmail,
validPassword,
validRole,
validSettings,
validInbox);
Feedback feedback =
new Feedback(
UUID.randomUUID().toString(),
user,
"Feedback.",
LocalDate.now()
);
ArrayList<Feedback>feedbackList = new ArrayList<>();
feedbackList.add(feedback);

charity.setFeedbacks(feedbackList);

assertSame(charity.getFeedbacks(), feedbackList);
}

@Test
void setNameShouldBeCorrect() {
String name = "Bob's charity";

charity.setName(name);

assertEquals(name, charity.getName());
}

@Test
void setCategoryShouldBeCorrect() {
String category = "Ghana";
List<String> categoryList = new ArrayList<>();
categoryList.add(category);

charity.setCategory(categoryList);

assertEquals(category, charity.getCategory().getFirst());
}

@Test
void setDescriptionShouldBeCorrect() {
String description = "blablabla";

charity.setDescription(description);

assertEquals(description, charity.getDescription());
}

@Test
void setLogoUrlShouldBeCorrect() {
String logoURL = "www.image.png";

charity.setLogoURL(logoURL);

assertEquals(logoURL, charity.getLogoURL());
}

@Test
void setKeyValuesShouldBeCorrect() {
String keyValues = "98,2;5,6;75,4";

charity.setKeyValues(keyValues);

assertEquals(keyValues, charity.getKeyValues());
}

@Test
void setLogoBlobShouldBeCorrect() {
byte[] logoBlob = new byte[] {1, 2, 3, 4, 5};

charity.setLogoBlob(logoBlob);

assertEquals(logoBlob, charity.getLogoBlob());
}

@Test
void setUUIDFromStringShouldBeCorrect() {
UUID uuid = UUID.randomUUID();

charity.setUUIDFromString(uuid.toString());

assertEquals(uuid, charity.getUUID());
}
}

0 comments on commit 7201f0e

Please sign in to comment.