Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ services:
MYSQL_PASSWORD: strong_password_here
ports:
- "3306:3306"
command: --default-authentication-plugin=mysql_native_password
6 changes: 0 additions & 6 deletions faktura.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
FAKTURA - EVTA Rental
Kund: eric
Att betala: 1700.0 kr
Betala till:

Bankgiro: 3492-232
OCR: 0000000000
1 change: 1 addition & 0 deletions sql/seeds.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

USE car_rental;

INSERT INTO cars (brand, model, registrationNumber, pricePerHour, pricePerDay) VALUES
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions src/main/java/org/example/entity/Addon.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public Addon(String name, double price) {
this.price = price;
}

public Addon(String name, String description, double price) {
this.name = name;
this.price = price;
}
Comment thread
Boppler12 marked this conversation as resolved.

public Long getId() { return id; }
public String getName() { return name; }
public double getPrice() { return price; }
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/example/entity/PaymentMethod.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example.entity;

public enum PaymentMethod {
Debit,
CASH,
INVOICE
}
1 change: 1 addition & 0 deletions src/test/java/org/example/AppIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import static org.assertj.core.api.Assertions.assertThat;


public class AppIT {
@Test
void itTest() {
Expand Down
73 changes: 73 additions & 0 deletions src/test/java/org/example/BookingServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.example;

import org.example.entity.Addon;
import org.example.entity.BookingType;
import org.example.entity.Car;
import org.example.service.BookingService;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class BookingServiceTest {

private final BookingService bookingService = new BookingService();

@Test
void testCalculatePriceHourly() {
Car car = new Car("Volvo", "XC90", "ABC123", 500, 2000);
LocalDateTime start = LocalDateTime.of(2026, 1, 14, 10, 0);
LocalDateTime end = LocalDateTime.of(2026, 1, 14, 12, 0); // 2 timmar
List<Addon> addons = new ArrayList<>();

double price = bookingService.calculatePrice(car, start, end, BookingType.HOURLY, addons);

// 2 timmar * 500 kr/timme = 1000 kr
assertThat(price).isEqualTo(1000);
}

@Test
void testCalculatePriceDaily() {
Car car = new Car("Volvo", "XC90", "ABC123", 500, 2000);
LocalDateTime start = LocalDateTime.of(2026, 1, 14, 10, 0);
LocalDateTime end = LocalDateTime.of(2026, 1, 16, 10, 0); // 2 dagar
List<Addon> addons = new ArrayList<>();

double price = bookingService.calculatePrice(car, start, end, BookingType.DAILY, addons);

// 2 dagar * 2000 kr/dag = 4000 kr
assertThat(price).isEqualTo(4000);
}

@Test
void testCalculatePriceWithAddons() {
Car car = new Car("Volvo", "XC90", "ABC123", 500, 2000);
LocalDateTime start = LocalDateTime.of(2026, 1, 14, 10, 0);
LocalDateTime end = LocalDateTime.of(2026, 1, 14, 12, 0); // 2 timmar

List<Addon> addons = new ArrayList<>();
Addon addon1 = new Addon("GPS", "GPS-navigator", 100);
addons.add(addon1);

double price = bookingService.calculatePrice(car, start, end, BookingType.HOURLY, addons);

// (2 timmar * 500 kr/timme) + 100 kr addon = 1100 kr
assertThat(price).isEqualTo(1100);
}

@Test
void testCalculatePriceMinimumOneHour() {
Car car = new Car("Volvo", "XC90", "ABC123", 500, 2000);
LocalDateTime start = LocalDateTime.of(2026, 1, 14, 10, 30);
LocalDateTime end = LocalDateTime.of(2026, 1, 14, 10, 45); // Samma timme
List<Addon> addons = new ArrayList<>();

double price = bookingService.calculatePrice(car, start, end, BookingType.HOURLY, addons);

// Minimum 1 timme även om mindre än 1 timme valts
assertThat(price).isEqualTo(500);
}
}
27 changes: 27 additions & 0 deletions src/test/java/org/example/CarServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

package org.example;

import org.example.entity.Car;
import org.example.service.CarService;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class CarServiceTest {

private final CarService carService = new CarService();
Comment thread
Boppler12 marked this conversation as resolved.

@Test
void testGetAllCarsReturnsNotNull() {
List<Car> cars = carService.getAllCars();
assertThat(cars).isNotNull();
}

@Test
void testGetAllCarsReturnsAList() {
List<Car> cars = carService.getAllCars();
assertThat(cars).isInstanceOf(List.class);
}
}
Loading