Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ap;
- import org.testng.annotations.DataProvider;
- import org.testng.annotations.Test;
- import static org.testng.Assert.*;
- @Test
- public class TestClient {
- @Test(dataProvider = "getConstructorData")
- public void testClientConstructor(String name, int nif, String expectedName, int expectedNif) {
- //Act
- Client client = new Client(name, nif, 0);
- //Assert
- assertEquals(client.getName(), name);
- // assertEquals(client.,name); aqui o assert do nif mas com que metodo?????
- }
- @Test(expectedExceptions = InvalidOperationException.class)
- public void testClientNumberSizeLessThanZeroShouldThrowInvalidOperationException() throws InvalidOperationException {
- //Arrange
- String name = "1234567890";
- int nif = 100000003;
- Client client = new Client(name, nif, 0);// ask: é considerado arrange??
- //Act
- client.removePhoneNumber(0);
- }
- public void testClientNumberSizeShouldBeBiggerThanZero() {
- //Arrange
- String name = "12345678901";
- int nif = 100000004;
- //Act
- Client client = new Client(name, nif, 0);
- //Assert
- assertTrue(client.getPhoneNumbers().size() > 0);
- }
- public void testClientNumberSizeShouldBeEqualToFive() throws InvalidOperationException {
- //Arrange
- String name = "123456789012";
- int nif = 100000005;
- Client client = new Client(name, nif, 0);
- //Act
- for (int i = 1; i < 5; i++) {
- client.addPhoneNumber(i);
- }
- //Assert
- assertTrue(client.getPhoneNumbers().size() == 5);
- }
- @Test(expectedExceptions = InvalidOperationException.class)
- public void testClientNumberSizeShouldNotBeMoreThanFive() throws InvalidOperationException {
- //Arrange
- String name = "1234567890123";
- int nif = 100000006;
- Client client = new Client(name, nif, 0);
- //Act
- for (int i = 1; i < 6; i++) {
- client.addPhoneNumber(i);
- }
- }
- @Test(expectedExceptions = InvalidOperationException.class)
- public void testClientMobilePhonesShouldNotBeMoreThanNumberOfNumbers() throws InvalidOperationException {
- //Arrange
- String name = "123456789012345";
- int nif = 10000008;
- Client client = new Client(name, nif, 0);
- for (int i = 1; i < 5; i++) {
- client.addPhoneNumber(i);
- }
- //Act
- for (int i = 0; i < 6; i++) {
- client.registerMobile(i);
- }
- }
- @Test(expectedExceptions = InvalidNumberPhoneException.class)
- public void testClientFriendsShouldNotBeMoreThanThreeTimesNumberOfNumbersPlusFive() throws InvalidNumberPhoneException, InvalidOperationException {
- //Arrange
- String name = "123456789012";
- int nif = 100000005;
- Client client = new Client(name, nif, 0);
- for (int i = 1; i < 5; i++) {
- client.addPhoneNumber(i);
- }
- //Act
- for (int i = 0; i < client.getPhoneNumbers().size() * 3 + 5 + 1; i++) {
- client.addFriend(i);
- }
- }
- @DataProvider
- private Object[][] getConstructorData() {
- return new Object[][]{
- {"12345", 100000001, "12345", 100000001},
- {"1234", 100000002, null, 100000002},
- {"123456", 99999999, "123456", 0},
- {"1234567", 100000000, "1234567", 100000000},
- {"12345678", 1000000000, "12345678", 0},
- {"123456789", 999999999, "123456789", 999999999}
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement