package br.edu.ufcg.computacao.si1.service;

import br.edu.ufcg.computacao.si1.model.usuario.Usuario;
import br.edu.ufcg.computacao.si1.model.usuario.UsuarioEmpresa;
import br.edu.ufcg.computacao.si1.model.usuario.UsuarioPessoa;
import br.edu.ufcg.computacao.si1.repository.UsuarioRepository;
import org.junit.After;
import org.junit.Before;
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;

import java.util.Random;
import java.util.UUID;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;

/**
 * Created by gabriel on 08/03/17.
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class UsuarioTest {

    @Autowired
    private UsuarioRepository repo;

    private Usuario user1, user2;

    @Before
    public void setUp(){
        this.user1 = new UsuarioEmpresa("Belzebu", "sata@hell.com", "fire");
        this.user2 = new UsuarioPessoa("Gretchen", "gretchen@conga.com", "calabok");
    }

    @After
    public void tearDown() {
        repo.deleteAll();
    }

    @Test
    public void testInicializacao() {
        assertNotNull("Usuario1 não foi instânciado corretamente", user1);
        assertNotNull("Usuario2 não foi instânciado corretamente", user2);
    }

    @Test
    public void testPersistance(){
        Random r = new Random();
        int rand = r.nextInt(200);
        int i = rand;
        while(i>0){
            this.repo.save(new UsuarioEmpresa(UUID.randomUUID().toString(), UUID.randomUUID().toString()
                                        ,UUID.randomUUID().toString()));
            i--;
        }
        assertEquals(repo.count(), rand);
    }



}

@@ -1464,32 +1464,34 @@
  user2);%0A    %7D%0A%0A
+//
     @Test%0A    pu
@@ -1476,32 +1476,34 @@
  %7D%0A%0A//    @Test%0A
+//
     public void 
@@ -1517,24 +1517,26 @@
 sistance()%7B%0A
+//
         Rand
@@ -1552,24 +1552,26 @@
 w Random();%0A
+//
         int 
@@ -1593,16 +1593,18 @@
 t(200);%0A
+//
         
@@ -1617,16 +1617,18 @@
 = rand;%0A
+//
         
@@ -1639,16 +1639,18 @@
 e(i%3E0)%7B%0A
+//
         
@@ -1746,16 +1746,18 @@
 tring()%0A
+//
         
@@ -1821,16 +1821,18 @@
 ng()));%0A
+//
         
@@ -1840,16 +1840,18 @@
    i--;%0A
+//
         
@@ -1852,16 +1852,18 @@
       %7D%0A
+//
         
@@ -1900,15 +1900,14 @@
 d);%0A
+//
     %7D%0A
-%0A%0A%0A
 %7D%0A

Fix tests to build pass