2323import java .sql .SQLException ;
2424import java .time .LocalDateTime ;
2525import java .util .List ;
26+ import java .util .Map ;
2627import java .util .Optional ;
2728
2829import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
@@ -39,7 +40,8 @@ public static String readFixture(String fileName) throws IOException {
3940 @ BeforeAll
4041 static void beforeAll () throws IOException {
4142 mockServer = new MockWebServer ();
42- MockResponse mockedResponse = new MockResponse ().setBody (readFixture ("test.html" ));
43+ MockResponse mockedResponse = new MockResponse ()
44+ .setBody (readFixture ("test.html" ));
4345 mockServer .enqueue (mockedResponse );
4446 mockServer .start ();
4547 }
@@ -56,7 +58,6 @@ static void afterAll() throws IOException {
5658 mockServer .shutdown ();
5759 }
5860
59-
6061 // Main page
6162 @ Test
6263 void testMainPage () {
@@ -122,9 +123,33 @@ void testCheck() throws SQLException {
122123 assertThat (response .code ()).isEqualTo (200 );
123124 List <UrlCheck > urlCheckList = UrlCheckRepository .findById (savedUrl .getId ());
124125 assertThat (urlCheckList .contains (savedUrl ));
126+ for (UrlCheck urlCheck : urlCheckList ) {
127+ assertThat (urlCheck .getH1 ().equals ("Just do it!" ));
128+ assertThat (urlCheck .getTitle ().equals ("Test page" ));
129+ assertThat (urlCheck .getDescription ().equals ("just a simple test page" ));
130+ }
131+ Map <Long , UrlCheck > latestChecks = UrlCheckRepository .getLatestChecks ();
132+ assertThat (!latestChecks .isEmpty ());
125133 });
126134 }
127135
136+
137+ // everything below is for coverage test SonarQube
138+
139+
140+ @ Test
141+ void testGetEntities () throws SQLException {
142+ Url url = new Url ("https://mail.ru/" );
143+ url .setCreatedAt (LocalDateTime .now ());
144+ UrlRepository .save (url );
145+ url = new Url ("https://ya.ru/" );
146+ url .setCreatedAt (LocalDateTime .now ());
147+ UrlRepository .save (url );
148+
149+ List <Url > getEntities = UrlRepository .getEntities ();
150+ assertThat (!getEntities .isEmpty ());
151+ }
152+
128153 @ Test
129154 void testNoExistEntry () throws SQLException {
130155 Optional <Url > url = UrlRepository .find (999L );
0 commit comments