Rename year directories to allow natural ordering
This commit is contained in:
Binary file not shown.
38
year3/semester1/CT326: Programming III/assignments/assignment1/CT326-Assignment01/.gitignore
vendored
Normal file
38
year3/semester1/CT326: Programming III/assignments/assignment1/CT326-Assignment01/.gitignore
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
3
year3/semester1/CT326: Programming III/assignments/assignment1/CT326-Assignment01/.idea/.gitignore
generated
vendored
Normal file
3
year3/semester1/CT326: Programming III/assignments/assignment1/CT326-Assignment01/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
13
year3/semester1/CT326: Programming III/assignments/assignment1/CT326-Assignment01/.idea/misc.xml
generated
Normal file
13
year3/semester1/CT326: Programming III/assignments/assignment1/CT326-Assignment01/.idea/misc.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
124
year3/semester1/CT326: Programming III/assignments/assignment1/CT326-Assignment01/.idea/uiDesigner.xml
generated
Normal file
124
year3/semester1/CT326: Programming III/assignments/assignment1/CT326-Assignment01/.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
After Width: | Height: | Size: 82 KiB |
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>CT326-Assignment01</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
// Andrew Hayes, ID: 21321503
|
||||
public class DateInPastException extends RuntimeException {
|
||||
public DateInPastException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
// Andrew Hayes, ID: 21321503
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class NCTBooking {
|
||||
private static final AtomicLong NEXT_ID = new AtomicLong(0);
|
||||
|
||||
private String vehicleRegistrationNumber;
|
||||
private TestCentre testCentre;
|
||||
private LocalDateTime datetime;
|
||||
private final long bookingID = NEXT_ID.getAndIncrement();
|
||||
|
||||
public NCTBooking(String vehicleRegistrationNumber, TestCentre testCentre, LocalDateTime datetime) throws DateInPastException {
|
||||
// if datetime is in the future, initialising NCTBooking, otherwise throwing DateInPastException
|
||||
if (datetime.isAfter(LocalDateTime.now())) {
|
||||
this.vehicleRegistrationNumber = vehicleRegistrationNumber;
|
||||
this.testCentre = testCentre;
|
||||
this.datetime = datetime;
|
||||
}
|
||||
else {
|
||||
throw new DateInPastException("Passed datetime is in the past!");
|
||||
}
|
||||
}
|
||||
|
||||
public NCTBooking(String vehicleRegistrationNumber, TestCentre testCentre) {
|
||||
this.vehicleRegistrationNumber = vehicleRegistrationNumber;
|
||||
this.testCentre = testCentre;
|
||||
}
|
||||
|
||||
public TestCentre getTestCentre() { return testCentre; }
|
||||
|
||||
public String getVehicleRegistrationNumber() { return vehicleRegistrationNumber; }
|
||||
|
||||
public void setVehicleRegistrationNumber(String vehicleRegistrationNumber) { this.vehicleRegistrationNumber = vehicleRegistrationNumber; }
|
||||
|
||||
public long getBookingID() { return bookingID; }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("EEEE, d MMMM yyyy");
|
||||
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
|
||||
return "Booking ID Number: " + bookingID + "\n" +
|
||||
"Registration Number: " + vehicleRegistrationNumber + "\n" +
|
||||
"Centre: " + testCentre.getName() + "\n" +
|
||||
"Address: " + testCentre.getAddress() + "\n" +
|
||||
"Date & Time: On " + datetime.format(dateFormatter) + " at " + datetime.format(timeFormatter);
|
||||
}
|
||||
|
||||
public void setDatetime(LocalDateTime datetime) throws DateInPastException {
|
||||
// if datetime is in the future, setting datetime, otherwise throwing exception
|
||||
if (datetime.isAfter(LocalDateTime.now())) {
|
||||
this.datetime = datetime;
|
||||
}
|
||||
else {
|
||||
throw new DateInPastException(datetime.toString() + "is in the past!");
|
||||
}
|
||||
}
|
||||
|
||||
public LocalDateTime getDatetime() { return datetime; }
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
// Andrew Hayes, ID: 21321503
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public interface NCTBookingSlotWebservice {
|
||||
public LocalDateTime getBookingDateTime(TestCentre testCentre);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
// Andrew Hayes, ID: 21321503
|
||||
public class TestCentre {
|
||||
private String name;
|
||||
private String address;
|
||||
|
||||
public TestCentre(String name, String address) {
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public String getAddress() { return address; }
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
// Andrew Hayes, ID: 21321503
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
class NCTBookingTest {
|
||||
// tests ability to instantiate an NCTBooking
|
||||
@Test
|
||||
void testCreateNCTBooking() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
NCTBooking booking = new NCTBooking("221-RN-1234", testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0));
|
||||
assertNotNull(booking);
|
||||
}
|
||||
|
||||
// tests ability to query the test centre of a booking
|
||||
@Test
|
||||
void testGetTestCentre() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
NCTBooking booking = new NCTBooking("221-RN-1234", testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0));
|
||||
|
||||
// value returned by getTestCentre() should be the value set when the booking was created
|
||||
assertEquals(testCentre, booking.getTestCentre());
|
||||
}
|
||||
|
||||
// tests ability to query the vehicle registration for a booking
|
||||
@Test
|
||||
void testGetVehicleRegistrationNumber() {
|
||||
String vehicleRegistrationNumber = "221-RN-1234";
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
NCTBooking booking = new NCTBooking(vehicleRegistrationNumber, testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0));
|
||||
|
||||
// value returned by getVehicleRegistrationNumber() should be the value that was set when the booking was created (in this case)
|
||||
assertEquals(vehicleRegistrationNumber, booking.getVehicleRegistrationNumber());
|
||||
}
|
||||
|
||||
// tests ability to edit the vehicle registration number of a booking
|
||||
@Test
|
||||
void testSetVehicleRegistrationNumber() {
|
||||
String vehicleRegistrationNumber = "221-RN-1234";
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
NCTBooking booking = new NCTBooking(vehicleRegistrationNumber, testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0));
|
||||
|
||||
// changing the value of vehicleRegistrationNumber and testing that the value returned by getVehicleRegistrationNumber is equal to the updated value
|
||||
String newVehicleRegistrationNumber = "00-D-4321";
|
||||
booking.setVehicleRegistrationNumber(newVehicleRegistrationNumber);
|
||||
|
||||
// value returned by getVehicleRegistrationNumber() should be the value that was set in the last edit
|
||||
assertEquals(newVehicleRegistrationNumber, booking.getVehicleRegistrationNumber());
|
||||
}
|
||||
|
||||
// tests ability to instantiate an NCTBooking without specifying a date
|
||||
@Test
|
||||
void testCreateNCTBookingWithoutDate() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
NCTBooking booking = new NCTBooking("221-RN-123", testCentre);
|
||||
assertNotNull(booking);
|
||||
}
|
||||
|
||||
// tests ability to query the date and time of a booking
|
||||
@Test
|
||||
void testGetDatetime() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
LocalDateTime datetime = LocalDateTime.of(2024, 1, 1, 9, 0, 0);
|
||||
NCTBooking booking = new NCTBooking("221-RN-1234", testCentre, datetime);
|
||||
|
||||
// queried datetime should be equal to the datetime set on initialisation
|
||||
assertEquals(datetime, booking.getDatetime());
|
||||
}
|
||||
|
||||
// tests ability to set the date and time of a booking via an external API
|
||||
@Test
|
||||
void testSetDatetime() {
|
||||
// stub implementation of the NCTBookingSlotWebservice for testing purposes
|
||||
NCTBookingSlotWebservice testService = new NCTBookingSlotWebservice() {
|
||||
@Override
|
||||
public LocalDateTime getBookingDateTime(TestCentre testCentre) {
|
||||
return LocalDateTime.of(2024, 1, 1, 9, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
NCTBooking booking = new NCTBooking("221-RN-123", testCentre);
|
||||
LocalDateTime datetime = testService.getBookingDateTime(testCentre);
|
||||
booking.setDatetime(datetime);
|
||||
|
||||
assertEquals(datetime, booking.getDatetime());
|
||||
}
|
||||
|
||||
// tests that bookings with a date and time in the past throw a user-defined exception
|
||||
@Test
|
||||
void testCreateNCTBookingWithDataInThePast() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
assertThrows(
|
||||
DateInPastException.class,
|
||||
() -> new NCTBooking("221-RN-123", testCentre, LocalDateTime.of(1970, 1, 1, 9, 0, 0))
|
||||
);
|
||||
}
|
||||
|
||||
// tests that attempting to set the datetime of a booking to a time in the past throws a user-defined exception
|
||||
@Test
|
||||
void testSetDatetimeInPast() {
|
||||
// stub implementation of the NCTBookingSlotWebservice for testing purposes
|
||||
NCTBookingSlotWebservice testService = new NCTBookingSlotWebservice() {
|
||||
@Override
|
||||
public LocalDateTime getBookingDateTime(TestCentre testCentre) {
|
||||
return LocalDateTime.of(1970, 1, 1, 9, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
NCTBooking booking = new NCTBooking("221-RN-123", testCentre);
|
||||
LocalDateTime datetime = testService.getBookingDateTime(testCentre);
|
||||
|
||||
assertThrows(
|
||||
DateInPastException.class,
|
||||
() -> booking.setDatetime(datetime)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// tests that bookings have a unique booking ID number generated when they're created
|
||||
@Test
|
||||
void testUniqueIDGenerated() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
NCTBooking booking = new NCTBooking("221-RN-123", testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0));
|
||||
assertNotNull(booking.getBookingID());
|
||||
}
|
||||
|
||||
// attempts to test if booking IDs are not unique by comparing 10,000 of them (note that this does not prove uniqueness, just will disprove it in certain situations)
|
||||
@Test
|
||||
void testBookingIDsUnique() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
|
||||
NCTBooking[] bookings = new NCTBooking[10_000];
|
||||
for (int i = 0; i < 10_000; i ++) {
|
||||
bookings[i] = new NCTBooking("221-RN-123", testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0));
|
||||
}
|
||||
|
||||
// looping over the bookings and comparing each one to every other one
|
||||
for (int i = 0; i < 10_000; i ++) {
|
||||
for (int j = 0; j < 10_000; j ++) {
|
||||
if (i != j) {
|
||||
assertNotEquals(bookings[i].getBookingID(), bookings[j].getBookingID());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tests that output from toString() method matches a regex for the expected output
|
||||
@Test
|
||||
void testToString() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
NCTBooking booking = new NCTBooking("221-RN-123", testCentre, LocalDateTime.of(2024, 1, 1, 9, 0, 0));
|
||||
|
||||
// the only "regular-expressiony" part of the below regex is "[0-9]+" which just matches one or more decimal digits
|
||||
assertTrue(booking.toString().matches(
|
||||
"""
|
||||
Booking ID Number: [0-9]+
|
||||
Registration Number: 221-RN-123
|
||||
Centre: Test Centre 1
|
||||
Address: 10 Downing Street
|
||||
Date & Time: On Monday, 1 January 2024 at 09:00"""
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// Andrew Hayes, ID: 21321503
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
class TestCentreTest {
|
||||
// tests ability to instantiate a TestCentre
|
||||
@Test
|
||||
void testCreateTestCentre() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
assertNotNull(testCentre);
|
||||
}
|
||||
|
||||
// tests the getter for "name" in TestCentre class
|
||||
@Test
|
||||
void testGetName() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
assertEquals("Test Centre 1", testCentre.getName());
|
||||
}
|
||||
|
||||
// tests the getter for "address" in TestCentre class
|
||||
@Test
|
||||
void testGetAddress() {
|
||||
TestCentre testCentre = new TestCentre("Test Centre 1", "10 Downing Street");
|
||||
assertEquals("10 Downing Street", testCentre.getAddress());
|
||||
}
|
||||
}
|
Binary file not shown.
Reference in New Issue
Block a user