Skip to content

Commit

Permalink
Merge pull request #147 from rpuigm/feature/UnitTests
Browse files Browse the repository at this point in the history
Feature/unit tests
  • Loading branch information
rpuigm authored Feb 16, 2024
2 parents cd95d69 + c052fc9 commit 69d51e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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

0 comments on commit 69d51e6

Please sign in to comment.