Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/domain/organization/Organization.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Organization {

@JsonProperty("status")
private String status;

@JsonProperty("url")
private String url;

Expand All @@ -29,7 +29,6 @@ public class Organization {

public Organization() {}


public String getOrgNumber() { return orgNumber; }
public void setOrgNumber(String orgNumber) { this.orgNumber = orgNumber; }

Expand Down
115 changes: 115 additions & 0 deletions src/test/java/domain/DonationTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,120 @@
package domain;

import domain.donation.Cause;
import domain.donation.Donation;
import domain.organization.Organization;
import domain.user.User;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

class DonationTest {

//User Variables
private final String testUserName = "testUser";
private final String testPhoneNumber = "90909090";
private final String testEmail = "test@email.com";
private final String testPassword = "password";

//Organization Variables
private final String testName = "Name";
private final String testOrgNr = "123456789";
private final Cause testCause = Cause.HEALTH;
private final String testDescription = "Description";
private final String testContactEmail = "test@mail.com";
private final String testWebsite = "https://test.com";
private final boolean testVerified = true;

//Donation Variables
private Long testID = 123L;
private BigDecimal testAmount = new BigDecimal("1500");
private LocalDateTime testDateTime = LocalDateTime.of(2026, 3, 5, 8, 30, 0);
private User testUser;
private Organization testOrganization;

@BeforeEach
public void init() {
testUser = new User(testUserName, testPhoneNumber, testPassword, testEmail);
testOrganization = new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified);
}


@Test
public void DonationTestPositive(){
Donation donation = new Donation(testAmount, testUser, testOrganization);
}

@Test
public void DonationTestUserNull(){
testUser = null;
NullPointerException Exception = assertThrows(NullPointerException.class,
() -> new Donation (testAmount, testUser, testOrganization));

assertEquals("User cannot be null", Exception.getMessage());
}

@Test
public void DonationOrganizationNull(){
testOrganization = null;
NullPointerException Exception = assertThrows(NullPointerException.class,
() -> new Donation (testAmount, testUser, testOrganization));

assertEquals("Organization cannot be null", Exception.getMessage());
}

@Test
public void DonationTestAmountNegative(){
testAmount = new BigDecimal("-23");
IllegalArgumentException Exception = assertThrows(IllegalArgumentException.class,
() -> new Donation (testAmount, testUser, testOrganization));

assertEquals("Amount must be greater than 0", Exception.getMessage());
}

//Getter tests
/* id is never set, getter makes a NullPointerException
@Test
public void DonationTestIdGet(){
Donation donation = new Donation(testAmount, testUser, testOrganization);
assertEquals(0L, donation.getId());
}
*/

@Test
public void DonationTestAmountGet(){
Donation donation = new Donation(testAmount, testUser, testOrganization);
assertEquals(testAmount, donation.getAmount());

}

@Test
public void DonationTestDateTimeGet(){
LocalDateTime now = LocalDateTime.now();
Donation donation = new Donation(testAmount, testUser, testOrganization);

assertTrue(Duration.between(now, donation.getDateTime()).abs().toMillis() < 1000);

}

@Test
public void DonationTestUserGet(){
Donation donation = new Donation(testAmount, testUser, testOrganization);
assertEquals(testUser, donation.getUser());

}

@Test
public void DonationTestOrganizationGet(){
Donation donation = new Donation(testAmount, testUser, testOrganization);
assertEquals(testOrganization, donation.getOrganization());

}
}
202 changes: 202 additions & 0 deletions src/test/java/domain/OrganizationTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,207 @@
package domain;

import domain.donation.Cause;
import domain.organization.Organization;
import domain.user.User;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class OrganizationTest {
private String testName = "Name";
private String testOrgNr = "123456789";
private Cause testCause = Cause.HEALTH;
private String testDescription = "Description";
private String testContactEmail = "test@mail.com";
private String testWebsite = "https://test.com";
private boolean testVerified = true;

//Positive tests
@Test
public void organizationTestPositive(){
Organization organization = new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified);
}

//Negative tests
@Test
public void organizationTestNameBlank(){
testName = "";
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization("", testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Name cannot be null or blank", exception.getMessage());
}

@Test
public void organizationTestNameNull(){
testName = null;
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Name cannot be null or blank", exception.getMessage());
}

@Test
public void organizationTestOrgNrNull(){
testOrgNr = null;
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Organization number must be 9 digits", exception.getMessage());
}

@Test
public void organizationTestOrgNrLetters(){
testOrgNr = "12345678a";
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Organization number must be 9 digits", exception.getMessage());
}

@Test
public void organizationTestOrgNrShort(){
testOrgNr = "12345";
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Organization number must be 9 digits", exception.getMessage());
}

/* Mangler exception for når email er null
@Test
public void organizationTestContactEmailNull(){
testContactEmail = null;
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));
}
*/

@Test
public void organizationTestContactEmailTrim(){
testContactEmail = "test@mail.com ";
Organization organization = new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified);
}

@Test
public void organizationTestContactEmailBlank(){
testContactEmail = "";
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Email cannot be blank", exception.getMessage());
}

@Test
public void organizationTestContactEmailMissingAt(){
testContactEmail = "test.com";
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Invalid email format", exception.getMessage());
}

@Test
public void organizationTestContactEmailDoubleAt(){
testContactEmail = "test@@mail.com";
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Invalid email format", exception.getMessage());
}

@Test
public void organizationTestContactEmailMisplacedAt(){
testContactEmail = "@testmail.com";
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Invalid email format", exception.getMessage());
}

@Test
public void organizationTestContactEmailMissingDot(){
testContactEmail = "test@mailcom";
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Invalid email format", exception.getMessage());
}

@Test
public void organizationTestWebsiteMissingHttps(){
testWebsite = "test.com";
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));

assertEquals("Website must start with http:// or https://", exception.getMessage());
}

/* Mangler exception når url mangler domain extension (.com f.eks)
@Test
public void organizationTestWebsiteMissingDot(){
testWebsite = "https://testcom";
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));
assertEquals("Website must start with http:// or https://", exception.getMessage());
}
*/

/* Mangler exception når website er null
@Test
public void organizationTestWebsiteMissingDot(){
testWebsite = null;
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified));
assertEquals("Website must start with http:// or https://", exception.getMessage());
}
*/



//Getter tests
@Test
public void organizationTestNameGet(){
Organization Organization = new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified);
assertEquals(testName, Organization.getName());
}

@Test
public void organizationTestOrgNrGet(){
Organization Organization = new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified);
assertEquals(testOrgNr, Organization.getOrgNr());
}

@Test
public void organizationTestCauseGet(){
Organization Organization = new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified);
assertEquals(testCause, Organization.getCause());
}

@Test
public void organizationDescriptionGet(){
Organization Organization = new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified);
assertEquals(testDescription, Organization.getDescription());
}

@Test
public void organizationTestContactEmailGet(){
Organization Organization = new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified);
assertEquals(testContactEmail, Organization.getContactEmail());
}

@Test
public void organizationTestWebsiteGet(){
Organization Organization = new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified);
assertEquals(testWebsite, Organization.getWebsite());
}

@Test
public void organizationTestIsVerifiedGet(){
Organization Organization = new Organization(testName, testOrgNr, testCause, testDescription, testContactEmail, testWebsite, testVerified);
assertEquals(testVerified, Organization.isVerified());
}
}
Loading