Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/unit tests #147

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"ghcr.io/devcontainers-contrib/features/angular-cli:2": {}

},
"customizations": {
"vscode": {
"extensions": [
"ryanluker.vscode-coverage-gutters"
]
}
},
//"customizations": {
//"vscode": {
//"extensions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class CestaControllerTest {

@Mock
private CestaServiceI CestaServiceI;
private CestaServiceI cestaServiceI;

@InjectMocks
private CestaController cestaController;
Expand All @@ -39,7 +39,7 @@ private void recuperaCestaPorIdUsuarioTest() {
public void testRecuperaCestaPorIdUsuario() {
Long idUsuario = 1L;
Cesta cesta = new Cesta(); // crea una cesta ficticia para el test
when(CestaServiceI.buscarCestaPorUsuarioId(idUsuario)).thenReturn(cesta);
when(cestaServiceI.buscarCestaPorUsuarioId(idUsuario)).thenReturn(cesta);
Cesta resultado = cestaController.recuperaCestaPorIdUsuario(idUsuario);
assertEquals(cesta, resultado);

Expand All @@ -49,7 +49,7 @@ public void testRecuperaCestaPorIdUsuario() {
public void testActualizaCesta() {
Cesta cesta = newCestabyRandom(); // crea una cesta ficticia para el test
CestaEntity cestaEntity= CestaMapper.mapToCestaEntityFromCesta(cesta);
when(CestaServiceI.actualizaCesta(Mockito.any(CestaEntity.class)))
when(cestaServiceI.actualizaCesta(Mockito.any(CestaEntity.class)))
.thenReturn(cestaEntity);
Cesta response = cestaController.actualizaCesta(cesta);
assertEquals(cestaEntity, response);
Expand All @@ -60,12 +60,20 @@ public void testActualizaCesta() {
public void testListaCestas() {
List<CestaEntity> listCestasEntity= new ArrayList<>();
listCestasEntity = createListCestaEntitiesByRandom();
when(CestaServiceI.listaCestas()).thenReturn(listCestasEntity);
when(cestaServiceI.listaCestas()).thenReturn(listCestasEntity);
List<Cesta> resultado = cestaController.listaCestas();
assertEquals(listCestasEntity, resultado);

}

@Test
public void recuperaCestaPorIdUsuarioEliminandoTest(){
doNothing().when(cestaServiceI).eliminaCesta(Mockito.any(CestaEntity.class));
cestaController.recuperaCestaPorIdUsuario(newCestabyRandom());
}



private Cesta newCestabyRandom (){
Cesta cesta = new Cesta();
cesta.setId(1L);
Expand Down
Loading