Skip to content

Commit 59cd5d7

Browse files
committed
feat: Nova cobertura de código Java com Jacoco.
1 parent a56cf80 commit 59cd5d7

File tree

12 files changed

+690
-38
lines changed

12 files changed

+690
-38
lines changed

.github/workflows/maven.yml

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,55 @@
11
name: JavaCI
22

3-
on: [push]
3+
env:
4+
MAVEN_OPT: -q
45

5-
jobs:
6-
build:
6+
on:
7+
# Acione o fluxo de trabalho na solicitação push ou pull,
8+
# mas apenas para a ramificação principal.
9+
push:
10+
branches:
11+
- master
12+
- develop
13+
- 'release/**'
14+
tags:
15+
- v*
16+
paths-ignore:
17+
- '**.md'
18+
- '**.sh'
19+
- '**.json'
20+
- '**.yml'
21+
pull_request:
22+
branches:
23+
- master
24+
- develop
25+
- 'release/**'
26+
tags:
27+
- v*
728

29+
jobs:
30+
Test:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@master
34+
- name: Setup java
35+
uses: joschi/setup-jdk@v1
36+
with:
37+
java-version: 'openjdk11'
38+
architecture: 'x64'
39+
- name: Test with Maven
40+
run: |
41+
mvn ${MAVEN_OPT} -am clean test jacoco:report
42+
bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN
43+
Build:
44+
needs: Test
845
runs-on: ubuntu-latest
9-
1046
steps:
11-
- uses: actions/checkout@v1
12-
- name: Set up JDK 11
13-
uses: actions/setup-java@v1
47+
- uses: actions/checkout@master
48+
- name: Setup java
49+
uses: joschi/setup-jdk@v1
1450
with:
15-
java-version: 11
51+
java-version: 'openjdk11'
52+
architecture: 'x64'
1653
- name: Build with Maven
17-
run: mvn -B package --file pom.xml
54+
run: |
55+
mvn ${MAVEN_OPT} -am clean package install

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![Actions Status](https://github.com/danielso2007/somejava8examples/workflows/JavaCI/badge.svg)](https://github.com/danielso2007/somejava8examples/actions)
22
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/danielso2007/somejava8examples/JavaCI)
3+
[![codecov](https://codecov.io/gh/danielso2007/somejava8examples/branch/master/graph/badge.svg)](https://codecov.io/gh/danielso2007/somejava8examples)
34
![GitHub package.json version](https://img.shields.io/github/package-json/v/danielso2007/somejava8examples)
45
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/danielso2007/somejava8examples)
56
![Coveralls github](https://img.shields.io/coveralls/github/danielso2007/somejava8examples)

pom.xml

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</parent>
1212
<groupId>br.com.somejava8examples</groupId>
1313
<artifactId>someJava8Examples</artifactId>
14-
<version>0.0.1-SNAPSHOT</version>
14+
<version>0.1.0-SNAPSHOT</version>
1515
<name>Some Java8 Examples</name>
1616
<description>Some Java 8 examples</description>
1717

@@ -80,6 +80,11 @@
8080
<release>${java.version}</release>
8181
<source>${maven.compiler.source}</source>
8282
<target>${maven.compiler.target}</target>
83+
<fork>true</fork>
84+
<compilerargs>
85+
<arg>--add-modules</arg>
86+
<arg>java.xml.bind</arg>
87+
</compilerargs>
8388
</configuration>
8489
</plugin>
8590
<plugin>
@@ -93,15 +98,71 @@
9398
<skipTests>false</skipTests>
9499
<workingDirectory>${project.build.directory}</workingDirectory>
95100
<trimStackTrace>false</trimStackTrace>
96-
<forkCount>4</forkCount>
97-
<threadCount>4</threadCount>
101+
<forkCount>10</forkCount>
102+
<threadCount>10</threadCount>
98103
<reuseForks>false</reuseForks>
99104
<parallel>classes</parallel>
100105
<perCoreThreadCount>true</perCoreThreadCount>
101106
<useUnlimitedThreads>false</useUnlimitedThreads>
102-
<argLine>-Xmx1024m</argLine>
103107
</configuration>
104-
</plugin>
108+
</plugin>
109+
<plugin>
110+
<groupId>org.apache.maven.plugins</groupId>
111+
<artifactId>maven-failsafe-plugin</artifactId>
112+
<version>2.16</version>
113+
<executions>
114+
<execution>
115+
<id>default-integration-test</id>
116+
<goals>
117+
<goal>integration-test</goal>
118+
</goals>
119+
</execution>
120+
</executions>
121+
</plugin>
122+
<plugin>
123+
<groupId>org.jacoco</groupId>
124+
<artifactId>jacoco-maven-plugin</artifactId>
125+
<version>0.8.5</version>
126+
<executions>
127+
<execution>
128+
<id>prepare-agent</id>
129+
<goals>
130+
<goal>prepare-agent</goal>
131+
</goals>
132+
</execution>
133+
<execution>
134+
<id>post-unit-test</id>
135+
<phase>test</phase>
136+
<goals>
137+
<goal>report</goal>
138+
<goal>check</goal>
139+
</goals>
140+
<configuration>
141+
<excludes>
142+
<exclude>**/*SomeJava8ExamplesApplication.*</exclude>
143+
<exclude>br/com/somejava8examples/commons/entities*</exclude>
144+
</excludes>
145+
<rules>
146+
<rule>
147+
<element>BUNDLE</element>
148+
<limits>
149+
<limit implementation="org.jacoco.report.check.Limit">
150+
<counter>INSTRUCTION</counter>
151+
<value>COVEREDRATIO</value>
152+
<minimum>0.60</minimum>
153+
</limit>
154+
<limit>
155+
<counter>COMPLEXITY</counter>
156+
<value>COVEREDRATIO</value>
157+
<minimum>0.60</minimum>
158+
</limit>
159+
</limits>
160+
</rule>
161+
</rules>
162+
</configuration>
163+
</execution>
164+
</executions>
165+
</plugin>
105166
</plugins>
106167
</build>
107168

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
package br.com.somejava8examples.commons.service;
22

3-
import br.com.somejava8examples.commons.entities.*;
3+
import java.util.Optional;
4+
45
import org.springframework.stereotype.Service;
56

6-
import java.util.Optional;
7+
import br.com.somejava8examples.commons.entities.DisplayFeatures;
8+
import br.com.somejava8examples.commons.entities.DisplayFeatures2;
9+
import br.com.somejava8examples.commons.entities.Mobile;
10+
import br.com.somejava8examples.commons.entities.Mobile2;
11+
import br.com.somejava8examples.commons.entities.ScreenResolution;
712

813
@Service
914
public class MobileService {
10-
public int getMobileScreenWidth(Mobile mobile) {
11-
if (mobile != null) {
12-
DisplayFeatures dfeatures = mobile.getDisplayFeatures();
13-
if (dfeatures != null) {
14-
ScreenResolution resolution = dfeatures.getResolution();
15-
if (resolution != null) {
16-
return resolution.getWidth();
17-
}
18-
}
19-
}
20-
return 0;
21-
}
2215

23-
public Integer getMobileScreenWidth(Optional<Mobile2> mobile) {
24-
return mobile.flatMap(Mobile2::getDisplayFeatures2)
25-
.flatMap(DisplayFeatures2::getResolution)
26-
.map(ScreenResolution::getWidth)
27-
.orElse(0);
16+
public int getMobileScreenWidth(Mobile mobile) {
17+
if (mobile != null) {
18+
DisplayFeatures dfeatures = mobile.getDisplayFeatures();
19+
if (dfeatures != null) {
20+
ScreenResolution resolution = dfeatures.getResolution();
21+
if (resolution != null) {
22+
return resolution.getWidth();
23+
}
24+
}
25+
}
26+
return 0;
27+
}
2828

29-
}
29+
public Integer getMobileScreenWidth(Optional<Mobile2> mobile) {
30+
return mobile.flatMap(Mobile2::getDisplayFeatures2).flatMap(DisplayFeatures2::getResolution)
31+
.map(ScreenResolution::getWidth).orElse(0);
32+
}
3033

3134
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package br.com.somejava8examples;
2+
3+
import org.junit.jupiter.api.AfterAll;
4+
import org.junit.jupiter.api.AfterEach;
5+
import org.junit.jupiter.api.BeforeAll;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.test.context.ActiveProfiles;
10+
11+
@SpringBootTest
12+
@ActiveProfiles("test")
13+
class SomeJava8ExamplesApplicationTest {
14+
15+
@BeforeAll
16+
static void setUpBeforeClass() throws Exception {
17+
}
18+
19+
@AfterAll
20+
static void tearDownAfterClass() throws Exception {
21+
}
22+
23+
@BeforeEach
24+
void setUp() throws Exception {
25+
}
26+
27+
@AfterEach
28+
void tearDown() throws Exception {
29+
}
30+
31+
@Test
32+
void testMain() {
33+
SomeJava8ExamplesApplication.main(new String[] {});
34+
}
35+
36+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package br.com.somejava8examples.commons.entities;
2+
3+
import static org.junit.Assert.assertNotNull;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.test.context.ActiveProfiles;
10+
11+
@SpringBootTest
12+
@ActiveProfiles("test")
13+
class HostingTest {
14+
15+
private Hosting hosting;
16+
17+
@BeforeEach
18+
void setUp() throws Exception {
19+
hosting = new Hosting(12, "NAME", 23323L);
20+
}
21+
22+
@Test
23+
void testHashCode() {
24+
assertNotNull(hosting.hashCode());
25+
}
26+
27+
@Test
28+
void testHosting() {
29+
assertNotNull(new Hosting(44, "LASKÇDLSAK", 888L));
30+
}
31+
32+
@Test
33+
void testGetId() {
34+
assertNotNull(hosting.getId());
35+
}
36+
37+
@Test
38+
void testSetId() {
39+
hosting.setId(7938);
40+
assertNotNull(hosting.getId());
41+
}
42+
43+
@Test
44+
void testGetName() {
45+
assertNotNull(hosting.getName());
46+
}
47+
48+
@Test
49+
void testSetName() {
50+
hosting.setName("KKKJSJJS");
51+
assertNotNull(hosting.getName());
52+
}
53+
54+
@Test
55+
void testGetWebsites() {
56+
assertNotNull(hosting.getWebsites());
57+
}
58+
59+
@Test
60+
void testSetWebsites() {
61+
hosting.setWebsites(9999L);
62+
assertNotNull(hosting.getWebsites());
63+
}
64+
65+
@Test
66+
void testEqualsObject() {
67+
assertTrue(!hosting.equals(null));
68+
}
69+
70+
@Test
71+
void testEqualsNewObject() {
72+
assertTrue(!hosting.equals(new Object()));
73+
}
74+
75+
@Test
76+
void testEqualsNew() {
77+
assertTrue(!hosting.equals(new Hosting(33, "OOOI", 22299L)));
78+
}
79+
80+
@Test
81+
void testToString() {
82+
assertNotNull(hosting.toString());
83+
}
84+
85+
}

0 commit comments

Comments
 (0)