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

Further testing of tests. Issues with calling JDBC databse to a test environment

parent 518c6b09
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"
......@@ -37,12 +37,12 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
// https://mvnrepository.com/artifact/org.springframework/spring-dao
// implementation group: 'org.springframework', name: 'spring-tx', version: '6.1.1'
implementation 'org.springframework:spring-dao:2.0.8'
// implementation 'org.springframework:spring-dao:2.0.8'
// implementation 'org.springframework.dao.DataAccessException'
// https://mvnrepository.com/artifact/org.springframework/spring-core
implementation 'org.springframework:spring-core:6.0.6'
implementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.1'
implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.0.1'
// implementation 'org.springframework:spring-core:6.0.6'
// implementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.1'
// implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.0.1'
//Thanks for using https://jar-download.com
......@@ -58,3 +58,7 @@ tasks.named('test') {
useJUnitPlatform()
}
tasks.named('test') {
Test6Mock()
}
......@@ -50,4 +50,9 @@ public class Location {
}
public int testMe(){
int a=4;
return 4;
}
}
//package Team5.SmartTowns;
//
//import Team5.SmartTowns.Data.Calculator;
//import org.junit.jupiter.api.BeforeAll;
//import org.junit.jupiter.api.Test;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.core.NestedRuntimeException;
////import org.springframework.dao.DataAccessException;
//
//import static org.junit.jupiter.api.Assertions.assertEquals;
//import static org.junit.jupiter.api.Assertions.assertThrows;
//import org.junit.platform.engine.TestDescriptor;
package Team5.SmartTowns;
import Team5.SmartTowns.Data.Calculator;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.NestedRuntimeException;
//import org.springframework.dao.DataAccessException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.platform.engine.TestDescriptor;
//import org.junit.platform.commons.util.Preconditions;
//import org.apache.commons.logging.LogFactory;
//@SpringBootTest
//public class CalculatorTest {
//// String asd= getLegacyReportingName("das");
//
// private static Calculator calculator;
//
// @BeforeAll
// public static void before() {
// calculator = new Calculator();
// }
//
// @Test
// public void whenDivideNumbersThenReturnDivision() {
//
// assertEquals(2, calculator.divide(4, 2));
// }
//
// @Test
// public void whenDivideByZeroThenThrowException() {
// assertThrows(ArithmeticException.class, () -> calculator.divide(1, 0));
// }
// @Test
// public void whenAddingThingsThenAdd(){
// assertEquals(10,calculator.add(6,4));
// }
// @Test
// public void whenSubtractingThingsThenSubtract(){
// assertEquals(-5,calculator.subtract(5,10));
// }
//
// @Test
// public void whenMultiplyingThingsThenMultiply(){
// assertEquals(-60,calculator.multiply(-3,20));
// }
//
//
//
//
//}
import org.apache.commons.logging.LogFactory;
@SpringBootTest
public class CalculatorTest {
// String asd= getLegacyReportingName("das");
private static Calculator calculator;
@BeforeAll
public static void before() {
calculator = new Calculator();
}
@Test
public void whenDivideNumbersThenReturnDivision() {
assertEquals(2, calculator.divide(4, 2));
}
@Test
public void whenDivideByZeroThenThrowException() {
assertThrows(ArithmeticException.class, () -> calculator.divide(1, 0));
}
@Test
public void whenAddingThingsThenAdd(){
assertEquals(10,calculator.add(6,4));
}
@Test
public void whenSubtractingThingsThenSubtract(){
assertEquals(-5,calculator.subtract(5,10));
}
@Test
public void whenMultiplyingThingsThenMultiply(){
assertEquals(-60,calculator.multiply(-3,20));
}
}
package Team5.SmartTowns.Data;
import static org.junit.jupiter.api.Assertions.*;
class LocationTest {
}
\ No newline at end of file
//package Team5.SmartTowns.Data;
//
//import org.junit.jupiter.api.BeforeAll;
//import org.junit.jupiter.api.Test;
//import org.mockito.Mock;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.jdbc.core.JdbcTemplate;
//
//import java.util.List;
//
//import static org.junit.jupiter.api.Assertions.*;
//// create lists of sql data todo
//@SpringBootTest
//class locationRepositoryJDBCTest {
//
//private static locationRepository locationRepo;
//
//
// @Autowired
// private locationRepository locationRepo;
//
// @Mock
// private JdbcTemplate jdbc;
//@BeforeAll
//public static void setup(){
// locationRepositoryJDBC aa= new locationRepositoryJDBC(jdbc);
//}
// @Test
// void getAllLocation() {
// List<Location> locations= locationRepo.getAllLocation();
// int preAdd = locations.size();
// Location loc = new Location("House","House@Bricks","Description Here","Caerphilly",103);
// locationRepo.addLocation(loc);
// int postAdd = locationRepo.getAllLocation().size();
// assertEquals(1,(postAdd-preAdd));
// }
//
// @Test
// void addLocation() {
// }
//
// @Test
// void setJdbc() {
// }
//}
\ No newline at end of file
//package Team5.SmartTowns;
//
//import Team5.SmartTowns.Data.locationRepository;
//import Team5.SmartTowns.Data.locationRepositoryJDBC;
////import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,21 +14,23 @@
//import static org.testng.Assert.assertEquals;
//
//@SpringBootTest
//@JdbcTest
//
//@Sql({"schema.sql", "data.sql"})
////@JdbcTest
////
//@Sql({"schema.sql", "test-data.sql"})
//public class Test5 {
//
// @Autowired
// private JdbcTemplate ajdbc;
// private locationRepository locationRepo;
//
//
// @Test
//// test 1
// void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount() {
// locationRepositoryJDBC employeeDAO = new locationRepositoryJDBC(ajdbc);
//// locationRepositoryJDBC employeeDAO = new locationRepositoryJDBC(ajdbc);
// int aa=2;
// int bb=2;
//// employeeDAO.setJdbc(ajdbc);
// assertEquals(4, employeeDAO.getAllLocation().size());
// assertEquals(4, (aa+bb));
//
// }
//
......
//package Team5.SmartTowns;
//
//import Team5.SmartTowns.Data.Location;
//import Team5.SmartTowns.Data.locationRepository;
//import Team5.SmartTowns.Data.locationRepositoryJDBC;
//import org.junit.Before;
////import org.junit.runner.RunWith;
////import org.mockito.Mockito;
////import org.mockito.internal.invocation.InvocationsFinder;
//import org.junit.jupiter.api.BeforeAll;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.boot.test.context.TestConfiguration;
//
//import org.springframework.boot.test.mock.mockito.MockBean;
//import org.springframework.context.annotation.Bean;
//import org.springframework.jdbc.core.JdbcTemplate;
////import org.springframework.test.context.junit4.SpringRunner;
//import org.testng.annotations.Test;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import static org.testng.AssertJUnit.assertEquals;
//
////@RunWith(SpringRunner.class)
//@SpringBootTest
//public class Test6Mock {
//
// @TestConfiguration
// static class EmployeeServiceImplTestContextConfiguration {
//
// @Bean
// public Location location() {
// return new Location();
// }
// }
//
//
// @Autowired
// private locationRepository locationRepo;
// @Autowired
// private locationRepositoryJDBC locationRepoJ;
//
//
// @MockBean
// private JdbcTemplate jdbc;
//
//
// @BeforeAll
// public static void setUp() {
// locationRepository locationRepository= new locationRepository() {
// @Override
// public List<Location> getAllLocation() {
// return null;
// }
//
// @Override
// public void addLocation(Location loc) {
//
// }
// };
//
//// Location alex = new Location("House","House@Bricks","Description Here","Caerphilly",103);
////
//// Mockito.when(locationRepository.getAllLocation())
//// .thenReturn(locationRepository.getAllLocation());
// }
//
//
// @Test
// public void whenValidName_thenEmployeeShouldBeFound() {
// locationRepositoryJDBC s= new locationRepositoryJDBC(jdbc);
// List<Location> locations = locationRepository.getAllLocation();
// assertEquals(18,locations.size());
//
// }
// }
//
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment