Advertisement
Guest User

Untitled

a guest
May 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. package com.example.demo;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4.  
  5. import java.util.Optional;
  6.  
  7. import org.junit.Test;
  8. import org.junit.runner.RunWith;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.boot.test.context.SpringBootTest;
  11. import org.springframework.test.context.junit4.SpringRunner;
  12.  
  13. @RunWith(SpringRunner.class)
  14. @SpringBootTest
  15. public class DemoApplicationTests {
  16.  
  17. @Autowired
  18. UserRepository userRepository;
  19. @Autowired
  20. ApplicationRepository applicationsRepository;
  21.  
  22. @Test
  23. public void contextLoads() {
  24. }
  25.  
  26. @Test
  27. public void testAddUser() {
  28. User user = new User("Calin", "Agronium", "pass123");
  29. int result1 = 0;
  30. userRepository.save(user);
  31. Iterable<User> users = userRepository.findAll();
  32. for (User usr : users) {
  33. if (usr.getUsername().equals(user.getUsername()))
  34. result1 = 1;
  35. }
  36. assertEquals(1, result1);
  37. }
  38.  
  39. @Test
  40. public void testDeleteUser() {
  41. int id = 0;
  42. Iterable<User> users = userRepository.findAll();
  43. int result1 = 0;
  44. for (User usr : users) {
  45. result1++;
  46. id = usr.getIdentifier();
  47. }
  48. userRepository.deleteById(id);
  49. users = userRepository.findAll();
  50. int result2 = 0;
  51. for (User usr : users) {
  52. result2++;
  53. }
  54. assertEquals(result1 - 1, result2);
  55. }
  56.  
  57. @Test
  58. public void testDeleteApp() {
  59. int id = 0;
  60. Iterable<Application> apps = applicationsRepository.findAll();
  61. int result1 = 0;
  62. for (Application aps : apps) {
  63. result1++;
  64. id = aps.getIdentifier();
  65. }
  66. applicationsRepository.deleteById(id);
  67. apps = applicationsRepository.findAll();
  68. int result2 = 0;
  69. for (Application aps : apps) {
  70. result2++;
  71. }
  72. assertEquals(result1 - 1, result2);
  73. }
  74.  
  75. @Test
  76. public void testAddApp() {
  77. Application app = new Application("Eclipse", "Java", 11);
  78. int result1 = 0;
  79. Iterable<Application> apps = applicationsRepository.findAll();
  80. applicationsRepository.save(app);
  81. apps = applicationsRepository.findAll();
  82. for (Application aps : apps) {
  83. if (aps.getName().equals(app.getName()))
  84. result1 = 1;
  85. }
  86. applicationsRepository.save(app);
  87. assertEquals(1, result1);
  88.  
  89. // try
  90. //
  91. // {
  92. // System.out.println();
  93. // } catch (Exception e) {
  94. //
  95. // }
  96. }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement