diff --git a/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java b/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java index 68a585a4a58322490600f41ccb5b33502fee4622..67932b978cdb52ee102e89e082d55a45db411a60 100644 --- a/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java +++ b/src/test/java/Team5/SmartTowns/SmartTownsApplicationTests.java @@ -3,35 +3,57 @@ package Team5.SmartTowns; import Team5.SmartTowns.Data.Location; import Team5.SmartTowns.Data.Town; import Team5.SmartTowns.Data.TownRepository; +import Team5.SmartTowns.Data.locationRepositoryJDBC; import Team5.SmartTowns.Towns.TownController; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.util.ReflectionTestUtils; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.mockito.Mockito.mock; @SpringBootTest +@JdbcTest +@Sql({"schema.sql", "data.sql"}) class SmartTownsApplicationTests { private static TownController townController; - @Autowired - private Team5.SmartTowns.Data.locationRepository locationRepository; - private Team5.SmartTowns.Data.Location location; + private static Team5.SmartTowns.Data.Location location; +// @Mock +// private static JdbcTemplate jdbc; + + @Autowired + private Team5.SmartTowns.Data.locationRepository locationRepo; + JdbcTemplate jdbc = Mockito.mock(JdbcTemplate.class); @Autowired - private Team5.SmartTowns.Data.TownRepository townRepository; + private static Team5.SmartTowns.Data.TownRepository townRepository; + + + private static Team5.SmartTowns.Data.Location town; + private static RowMapper<Location> locationMapper; - private Team5.SmartTowns.Data.Location town; @BeforeAll - public static void before() { - locationRepositroy = new location.locationRepository(); + public void before() { +// MockitoAnnotations.initMocks(this); + location = new Location(); + locationRepo = mock(new locationRepositoryJDBC(jdbc)); + townController = new TownController(); } // @BeforeAll // public static void before(){} @@ -44,12 +66,13 @@ class SmartTownsApplicationTests { @Test public void whenFilteringTownsByLocationsReturnOneTown() { - List<Location> allLocations = locationRepository.getAllLocation(); + List<Location> allLocations = ( locationRepo.getAllLocation()); List<Town> allTowns = townRepository.getAllTowns(); int allLocationNumber=allLocations.size(); int allLocationNumberAfterFilter=0; for (Town town : allTowns){ - allLocationNumberAfterFilter+=townController.filterByLocationForTrails(allLocations,town.getTownName()).size(); + allLocationNumberAfterFilter+=townController.filterByLocationForTrails(allLocations, + town.getTownName()).size(); } assertSame(allLocationNumber,allLocationNumberAfterFilter); /// list of all locations,