Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.68 KB | None | 0 0
  1. package ap;
  2.  
  3. import org.testng.annotations.DataProvider;
  4. import org.testng.annotations.Test;
  5.  
  6. import static org.testng.Assert.*;
  7.  
  8. @Test
  9. public class TestClient {
  10.  
  11.  
  12.     @Test(dataProvider = "getConstructorData")
  13.     public void testClientConstructor(String name, int nif, String expectedName, int expectedNif) {
  14.  
  15.         //Act
  16.         Client client = new Client(name, nif, 0);
  17.  
  18.         //Assert
  19.         assertEquals(client.getName(), name);
  20.         //  assertEquals(client.,name); aqui o assert do nif mas com que metodo?????
  21.  
  22.  
  23.     }
  24.  
  25.     @Test(expectedExceptions = InvalidOperationException.class)
  26.     public void testClientNumberSizeLessThanZeroShouldThrowInvalidOperationException() throws InvalidOperationException {
  27.  
  28.         //Arrange
  29.         String name = "1234567890";
  30.         int nif = 100000003;
  31.         Client client = new Client(name, nif, 0);// ask: é considerado arrange??
  32.  
  33.         //Act
  34.         client.removePhoneNumber(0);
  35.  
  36.     }
  37.  
  38.  
  39.     public void testClientNumberSizeShouldBeBiggerThanZero() {
  40.  
  41.         //Arrange
  42.         String name = "12345678901";
  43.         int nif = 100000004;
  44.  
  45.         //Act
  46.         Client client = new Client(name, nif, 0);
  47.  
  48.         //Assert
  49.         assertTrue(client.getPhoneNumbers().size() > 0);
  50.  
  51.     }
  52.  
  53.  
  54.     public void testClientNumberSizeShouldBeEqualToFive() throws InvalidOperationException {
  55.  
  56.         //Arrange
  57.         String name = "123456789012";
  58.         int nif = 100000005;
  59.         Client client = new Client(name, nif, 0);
  60.  
  61.         //Act
  62.         for (int i = 1; i < 5; i++) {
  63.             client.addPhoneNumber(i);
  64.         }
  65.  
  66.         //Assert
  67.         assertTrue(client.getPhoneNumbers().size() == 5);
  68.  
  69.     }
  70.  
  71.  
  72.     @Test(expectedExceptions = InvalidOperationException.class)
  73.     public void testClientNumberSizeShouldNotBeMoreThanFive() throws InvalidOperationException {
  74.  
  75.         //Arrange
  76.         String name = "1234567890123";
  77.         int nif = 100000006;
  78.         Client client = new Client(name, nif, 0);
  79.  
  80.         //Act
  81.         for (int i = 1; i < 6; i++) {
  82.             client.addPhoneNumber(i);
  83.         }
  84.  
  85.     }
  86.  
  87.     @Test(expectedExceptions = InvalidOperationException.class)
  88.     public void testClientMobilePhonesShouldNotBeMoreThanNumberOfNumbers() throws InvalidOperationException {
  89.  
  90.         //Arrange
  91.         String name = "123456789012345";
  92.         int nif = 10000008;
  93.         Client client = new Client(name, nif, 0);
  94.  
  95.         for (int i = 1; i < 5; i++) {
  96.             client.addPhoneNumber(i);
  97.         }
  98.  
  99.         //Act
  100.  
  101.         for (int i = 0; i < 6; i++) {
  102.             client.registerMobile(i);
  103.         }
  104.  
  105.     }
  106.  
  107.     @Test(expectedExceptions = InvalidNumberPhoneException.class)
  108.     public void testClientFriendsShouldNotBeMoreThanThreeTimesNumberOfNumbersPlusFive() throws InvalidNumberPhoneException, InvalidOperationException {
  109.  
  110.         //Arrange
  111.         String name = "123456789012";
  112.         int nif = 100000005;
  113.         Client client = new Client(name, nif, 0);
  114.  
  115.         for (int i = 1; i < 5; i++) {
  116.             client.addPhoneNumber(i);
  117.         }
  118.  
  119.         //Act
  120.         for (int i = 0; i < client.getPhoneNumbers().size() * 3 + 5 + 1; i++) {
  121.             client.addFriend(i);
  122.         }
  123.  
  124.     }
  125.  
  126.  
  127.     @DataProvider
  128.     private Object[][] getConstructorData() {
  129.         return new Object[][]{
  130.                 {"12345", 100000001, "12345", 100000001},
  131.                 {"1234", 100000002, null, 100000002},
  132.                 {"123456", 99999999, "123456", 0},
  133.                 {"1234567", 100000000, "1234567", 100000000},
  134.                 {"12345678", 1000000000, "12345678", 0},
  135.                 {"123456789", 999999999, "123456789", 999999999}
  136.         };
  137.     }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement