Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.demo;
- import static org.junit.Assert.assertEquals;
- import java.util.Optional;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.context.SpringBootTest;
- import org.springframework.test.context.junit4.SpringRunner;
- @RunWith(SpringRunner.class)
- @SpringBootTest
- public class DemoApplicationTests {
- @Autowired
- UserRepository userRepository;
- @Autowired
- ApplicationRepository applicationsRepository;
- @Test
- public void contextLoads() {
- }
- @Test
- public void testAddUser() {
- User user = new User("Calin", "Agronium", "pass123");
- int result1 = 0;
- userRepository.save(user);
- Iterable<User> users = userRepository.findAll();
- for (User usr : users) {
- if (usr.getUsername().equals(user.getUsername()))
- result1 = 1;
- }
- assertEquals(1, result1);
- }
- @Test
- public void testDeleteUser() {
- int id = 0;
- Iterable<User> users = userRepository.findAll();
- int result1 = 0;
- for (User usr : users) {
- result1++;
- id = usr.getIdentifier();
- }
- userRepository.deleteById(id);
- users = userRepository.findAll();
- int result2 = 0;
- for (User usr : users) {
- result2++;
- }
- assertEquals(result1 - 1, result2);
- }
- @Test
- public void testDeleteApp() {
- int id = 0;
- Iterable<Application> apps = applicationsRepository.findAll();
- int result1 = 0;
- for (Application aps : apps) {
- result1++;
- id = aps.getIdentifier();
- }
- applicationsRepository.deleteById(id);
- apps = applicationsRepository.findAll();
- int result2 = 0;
- for (Application aps : apps) {
- result2++;
- }
- assertEquals(result1 - 1, result2);
- }
- @Test
- public void testAddApp() {
- Application app = new Application("Eclipse", "Java", 11);
- int result1 = 0;
- Iterable<Application> apps = applicationsRepository.findAll();
- applicationsRepository.save(app);
- apps = applicationsRepository.findAll();
- for (Application aps : apps) {
- if (aps.getName().equals(app.getName()))
- result1 = 1;
- }
- applicationsRepository.save(app);
- assertEquals(1, result1);
- // try
- //
- // {
- // System.out.println();
- // } catch (Exception e) {
- //
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement