├── .circleci └── config.yml ├── .github ├── dependabot.yml └── workflows │ ├── ci.yml │ └── enforce-license-compliance.yml ├── .gitignore ├── .travis.yml ├── LICENSE.md ├── README.md ├── pom.xml └── src ├── main └── java │ └── calculator │ └── Calculator.java └── test └── java └── calculator └── CalculatorTest.java /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | orbs: 3 | codecov: codecov/codecov@3 4 | 5 | jobs: 6 | build: 7 | docker: 8 | - image: cimg/openjdk:18.0.2 9 | steps: 10 | - checkout 11 | - run: 12 | name: Install dependencies 13 | command: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V 14 | - run: 15 | name: Run tests and collect coverage 16 | command: mvn -B test 17 | - codecov/upload 18 | 19 | workflow: 20 | version: 2.1 21 | build-test: 22 | jobs: 23 | - build 24 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: maven 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Workflow for Codecov example-java-maven 2 | on: [push, pull_request] 3 | jobs: 4 | run: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Checkout 8 | uses: actions/checkout@v4 9 | - name: Set up JDK 18 10 | uses: actions/setup-java@v1 11 | with: 12 | java-version: 18 13 | - name: Install dependencies 14 | run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V 15 | - name: Run tests and collect coverage 16 | run: mvn -B test 17 | - name: Upload coverage to Codecov 18 | uses: codecov/codecov-action@v5 19 | env: 20 | CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} 21 | -------------------------------------------------------------------------------- /.github/workflows/enforce-license-compliance.yml: -------------------------------------------------------------------------------- 1 | name: Enforce License Compliance 2 | 3 | on: 4 | pull_request: 5 | branches: [main, master] 6 | 7 | jobs: 8 | enforce-license-compliance: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: 'Enforce License Compliance' 12 | uses: getsentry/action-enforce-license-compliance@57ba820387a1a9315a46115ee276b2968da51f3d # main 13 | with: 14 | fossa_api_key: ${{ secrets.FOSSA_API_KEY }} 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | # Cobertura is not supported in JDK11 so you must downgrade the JDK that Travis uses if you want to use Cobertura with Travis. 4 | # https://github.com/cobertura/cobertura/issues/381 5 | jdk: 6 | - openjdk8 7 | 8 | sudo: false # faster builds 9 | 10 | script: "mvn cobertura:cobertura" 11 | 12 | after_success: 13 | - bash <(curl -s https://codecov.io/bash) 14 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Codecov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Codecov](https://codecov.io) Java Maven Example 2 | [![codecov](https://codecov.io/github/codecov/example-java-maven/branch/main/graph/badge.svg?token=ob1cArXXM6)](https://app.codecov.io/github/codecov/example-java-maven) 3 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java-maven.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java-maven?ref=badge_shield) 4 | 5 | This example repository shows how Codecov can be integrated with a simple java-maven project. It uses **GitHub Actions** and **CircleCI** as CI/CD providers and **Jacoco** as the coverage provider. 6 | 7 | For more information, please see the links below. 8 | 9 | ## Links 10 | - [Quick Start](https://docs.codecov.com/docs/quick-start) 11 | - [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial) 12 | - [Community Boards](https://community.codecov.io) 13 | - [Support](https://codecov.io/support) 14 | - [Documentation](https://docs.codecov.io) 15 | 16 | 17 | ## License 18 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java-maven.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-java-maven?ref=badge_large) 19 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | io.codecov 6 | example-java 7 | 1.0 8 | 9 | Codecov example Java repository 10 | http://github.com/codecov/example-java 11 | 12 | 18 13 | 18 14 | UTF-8 15 | 16 | 17 | 18 | 19 | junit 20 | junit 21 | 4.13.2 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.jacoco 30 | jacoco-maven-plugin 31 | 0.8.13 32 | 33 | 34 | prepare-agent 35 | 36 | prepare-agent 37 | 38 | 39 | 40 | report 41 | test 42 | 43 | report 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/main/java/calculator/Calculator.java: -------------------------------------------------------------------------------- 1 | package calculator; 2 | 3 | public class Calculator { 4 | public static double add(double x, double y) { 5 | return x + y; 6 | } 7 | 8 | public static double subtract(double x, double y) { 9 | return x - y; 10 | } 11 | 12 | public static double multiply(double x, double y) { 13 | return x * y; 14 | } 15 | 16 | public static double divide(double x, double y) { 17 | if (y == 0) { 18 | System.out.println("Cannot divide by 0"); 19 | return 0; 20 | } 21 | return x / y; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/calculator/CalculatorTest.java: -------------------------------------------------------------------------------- 1 | package calculator; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | public class CalculatorTest { 8 | private static final double DELTA = 0.001; 9 | 10 | @Test 11 | public void testAdd() { 12 | assertEquals(Calculator.add(1, 2), 3.0, DELTA); 13 | assertEquals(Calculator.add(1.0, 2.0), 3.0, DELTA); 14 | assertEquals(Calculator.add(0, 2.0), 2.0, DELTA); 15 | assertEquals(Calculator.add(2.0, 0), 2.0, DELTA); 16 | assertEquals(Calculator.add(-4, 2.0), -2.0, DELTA); 17 | } 18 | 19 | @Test 20 | public void testSubtract() { 21 | assertEquals(Calculator.subtract(1, 2), -1.0, DELTA); 22 | assertEquals(Calculator.subtract(2, 1), 1.0, DELTA); 23 | assertEquals(Calculator.subtract(1.0, 2.0), -1.0, DELTA); 24 | assertEquals(Calculator.subtract(0, 2.0), -2.0, DELTA); 25 | assertEquals(Calculator.subtract(2.0, 0), 2.0, DELTA); 26 | assertEquals(Calculator.subtract(-4, 2.0), -6.0, DELTA); 27 | } 28 | 29 | @Test 30 | public void testMultiply() { 31 | assertEquals(Calculator.multiply(1, 2), 2.0, DELTA); 32 | assertEquals(Calculator.multiply(1.0, 2.0), 2.0, DELTA); 33 | assertEquals(Calculator.multiply(0, 2.0), 0.0, DELTA); 34 | assertEquals(Calculator.multiply(2.0, 0), 0.0, DELTA); 35 | assertEquals(Calculator.multiply(-4, 2.0), -8.0, DELTA); 36 | } 37 | 38 | @Test 39 | public void testDivide() { 40 | assertEquals(Calculator.divide(1, 2), 0.5, DELTA); 41 | assertEquals(Calculator.divide(1.0, 2.0), 0.5, DELTA); 42 | assertEquals(Calculator.divide(0, 2.0), 0, DELTA); 43 | assertEquals(Calculator.divide(-4, 2.0), -2.0, DELTA); 44 | // assertEquals(Calculator.divide(2.0, 0), 0.0, DELTA); 45 | } 46 | } 47 | --------------------------------------------------------------------------------