Skip to content

Commit eb349c9

Browse files
committed
refactor: clean up formatting and improve readability in JUnit5ExampleTest11
1 parent eff75f4 commit eb349c9

File tree

1 file changed

+46
-44
lines changed

1 file changed

+46
-44
lines changed
Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package net.codejava;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
6+
import java.util.Calendar;
7+
import java.util.List;
8+
29
import org.junit.jupiter.api.Test;
310
import org.springframework.beans.factory.annotation.Autowired;
411
import org.springframework.boot.test.context.SpringBootTest;
5-
import org.springframework.test.context.ActiveProfiles;
612
import org.springframework.test.context.TestPropertySource;
7-
import static org.junit.jupiter.api.Assertions.assertEquals;
8-
import java.util.Calendar;
9-
import java.util.List;
10-
import static org.junit.jupiter.api.Assertions.assertNotNull;
1113

1214
@SpringBootTest
1315
@TestPropertySource(properties = {
14-
"enableSearchFeature=true",
15-
"spring.datasource.url=jdbc:h2:mem:testdb;Mode=PostgreSQL",
16-
"spring.jpa.hibernate.ddl-auto=create-drop"
16+
"enableSearchFeature=true",
17+
"spring.datasource.url=jdbc:h2:mem:testdb;Mode=PostgreSQL",
18+
"spring.jpa.hibernate.ddl-auto=create-drop"
1719
})
1820
public class JUnit5ExampleTest11 {
1921

@@ -26,53 +28,53 @@ public class JUnit5ExampleTest11 {
2628

2729
@Test
2830
void testInsert() {
29-
Calendar calendar = Calendar.getInstance();
30-
calendar.set(2021, Calendar.FEBRUARY, 1);
31-
java.util.Date utilDate = calendar.getTime();
32-
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
31+
Calendar calendar = Calendar.getInstance();
32+
calendar.set(2021, Calendar.FEBRUARY, 1);
33+
java.util.Date utilDate = calendar.getTime();
34+
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
3335

34-
// Generate a unique serial number based on the current timestamp
35-
String serialNumber = String.valueOf(System.currentTimeMillis());
36+
// Generate a unique serial number based on the current timestamp
37+
String serialNumber = String.valueOf(System.currentTimeMillis());
3638

37-
Sale sale = new Sale(serialNumber, "Laptop", 1, 1500.00f, sqlDate);
38-
sale.setEditing(false); // Set the isEditing field to false for the test
39-
salesDAO.save(sale);
39+
Sale sale = new Sale(serialNumber, "Laptop", 1, 1500.00f, sqlDate);
40+
sale.setEditing(false); // Set the isEditing field to false for the test
41+
salesDAO.save(sale);
4042

41-
// list all the records
42-
List<Sale> listSale = salesDAO.list(10, 0);
43+
// list all the records
44+
List<Sale> listSale = salesDAO.list(10, 0);
4345

44-
// Find the sale with the matching serial number
45-
Sale insertedSale = listSale.stream()
46-
.filter(s -> s.getSerialNumber().equals(serialNumber))
47-
.findFirst()
48-
.orElse(null);
46+
// Find the sale with the matching serial number
47+
Sale insertedSale = listSale.stream()
48+
.filter(s -> s.getSerialNumber().equals(serialNumber))
49+
.findFirst()
50+
.orElse(null);
4951

50-
System.out.println("\n\n");
51-
System.out.println("--------------------------------------------------------------------------------");
52-
System.out.println("Expected value of item: Laptop");
53-
System.out.println("Actual value of item: " + insertedSale.getItem());
54-
System.out.println("--------------------------------------------------------------------------------");
55-
assertNotNull(insertedSale, "Inserted sale not found");
56-
assertEquals("Laptop", insertedSale.getItem(), "Item name does not match");
52+
System.out.println("\n\n");
53+
System.out.println("--------------------------------------------------------------------------------");
54+
System.out.println("Expected value of item: Laptop");
55+
System.out.println("Actual value of item: " + insertedSale.getItem());
56+
System.out.println("--------------------------------------------------------------------------------");
57+
assertNotNull(insertedSale, "Inserted sale not found");
58+
assertEquals("Laptop", insertedSale.getItem(), "Item name does not match");
5759

58-
// clean up the database
59-
salesDAO.delete(serialNumber);
60-
System.out.println("\n\nTest11-1 Successful!\n\n");
60+
// clean up the database
61+
salesDAO.delete(serialNumber);
62+
System.out.println("\n\nTest11-1 Successful!\n\n");
6163
}
6264

6365
// test the variable enableSearchFeature in AppController.java
6466
@Test
6567
void testEnableSearchFeature() {
66-
// print a comment about the value of enableSearchFeature
67-
System.out.println("\n\n");
68-
System.out.println("--------------------------------------------------------------------------------");
69-
System.out.println("Expected value of enableSearchFeature: true");
70-
System.out.println("Actual value of enableSearchFeature: " + appController.getEnableSearchFeature());
71-
System.out.println("--------------------------------------------------------------------------------");
68+
// print a comment about the value of enableSearchFeature
69+
System.out.println("\n\n");
70+
System.out.println("--------------------------------------------------------------------------------");
71+
System.out.println("Expected value of enableSearchFeature: true");
72+
System.out.println("Actual value of enableSearchFeature: " + appController.getEnableSearchFeature());
73+
System.out.println("--------------------------------------------------------------------------------");
7274

73-
// assert that the value of enableSearchFeature is true
74-
assertEquals(true, appController.getEnableSearchFeature());
75+
// assert that the value of enableSearchFeature is true
76+
assertEquals(true, appController.getEnableSearchFeature());
7577

76-
System.out.println("\n\nTest11-2 Successful!\n\n");
78+
System.out.println("\n\nTest11-2 Successful!\n\n");
7779
}
78-
}
80+
}

0 commit comments

Comments
 (0)