-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new unit test with SalesDAO - db test
- Loading branch information
szandany
committed
Apr 30, 2023
1 parent
e60d9e7
commit 138e458
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.codejava; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import java.util.List; | ||
|
||
@SpringBootTest | ||
public class JUnit5ExampleTest11 { | ||
|
||
@Autowired | ||
// create private instance of SalesDAO | ||
private SalesDAO salesDAO = new SalesDAO();; | ||
|
||
@Test | ||
void testInsert() { | ||
Sale sale = new Sale("test item 123", 1, 1); | ||
salesDAO.save(sale); | ||
// list all the records | ||
List<Sale> listSale = salesDAO.list(); | ||
// print a comment about the latest item on the list | ||
System.out.println("Expected item on the list: test item 123"); | ||
System.out.println("Actual item on the list: " + listSale.get(listSale.size()-1).getItem()); | ||
// assert that the latest item on the list is "test item 123" | ||
assertEquals("test item 123", listSale.get(listSale.size()-1).getItem()); | ||
// clean up the database | ||
salesDAO.delete(listSale.get(listSale.size()-1).getId()); | ||
System.out.println("\n\nTest11-1 Successful!\n\n"); | ||
} | ||
} |