diff --git a/build.gradle b/build.gradle index 333280458bd488e56e0a81a7acd4fcfc5ec7513c..5689fe1a8341e25be401b65483d5803bbb85a46c 100644 --- a/build.gradle +++ b/build.gradle @@ -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() +} + diff --git a/src/main/java/Team5/SmartTowns/Data/Location.java b/src/main/java/Team5/SmartTowns/Data/Location.java index cf9e69645f80f10116cdcc6a7b428c622e619c91..7ec4ede38d187bb5b6a667662b7cf7241661defe 100644 --- a/src/main/java/Team5/SmartTowns/Data/Location.java +++ b/src/main/java/Team5/SmartTowns/Data/Location.java @@ -50,4 +50,9 @@ public class Location { } + + public int testMe(){ + int a=4; + return 4; + } } diff --git a/src/test/java/Team5/SmartTowns/CalculatorTest.java b/src/test/java/Team5/SmartTowns/CalculatorTest.java index 49fc027fbba95aa0a072759a0ad86995dc79e824..1aea1c6ac81241ecd401b728217b416d615e2d1b 100644 --- a/src/test/java/Team5/SmartTowns/CalculatorTest.java +++ b/src/test/java/Team5/SmartTowns/CalculatorTest.java @@ -1,53 +1,53 @@ -//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)); + } + + + + +} diff --git a/src/test/java/Team5/SmartTowns/Data/LocationTest.java b/src/test/java/Team5/SmartTowns/Data/LocationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..3607963a152f412345ceaa0bf90908940edd74e4 --- /dev/null +++ b/src/test/java/Team5/SmartTowns/Data/LocationTest.java @@ -0,0 +1,7 @@ +package Team5.SmartTowns.Data; + +import static org.junit.jupiter.api.Assertions.*; + +class LocationTest { + +} \ No newline at end of file diff --git a/src/test/java/Team5/SmartTowns/Data/locationRepositoryJDBCTest.java b/src/test/java/Team5/SmartTowns/Data/locationRepositoryJDBCTest.java new file mode 100644 index 0000000000000000000000000000000000000000..29564125d79044a2b7b30ed9731a82ea80675b68 --- /dev/null +++ b/src/test/java/Team5/SmartTowns/Data/locationRepositoryJDBCTest.java @@ -0,0 +1,46 @@ +//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 diff --git a/src/test/java/Team5/SmartTowns/Test5.java b/src/test/java/Team5/SmartTowns/Test5.java index a5a518e542a11662c5863dc0cc12a11d0bdc4984..4ea4af12de0eb1e1dbe9f5dff8b9d2778d711d50 100644 --- a/src/test/java/Team5/SmartTowns/Test5.java +++ b/src/test/java/Team5/SmartTowns/Test5.java @@ -1,5 +1,6 @@ //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)); // // } // diff --git a/src/test/java/Team5/SmartTowns/Test6Mock.java b/src/test/java/Team5/SmartTowns/Test6Mock.java new file mode 100644 index 0000000000000000000000000000000000000000..f84b318f0b48c850a66ed1f3f6836914f5dee955 --- /dev/null +++ b/src/test/java/Team5/SmartTowns/Test6Mock.java @@ -0,0 +1,79 @@ +//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()); +// +// } +// } +//