Skip to content

Commit 977c06d

Browse files
author
rustavil
committed
[added] lombok and useCase tests
1 parent 050830b commit 977c06d

File tree

42 files changed

+503
-644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+503
-644
lines changed

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<swgger.version>2.9.2</swgger.version>
2121
<mapper.version>1.3.0.Final</mapper.version>
2222
<db.version>1.4.199</db.version>
23+
<lombok.version>1.18.4</lombok.version>
2324
</properties>
2425

2526
<dependencies>
@@ -43,6 +44,13 @@
4344
<artifactId>mapstruct-jdk8</artifactId>
4445
<version>${mapper.version}</version>
4546
</dependency>
47+
<!--Lombok-->
48+
<dependency>
49+
<groupId>org.projectlombok</groupId>
50+
<artifactId>lombok</artifactId>
51+
<version>${lombok.version}</version>
52+
<scope>provided</scope>
53+
</dependency>
4654
<!--Mail-->
4755
<dependency>
4856
<groupId>org.springframework.boot</groupId>
@@ -100,6 +108,11 @@
100108
<artifactId>mapstruct-processor</artifactId>
101109
<version>${mapper.version}</version>
102110
</path>
111+
<path>
112+
<groupId>org.projectlombok</groupId>
113+
<artifactId>lombok</artifactId>
114+
<version>${lombok.version}</version>
115+
</path>
103116
</annotationProcessorPaths>
104117
<compilerArgs>
105118
<arg>-Amapstruct.suppressGeneratorTimestamp=true</arg>
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
package ru.rustavil.fuel_consumption.domain;
22

3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
36
import ru.rustavil.fuel_consumption.domain.exceptions.InvalidException;
47

58
import java.util.UUID;
69

10+
@Builder
11+
@Getter
12+
@AllArgsConstructor
713
public class Driver {
814

9-
private final UUID id;
15+
@Builder.Default
16+
private final UUID id = UUID.randomUUID();
1017
private final Long identifier;
1118

12-
public Driver(Long identifier) {
13-
this.id = UUID.randomUUID();
14-
if (identifier <= 0) {
15-
throw new InvalidException("Driver identifier must be positive");
16-
}
17-
this.identifier = identifier;
19+
public static DriverBuilder builder() {
20+
return new ValidateDriverBuilder();
1821
}
1922

20-
public UUID getId() {
21-
return id;
22-
}
23+
private static class ValidateDriverBuilder extends DriverBuilder {
2324

24-
public Long getIdentifier() {
25-
return identifier;
26-
}
25+
@Override
26+
public Driver build() {
27+
if (super.identifier <= 0) {
28+
throw new InvalidException("Driver identifier must be positive");
29+
}
30+
return super.build();
31+
}
2732

33+
}
2834
}
Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,45 @@
11
package ru.rustavil.fuel_consumption.domain;
22

3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
36
import ru.rustavil.fuel_consumption.domain.exceptions.InvalidException;
47

58
import java.math.BigDecimal;
69
import java.util.Objects;
710
import java.util.UUID;
811

12+
@Builder
13+
@Getter
14+
@AllArgsConstructor
915
public class FuelConsumption {
1016

11-
private final UUID id;
17+
@Builder.Default
18+
private final UUID id = UUID.randomUUID();
1219
private final Driver driver;
1320
private final FuelType fuelType;
1421
private final Double fuelVolume;
1522
private final BigDecimal fuelPrice;
1623

17-
public FuelConsumption(UUID id,
18-
Driver driver,
19-
FuelType fuelType,
20-
Double fuelVolume,
21-
BigDecimal fuelPrice) {
22-
this.id = id;
23-
if (Objects.isNull(driver)) {
24-
throw new InvalidException("Driver required");
25-
}
26-
this.driver = driver;
27-
this.fuelType = fuelType;
28-
if (fuelVolume <= 0) {
29-
throw new InvalidException("Fuel volume must be great than 0");
30-
}
31-
this.fuelVolume = fuelVolume;
32-
if (fuelPrice.compareTo(BigDecimal.ZERO) <= 0) {
33-
throw new InvalidException("Fuel price must be great than 0");
34-
}
35-
this.fuelPrice = fuelPrice;
24+
public static FuelConsumptionBuilder builder() {
25+
return new ValidateFuelConsumptionBuilder();
3626
}
3727

38-
public FuelConsumption(Driver driver,
39-
FuelType fuelType,
40-
Double fuelVolume,
41-
BigDecimal fuelPrice) {
42-
this.id = UUID.randomUUID();
43-
if (Objects.isNull(driver)) {
44-
throw new InvalidException("Driver required");
45-
}
46-
this.driver = driver;
47-
this.fuelType = fuelType;
48-
if (fuelVolume <= 0) {
49-
throw new InvalidException("Fuel volume must be great than 0");
28+
private static class ValidateFuelConsumptionBuilder extends FuelConsumptionBuilder {
29+
30+
@Override
31+
public FuelConsumption build() {
32+
if (Objects.isNull(super.driver)) {
33+
throw new InvalidException("Driver required");
34+
}
35+
if (super.fuelVolume <= 0) {
36+
throw new InvalidException("Fuel volume must be great than 0");
37+
}
38+
if (super.fuelPrice.compareTo(BigDecimal.ZERO) <= 0) {
39+
throw new InvalidException("Fuel price must be great than 0");
40+
}
41+
return super.build();
5042
}
51-
this.fuelVolume = fuelVolume;
52-
if (fuelPrice.compareTo(BigDecimal.ZERO) <= 0) {
53-
throw new InvalidException("Fuel price must be great than 0");
54-
}
55-
this.fuelPrice = fuelPrice;
56-
}
57-
58-
public UUID getId() {
59-
return id;
60-
}
61-
62-
public Driver getDriver() {
63-
return driver;
64-
}
65-
66-
public FuelType getFuelType() {
67-
return fuelType;
68-
}
69-
70-
public Double getFuelVolume() {
71-
return fuelVolume;
72-
}
7343

74-
public BigDecimal getFuelPrice() {
75-
return fuelPrice;
7644
}
7745
}

src/main/java/ru/rustavil/fuel_consumption/domain/FuelPurchase.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package ru.rustavil.fuel_consumption.domain;
22

33

4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Getter;
47
import ru.rustavil.fuel_consumption.domain.exceptions.InvalidException;
58

69
import java.math.BigDecimal;
710
import java.util.*;
811
import java.util.stream.Collectors;
912

13+
@Builder
14+
@Getter
1015
public class FuelPurchase {
1116

1217
private final List<FuelConsumption> fuelConsumptionList;
@@ -41,4 +46,19 @@ public BigDecimal getTotalPrice() {
4146
return this.fuelConsumptionList.stream().map(FuelConsumption::getFuelPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
4247
}
4348

49+
public static FuelPurchaseBuilder builder() {
50+
return new ValidateFuelPurchaseBuilder();
51+
}
52+
53+
private static class ValidateFuelPurchaseBuilder extends FuelPurchaseBuilder {
54+
55+
@Override
56+
public FuelPurchase build() {
57+
if (Objects.isNull(super.fuelConsumptionList) || super.fuelConsumptionList.isEmpty()) {
58+
throw new InvalidException("Fuel consumption empty");
59+
}
60+
return super.build();
61+
}
62+
63+
}
4464
}

src/main/java/ru/rustavil/fuel_consumption/domain/FuelPurchaseNotification.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package ru.rustavil.fuel_consumption.domain;
22

33
import com.google.common.base.Joiner;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
46
import ru.rustavil.fuel_consumption.domain.exceptions.InvalidException;
57

68
import java.util.Map;
79

10+
@Builder
811
public class FuelPurchaseNotification implements Notification {
912

1013
private static final String TITLE = "New fuel purchase!";
@@ -38,4 +41,22 @@ public String buildMsg() {
3841
return String.format(MSG_TMPL, totalFuelVolume, Joiner.on(",").withKeyValueSeparator(":").join(this.fuelVolumeMap), totalPrice);
3942
}
4043

44+
public static FuelPurchaseNotificationBuilder builder() {
45+
return new ValidateFuelPurchaseNotificationBuilder();
46+
}
47+
48+
private static class ValidateFuelPurchaseNotificationBuilder extends FuelPurchaseNotificationBuilder {
49+
50+
@Override
51+
public FuelPurchaseNotification build() {
52+
if (super.totalFuelVolume < 0) {
53+
throw new InvalidException("Total fuel price must not be negative");
54+
}
55+
if (super.totalPrice < 0) {
56+
throw new InvalidException("Total fuel price must not be negative");
57+
}
58+
return super.build();
59+
}
60+
61+
}
4162
}
Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package ru.rustavil.fuel_consumption.domain;
22

3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.Getter;
37
import ru.rustavil.fuel_consumption.domain.exceptions.InvalidException;
48

59
import java.math.BigDecimal;
610
import java.time.LocalDate;
7-
import java.util.Objects;
811

12+
@Builder
13+
@Getter
14+
@AllArgsConstructor
15+
@EqualsAndHashCode
916
public class MonthDriverFuelConsumption {
1017

1118
private final LocalDate date;
@@ -30,41 +37,22 @@ public MonthDriverFuelConsumption(
3037
this.fuelPrice = fuelPrice;
3138
}
3239

33-
public LocalDate getDate() {
34-
return date;
40+
public static MonthDriverFuelConsumptionBuilder builder() {
41+
return new ValidateMonthDriverFuelConsumptionBuilder();
3542
}
3643

37-
public Long getDriverIdentifier() {
38-
return driverIdentifier;
39-
}
40-
41-
public FuelType getFuelType() {
42-
return fuelType;
43-
}
44-
45-
public Double getFuelVolume() {
46-
return fuelVolume;
47-
}
44+
private static class ValidateMonthDriverFuelConsumptionBuilder extends MonthDriverFuelConsumptionBuilder {
4845

49-
public BigDecimal getFuelPrice() {
50-
return fuelPrice;
51-
}
52-
53-
@Override
54-
public boolean equals(Object o) {
55-
if (this == o) return true;
56-
if (o == null || getClass() != o.getClass()) return false;
57-
MonthDriverFuelConsumption that = (MonthDriverFuelConsumption) o;
58-
return Objects.equals(date, that.date) &&
59-
Objects.equals(driverIdentifier, that.driverIdentifier) &&
60-
fuelType == that.fuelType &&
61-
Objects.equals(fuelVolume, that.fuelVolume) &&
62-
Objects.equals(fuelPrice, that.fuelPrice);
63-
}
46+
@Override
47+
public MonthDriverFuelConsumption build() {
48+
if (super.fuelVolume < 0) {
49+
throw new InvalidException("Total fuel volume must not be negative");
50+
}
51+
if (super.fuelPrice.compareTo(BigDecimal.ZERO) < 0 ) {
52+
throw new InvalidException("Total fuel price must not be negative");
53+
}
54+
return super.build();
55+
}
6456

65-
@Override
66-
public int hashCode() {
67-
return Objects.hash(date, driverIdentifier,
68-
fuelType, fuelVolume, fuelPrice);
6957
}
7058
}

src/main/java/ru/rustavil/fuel_consumption/domain/MonthFuelConsumption.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
package ru.rustavil.fuel_consumption.domain;
22

3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.Getter;
37
import ru.rustavil.fuel_consumption.domain.exceptions.InvalidException;
48

59
import java.math.BigDecimal;
610
import java.time.LocalDate;
711
import java.util.Objects;
812

13+
@Builder
14+
@Getter
15+
@AllArgsConstructor
16+
@EqualsAndHashCode
917
public class MonthFuelConsumption {
1018

1119
private final LocalDate date;
@@ -33,23 +41,25 @@ public MonthFuelConsumption(int year, int mont,
3341
this.avgFuelPrice = avgFuelPrice;
3442
}
3543

36-
public LocalDate getDate() {
37-
return date;
44+
public static MonthFuelConsumptionBuilder builder() {
45+
return new ValidateMonthFuelConsumptionBuilder();
3846
}
3947

40-
public FuelType getFuelType() {
41-
return fuelType;
42-
}
43-
44-
public Double getFuelVolume() {
45-
return fuelVolume;
46-
}
48+
private static class ValidateMonthFuelConsumptionBuilder extends MonthFuelConsumptionBuilder {
4749

48-
public BigDecimal getTotalFuelPrice() {
49-
return totalFuelPrice;
50-
}
50+
@Override
51+
public MonthFuelConsumption build() {
52+
if (super.fuelVolume < 0) {
53+
throw new InvalidException("Fuel volume must not be negative");
54+
}
55+
if (super.totalFuelPrice.compareTo(BigDecimal.ZERO) < 0) {
56+
throw new InvalidException("Total fuel price must not be negative");
57+
}
58+
if (super.avgFuelPrice.compareTo(BigDecimal.ZERO) < 0) {
59+
throw new InvalidException("Fuel avg price must not be negative");
60+
}
61+
return super.build();
62+
}
5163

52-
public BigDecimal getAvgFuelPrice() {
53-
return avgFuelPrice;
5464
}
5565
}

0 commit comments

Comments
 (0)