Skip to content

Commit 13d99de

Browse files
Add tests for coverage tests
1 parent 23100c7 commit 13d99de

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

app/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ run:
1010
./gradlew run
1111
test:
1212
./gradlew test
13+
report:
14+
./gradlew jacocoTestReport
1315

1416
build-run: build run

app/src/test/java/hexlet/code/AppTest.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.sql.SQLException;
2424
import java.time.LocalDateTime;
2525
import java.util.List;
26+
import java.util.Map;
2627
import java.util.Optional;
2728

2829
import 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

Comments
 (0)