forked from algaworks/curso-testes-unitarios-junit-projeto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from leco123/MODULO-3
Modulo 3
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/test/java/com/algaworks/junit/blog/negocio/ArmazenamentoEditorFixoEmMemoria.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.algaworks.junit.blog.negocio; | ||
|
||
import com.algaworks.junit.blog.armazenamento.ArmazenamentoEditor; | ||
import com.algaworks.junit.blog.modelo.Editor; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static java.util.Objects.isNull; | ||
|
||
/** | ||
* Implementação Sub, ou seja, Duble, ficticia | ||
*/ | ||
public class ArmazenamentoEditorFixoEmMemoria implements ArmazenamentoEditor { | ||
|
||
@Override | ||
public Editor salvar(Editor editor) { | ||
if (isNull(editor)) { | ||
editor.setId(1L); | ||
} | ||
return editor; | ||
} | ||
|
||
@Override | ||
public Optional<Editor> encontrarPorId(Long editor) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<Editor> encontrarPorEmail(String email) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<Editor> encontrarPorEmailComIdDiferenteDe(String email, Long id) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public void remover(Long editorId) { | ||
|
||
} | ||
|
||
@Override | ||
public List<Editor> encontrarTodos() { | ||
return null; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/java/com/algaworks/junit/blog/negocio/CadastroEditorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.algaworks.junit.blog.negocio; | ||
|
||
import com.algaworks.junit.blog.modelo.Editor; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
|
||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
class CadastroEditorTest { | ||
|
||
static CadastroEditor cadastroEditor; | ||
Editor editor; | ||
|
||
//Executa antes de todos os testes | ||
@BeforeAll | ||
static void beforeAll() { | ||
|
||
System.out.println("@BeforeAll: Antes de todos os testes"); | ||
|
||
cadastroEditor = new CadastroEditor( | ||
new ArmazenamentoEditorFixoEmMemoria(), | ||
new GerenciadorEnvioEmail() { | ||
|
||
@Override | ||
void enviarEmail(Mensagem mensagem) { | ||
System.out.println("Enviando mensagem para: "+mensagem.getDestinatario()); | ||
} | ||
} | ||
); | ||
} | ||
|
||
// Preparar as variáveis para o senário de teste; | ||
@BeforeEach | ||
void beforeEach() { | ||
|
||
// [A]rrange: Preparar as variáveis para o senário de teste; | ||
System.out.println("@BeforeEach: Executa antes de cada teste"); | ||
|
||
editor = new Editor(); | ||
} | ||
|
||
} |