Skip to content

Instantly share code, notes, and snippets.

@FranckSilvestre
Created May 22, 2024 14:50
Show Gist options
  • Save FranckSilvestre/21a575ff0da1eabb40df5fb63b31ae8e to your computer and use it in GitHub Desktop.
Save FranckSilvestre/21a575ff0da1eabb40df5fb63b31ae8e to your computer and use it in GitHub Desktop.
OurBusinessProject BUT3 2024
package ourbusinessproject;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(MockitoExtension.class)
public class PartnershipTest {
private Validator validator;
@Mock
private Project project;
@Mock
private Enterprise enterprise;
private Partnership partnership;
@BeforeEach
public void setUp() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
partnership = new Partnership();
partnership.setCreationDate(new Date());
partnership.setEnterprise(enterprise);
partnership.setProject(project);
}
@Test
public void testValidPartnershipValidation() {
// given a valid partnership
// expect validating the partnership instance returns no constraints violation
assertTrue(validator.validate(partnership).isEmpty());
}
@Test
public void testPartnerShipWithNoDateSetIsInvalid() {
// given a partnership without creation date set
partnership.setCreationDate(null);
// expect validating the partnership instance returns constraint violation
assertFalse(validator.validate(partnership).isEmpty());
}
@Test
public void testPartnerShipWithNoEnterpriseIsInvalid() {
// given a partnership without enterprise
partnership.setEnterprise(null);
// expect validating the partnership instance returns constraint violation
assertFalse(validator.validate(partnership).isEmpty());
}
@Test
public void testPartnerShipWithNoProjectIsInvalid() {
// given a partnership without project
partnership.setProject(null);
// expect validating the partnership instance returns constraint violation
assertFalse(validator.validate(partnership).isEmpty());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment