package persistent;

import models.User;
import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;

/**
 * Created by Ivan Sliusar on 05.07.2018.
 * Red Line Soft corp.
 */
public class PostgreUserStoreTest {
    final PostgreUserStore store = PostgreUserStore.getInstance();

    @Test
    public void add() throws Exception {
        User user = new User();
        user.setName("John");
        user.setEmail("john@gmail.com");
        this.store.add(user);
        assertThat(user,is(this.store.findById(user.getId())));

    }

    @Test
    public void update() throws Exception {
        User user = new User();
        user.setName("John");
        user.setEmail("john@gmail.com");
        this.store.add(user);
        user.setName("Mark");
        this.store.update(user);
        assertThat(user.getName(),is(this.store.findById(user.getId()).getName()));
    }

    @Test
    public void delete() throws Exception {
        User user = new User();
        user.setName("John");
        user.setEmail("john@gmail.com");
        this.store.add(user);

        this.store.delete(user);
        assertNull(this.store.findById(user.getId()));
    }

    @Test
    public void findAll() throws Exception {
        User user = new User();
        user.setName("John");
        user.setEmail("john@gmail.com");
        this.store.add(user);
        assertTrue(this.store.findAll().contains(user));
    }

    @Test
    public void findById() throws Exception {
        User user = new User();
        user.setName("John");
        user.setEmail("john@gmail.com");
        this.store.add(user);
        assertThat(user.getId(),is(this.store.findById(user.getId()).getId()));
    }

    @Test
    public void findByEmail() throws Exception {
        User user = new User();
        user.setName("John");
        user.setEmail("john@gmail.com");
        this.store.add(user);
        assertThat(user.getEmail(),is(this.store.findById(user.getId()).getEmail()));
    }

}
@@ -34,16 +34,41 @@
 s.User;%0A
+import org.junit.Before;%0A
 import o
@@ -337,57 +337,67 @@
 ();%0A
-%0A    @Test%0A    public void add() throws Exception
+    private User user;%0A%0A    @Before%0A    public void setUp()
  %7B%0A 
@@ -395,37 +395,32 @@
 tUp() %7B%0A        
-User 
 user = new User(
@@ -485,32 +485,90 @@
 hn@gmail.com%22);%0A
+    %7D%0A%0A    @Test%0A    public void add() throws Exception %7B%0A
         this.sto
@@ -605,16 +605,17 @@
 at(user,
+ 
 is(this.
@@ -646,17 +646,16 @@
 d())));%0A
-%0A
     %7D%0A%0A 
@@ -711,111 +711,8 @@
 n %7B%0A
-        User user = new User();%0A        user.setName(%22John%22);%0A        user.setEmail(%22john@gmail.com%22);%0A
     
@@ -834,16 +834,17 @@
 tName(),
+ 
 is(this.
@@ -950,111 +950,8 @@
 n %7B%0A
-        User user = new User();%0A        user.setName(%22John%22);%0A        user.setEmail(%22john@gmail.com%22);%0A
     
@@ -976,17 +976,16 @@
 (user);%0A
-%0A
         
@@ -1130,111 +1130,8 @@
 n %7B%0A
-        User user = new User();%0A        user.setName(%22John%22);%0A        user.setEmail(%22john@gmail.com%22);%0A
     
@@ -1280,111 +1280,8 @@
 n %7B%0A
-        User user = new User();%0A        user.setName(%22John%22);%0A        user.setEmail(%22john@gmail.com%22);%0A
     
@@ -1338,16 +1338,17 @@
 getId(),
+ 
 is(this.
@@ -1457,111 +1457,8 @@
 n %7B%0A
-        User user = new User();%0A        user.setName(%22John%22);%0A        user.setEmail(%22john@gmail.com%22);%0A
     
@@ -1518,16 +1518,17 @@
 Email(),
+ 
 is(this.

Добавить интеграционные тесты для площадок машин. [#4746] fix