Commit 8f1dc59d authored by Nabhan Abdulla's avatar Nabhan Abdulla
Browse files

Reset to stubs

parent 9bf45107
No preview for this file type
No preview for this file type
No preview for this file type
package project;
import java.io.File;
import java.io.FileNotFoundException;
import java.text.StringCharacterIterator;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
......@@ -12,7 +9,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class AdHandler {
......@@ -54,7 +50,12 @@ public class AdHandler {
}
AdData adData = new AdData(description, type, seller, LocalDateTime.now());
this.allAdsList.add(adData);
List<AdData> list = new ArrayList<>();
list.add(adData);
this.allAdsList = list;
// this.allAdsList.add(adData);
}
public void addNewMeeting(int adId, String meetingTime, String customerName) {
......@@ -70,33 +71,37 @@ public class AdHandler {
}
}
// public boolean isValidMeetingTime(LocalTime timeToCheck) {
// // * - For meetings hours: 10AM - 12PM, 2PM-3PM, 6PM-8PM
public boolean isValidMeetingTime(LocalTime timeToCheck) {
// * - For meetings hours: 10AM - 12PM, 2PM-3PM, 6PM-8PM
// if (timeToCheck.isAfter(LocalTime.of(10, 0)) && timeToCheck.isBefore(LocalTime.of(12, 0))) {
// return true;
// } else if (timeToCheck.isAfter(LocalTime.of(14, 0)) && timeToCheck.isBefore(LocalTime.of(15, 0))) {
// return true;
// } else if (timeToCheck.isAfter(LocalTime.of(18, 0)) && timeToCheck.isBefore(LocalTime.of(20, 0))) {
// return true;
// }
if (timeToCheck.isAfter(LocalTime.of(10, 0)) && timeToCheck.isBefore(LocalTime.of(12, 0))) {
return true;
} else if (timeToCheck.isAfter(LocalTime.of(14, 0)) && timeToCheck.isBefore(LocalTime.of(15, 0))) {
return true;
} else if (timeToCheck.isAfter(LocalTime.of(18, 0)) && timeToCheck.isBefore(LocalTime.of(20, 0))) {
return true;
}
// return false;
// }
return false;
}
// TODO: To be uncommented in M2
// Comment out isValidMeetingTime, and rename below method to isValidMeetingTime()
public boolean isValidMeetingTime(LocalTime timeToCheck) {
// * - For meetings hours: 10AM - 12PM, 2PM-3PM, 6PM-8PM
return isBetween(timeToCheck, LocalTime.of(10, 0), LocalTime.of(12, 0))
|| isBetween(timeToCheck, LocalTime.of(14, 0), LocalTime.of(15, 0))
|| isBetween(timeToCheck, LocalTime.of(18, 0), LocalTime.of(20, 0));
// public boolean isValidMeetingTimeRefactored(LocalTime timeToCheck) {
// // * - For meetings hours: 10AM - 12PM, 2PM-3PM, 6PM-8PM
// return isBetween(timeToCheck, LocalTime.of(10, 0), LocalTime.of(12, 0))
// || isBetween(timeToCheck, LocalTime.of(14, 0), LocalTime.of(15, 0))
// || isBetween(timeToCheck, LocalTime.of(18, 0), LocalTime.of(20, 0));
}
// }
// public boolean isBetween(LocalTime timeToCheck, LocalTime startTime, LocalTime endTime) {
// return (timeToCheck.isBefore(startTime)) && timeToCheck.isBefore(endTime);
// }
public boolean isBetween(LocalTime timeToCheck, LocalTime startTime, LocalTime endTime) {
return (timeToCheck.isBefore(startTime)) && timeToCheck.isAfter(endTime);
}
// TODO - Code to be checked in M5 - Don't use system specific code
/*
public void addNewAdInputLocalDateTime(String description, String type, int sellerID, LocalDateTime localDateTime) throws FileNotFoundException {
Seller seller = sellerMap.get(sellerID);
......@@ -135,31 +140,33 @@ public class AdHandler {
public void addNewAdRefactored(String description, String type,
int sellerID, LocalDateTime date) throws FileNotFoundException {
Seller seller = sellerMap.get(sellerID);
// TODO: Code to be checked in Milestone 5 - Writing Testable code
// public void addNewAdRefactored(String description, String type,
// int sellerID, LocalDateTime date) throws FileNotFoundException {
// Seller seller = sellerMap.get(sellerID);
validateDescription(description);
validateType(type);
// validateDescription(description);
// validateType(type);
AdData adData = new AdData(description, type, seller, date);
allAdsList.add(adData);
// AdData adData = new AdData(description, type, seller, date);
// allAdsList.add(adData);
}
// }
private void validateDescription(String description) {
if (description.length() > 50) {
throw new RuntimeException("\nDescription length should be less than 50");
}
}
// private void validateDescription(String description) {
// if (description.length() > 50) {
// throw new RuntimeException("\nDescription length should be less than 50");
// }
// }
private void validateType(String type) {
if (typesList.contains(type) == false) {
String msg = "\nInvalid Ad type entered. Supported are "
+ this.typesList.toString();
throw new RuntimeException(msg);
}
}
// private void validateType(String type) {
// if (typesList.contains(type) == false) {
// String msg = "\nInvalid Ad type entered. Supported are "
// + this.typesList.toString();
// throw new RuntimeException(msg);
// }
// }
public List<AdData> getAllAds() {
return this.allAdsList;
......@@ -213,35 +220,4 @@ public class AdHandler {
this.sellerMap = sellerMap;
}
// private Map<Integer, Seller> readsellerMap(String filePath) throws FileNotFoundException {
// File typesFile = new File(filePath);
// Scanner scanner = new Scanner(typesFile);
// Seller seller;
// Map<Integer, Seller> sellers = new HashMap<>();
// while(scanner.hasNext()) {
// String sellerName = scanner.next().trim();
// seller = new Seller(sellerName);
// sellers.put(seller.getID(), seller);
// }
// return sellers;
// }
// private List<String> readAdTypes(String filePath) throws FileNotFoundException {
// List<String> list = new ArrayList<>();
// File typesFile = new File(filePath);
// Scanner scanner = new Scanner(typesFile);
// while(scanner.hasNext()) {
// String typeRead = scanner.next().trim();
// list.add(typeRead);
// }
// return list;
// }
}
\ No newline at end of file
......@@ -14,15 +14,21 @@ import org.junit.jupiter.api.Test;
public class AdHandlerTest {
private static AdHandler adHandler = new AdHandler();
private static AdHandler adHandler;
// TODO - Remove/comment method post Milestone 1
// @Test
// public void testAddImageToAd() throws FileNotFoundException {
// String actualOutput = AdHandler.addImageToAd("https://my.image.url/image1");
// assertNotNull(actualOutput);
// }
@BeforeEach
public void setup() {
adHandler = new AdHandler();
}
@Test
public void testNewAdHandlerCreatesEmptyAdList() throws FileNotFoundException {
// adHandler = new AdHandler();
adHandler = new AdHandler();
assertEquals(0, adHandler.getAllAdsList().size());
}
......@@ -30,10 +36,10 @@ public class AdHandlerTest {
@Test
public void testAddingSingleAdCreatesOneAd() throws FileNotFoundException {
// Given
// adHandler = new AdHandler();
adHandler = new AdHandler();
// When
adHandler.addNewAd("djfksld", "toy", 0);
adHandler.addNewAd("Toys Set - 40pcs", "toy", 0);
// Then
assertEquals(1, adHandler.getAllAdsList().size());
......@@ -42,70 +48,66 @@ public class AdHandlerTest {
@Test
public void testAddingMultipleAdsCreatesMultipleAd() throws FileNotFoundException {
// Given
// adHandler = new AdHandler();
adHandler = new AdHandler();
// When
adHandler.addNewAd("djfksld", "toy", 0);
adHandler.addNewAd("jfklajfe", "vehicle", 1);
adHandler.addNewAd("jfklajfe", "toy", 1);
adHandler.addNewAd("Toys Set - 40pcs", "toy", 0);
adHandler.addNewAd("Pulsar 200", "vehicle", 1);
adHandler.addNewAd("Unbreakable Toys", "toy", 1);
// Then
assertEquals(3, adHandler.getAllAdsList().size());
}
@Test
public void test5PMIsValidMeetingTime() {
// * - For meetings hours: 10AM - 12PM, 2PM-3PM, 6PM-8PM
// Given
adHandler = new AdHandler();
LocalTime datetime = LocalTime.of(17, 0);
// TODO - Milestone 2 - Uncomment below method
// When
boolean actual = adHandler.isValidMeetingTime(datetime);
// @Test
// public void test5PMIsValidMeetingTime() {
// // * - For meetings hours: 10AM - 12PM, 2PM-3PM, 6PM-8PM
// // Given
// adHandler = new AdHandler();
// LocalTime datetime = LocalTime.of(17, 0);
// Then
assertEquals(false, actual);
// // When
// boolean actual = adHandler.isValidMeetingTime(datetime);
}
// // Then
// assertEquals(false, actual);
@Test
public void testNewAdHandlerInitialisesMeetingList() {
// Given
adHandler = new AdHandler();
// }
// When
List<Meeting> meetingsList = adHandler.getAllMeetings();
// Then
// TODO: Use assertNotNull to check the output of adHandler.getAllMeetings()
assertNotNull(meetingsList);
}
// TODO - Milestone 3 - Uncomment below method
@Test
public void testInvalidAdTypeReturnsException() throws FileNotFoundException {
adHandler = new AdHandler();
// public void testNewAdHandlerInitialisesMeetingList() {
// // Given
// adHandler = new AdHandler();
String description = "Bullet Proof Contact Lenses";
String type = "someInvalidType";
int sellerID = 0;
// use assertThrows to check RuntimeException is thrown
// when type entered to adHandler.addNewAd() is not supported
RuntimeException ex = assertThrows(RuntimeException.class, () -> {
adHandler.addNewAd(description, type, sellerID);
});
// use assertNotEquals to check length of exception message is not zero
assertNotEquals(0, ex.getMessage().length());
}
// // When
// List<Meeting> meetingsList = adHandler.getAllMeetings();
// @Test
// public void testAddImageToAd() throws FileNotFoundException {
// // Then
// // TODO: Use assertNotNull to check the output of adHandler.getAllMeetings()
// assertNotNull(meetingsList);
// }
// String actualOutput = AdHandler.addImageToAd("https://my.image.url/image1");
// TODO - Milestone 3 - Uncomment below method
// assertNotNull(actualOutput);
// public void testInvalidAdTypeReturnsException() throws FileNotFoundException {
// adHandler = new AdHandler();
// String description = "Bullet Proof Contact Lenses";
// String type = "someInvalidType";
// int sellerID = 0;
// // TODO - Milestone 3
// // use assertThrows to check RuntimeException is thrown
// // when type entered to adHandler.addNewAd() is not supported
// // TODO - Milestone 3
// // use assertNotEquals to check length of exception message is not zero
// }
......
......@@ -14,40 +14,35 @@ class SellerTest {
public static Scanner scanner;
@AfterAll
public static void teardown() {
if (scanner != null) {
scanner.close();
}
}
// TODO - Milestone 4 - Uncomment these methods
@Test
public void testSellersList() throws FileNotFoundException {
// Given
File typesFile = new File("src/test/resources/sellers.txt");
scanner = new Scanner(typesFile);
// @Test
// public void testSellersList() throws FileNotFoundException {
// // Given
// File typesFile = new File("src/test/resources/sellers.txt");
// scanner = new Scanner(typesFile);
// When
List<String> sellersList = Seller.readSellerList(scanner);
// // When
// List<String> sellersList = Seller.readSellerList(scanner);
// Then
assertEquals(3, sellersList.size());
// // Then
// assertEquals(3, sellersList.size());
scanner.close();
}
// scanner.close();
// }
@Test
public void testSellersLargeList() throws FileNotFoundException {
// Given
File typesFile = new File("src/test/resources/sellersLarge.txt");
scanner = new Scanner(typesFile);
// @Test
// public void testSellersLargeList() throws FileNotFoundException {
// // Given
// File typesFile = new File("src/test/resources/sellersLarge.txt");
// scanner = new Scanner(typesFile);
// When
List<String> sellersList = Seller.readSellerList(scanner);
// // When
// List<String> sellersList = Seller.readSellerList(scanner);
// Then
assertEquals(45, sellersList.size());
// // Then
// assertEquals(45, sellersList.size());
scanner.close();
}
// scanner.close();
// }
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment