Skip to content
Snippets Groups Projects
Commit e321e10b authored by Rhys Evans's avatar Rhys Evans
Browse files

Further work on getting JUnit test to work

parent 545d2602
No related branches found
No related tags found
1 merge request!34Resolve "As a user, I would like a town specific page which shows all trails for that town so that I can easily see my progress"
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment