Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. package aspectexample;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4.  
  5. import org.junit.Test;
  6.  
  7. import aspects.CountInvokesAspect;
  8. import services.AdminService;
  9. import services.UserService;
  10. import usersManagment.User;
  11.  
  12. public class CountInvokesTest {
  13.  
  14.  
  15.     @Test
  16.     public void secondAspectTest() {
  17.  
  18.         UserService userService = new UserService();
  19.        
  20.         userService.addUser("jk","passjk","jk@gmail.com");
  21.         userService.addUser("jk","passjk","jk@gmail.com");
  22.         userService.addUser("jk","passjk","jk@gmail.com");
  23.         userService.addUser("jk","passjk","jk@gmail.com");
  24.        
  25.         assertEquals("wrong counting for userService and addUser",
  26.                 4, CountInvokesAspect.getNumberOfCalls(userService, "addUser"));
  27.        
  28.         UserService userService2 = new UserService();
  29.        
  30.         userService2.addUser("jk","passjk","jk@gmail.com");
  31.         userService2.addUser("jk","passjk","jk@gmail.com");
  32.        
  33.         assertEquals("wrong counting for userService2 and addUser",
  34.                 2, CountInvokesAspect.getNumberOfCalls(userService2, "addUser"));
  35.        
  36.         AdminService adminService = new AdminService();
  37.        
  38.         adminService.method1();
  39.         adminService.method1();
  40.         adminService.method3();
  41.         adminService.method5();
  42.         adminService.method5();
  43.         adminService.method5();
  44.         adminService.method5();
  45.              
  46.         assertEquals("wrong counting for adminService and method1",
  47.                 2, CountInvokesAspect.getNumberOfCalls(adminService, "method1"));
  48.        
  49.         assertEquals("wrong counting for adminService and method3",
  50.                 1, CountInvokesAspect.getNumberOfCalls(adminService, "method3"));
  51.        
  52.         assertEquals("wrong counting for adminService and method5",
  53.                 4, CountInvokesAspect.getNumberOfCalls(adminService, "method5"));
  54.     }
  55.    
  56.     @Test(expected = IllegalArgumentException.class)
  57.     public void firstAspectTest() {
  58.         User user = new User();
  59.         user.doSomething("sdasd", null, 1.5);
  60.     }
  61.        
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement