Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавить checker framework и github action для юнит тестов #541

Merged
merged 56 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d4ef609
add checker framework and unit tests github action
vananiev May 3, 2023
2987e79
add tests badge to README.md
vananiev May 3, 2023
c043c2f
add package-info.java
vananiev May 3, 2023
e2ddb9e
add Nullable to entity classes
vananiev May 4, 2023
590fd88
fix compilation error
vananiev Jan 3, 2024
204340c
replace Nullable annotation
vananiev Jan 3, 2024
efdcf2f
fix controller npe warns
vananiev Jan 3, 2024
8615044
fix unit tests workflow
vananiev Jan 3, 2024
2d4b87b
fix npe warns for TradePof
vananiev Jan 4, 2024
ebb6e12
fix nullable warns
vananiev Jan 6, 2024
0ca774a
update maven-compiler-plugin to fix compilation error
vananiev Sep 29, 2024
8e3cb08
fix nullable warn in api package
vananiev Sep 30, 2024
775ccc7
fix unit tests ci
vananiev Sep 30, 2024
a731556
update jacoco version to 0.8.12
vananiev Sep 30, 2024
6f26abf
fix codecov
vananiev Sep 30, 2024
e6556ff
fix nullness warn in openformat package
vananiev Oct 17, 2024
7086aac
add nullable annotations
vananiev Oct 17, 2024
65c05a6
update broker-report-parser-api
vananiev Oct 21, 2024
eeabbc9
refactor AbstractBrokerReport
vananiev Oct 22, 2024
78a97a9
remove unnecessary annos (idea 2024.2 bug)
vananiev Oct 22, 2024
6d6ba5b
add permit-nullness-assertion-exception.astub
vananiev Oct 27, 2024
c25e8f0
add nullable annos
vananiev Oct 27, 2024
e5f557b
fix checker framework "override.param" warn
vananiev Oct 27, 2024
05d8579
fix null warning on enum
vananiev Oct 27, 2024
959dbf7
fix removal warn
vananiev Oct 27, 2024
964f2d1
fix return checker framework warning
vananiev Oct 27, 2024
d78f5e4
fix type.anno.before.modifier checker framework warning
vananiev Oct 28, 2024
d9b273e
fix type.anno.before.decl.anno checker framework warning
vananiev Oct 28, 2024
ae90efa
remove unnecessary hibernate-jpamodelgen dep (moved to maven-compiler…
vananiev Oct 28, 2024
d60818d
fix "initialization.static.field.uninitialized" checker framework warn
vananiev Oct 28, 2024
d600738
fix "initialization.field.uninitialized" checker framework warn
vananiev Oct 29, 2024
03e899d
close executor service
vananiev Oct 31, 2024
6ee7349
fix "method.invocation" checker framework warn
vananiev Oct 31, 2024
3545b9c
add .idea/misc.xml with nullable annotation configuration
vananiev Nov 1, 2024
e3132a9
fix some "assignment" checker framework warn
vananiev Nov 1, 2024
938b12a
Revert "add .idea/misc.xml with nullable annotation configuration"
vananiev Nov 2, 2024
564ca58
fix remaining "assignment" checker framework warn
vananiev Nov 2, 2024
28abcfb
fix AbstractEntityRepositoryService tests
vananiev Nov 2, 2024
4b50804
fix "unboxing.of.nullable" checker framework warn
vananiev Nov 2, 2024
b51b9c7
fix one "argument" checker framework warn
vananiev Nov 2, 2024
b619ea6
fix all other "argument" checker framework warn
vananiev Nov 3, 2024
f990423
fix "dereference.of.nullable" checker framework warn
vananiev Nov 3, 2024
412776c
impl todo from pom.xml
vananiev Nov 3, 2024
1406ef8
fix checker framework warn for LoadingPageServer
vananiev Nov 3, 2024
69f2fc5
fir idea build
vananiev Nov 3, 2024
217f951
clarify comment
vananiev Nov 3, 2024
b627a28
revert jakarta notnull anno
vananiev Nov 3, 2024
2dc0ebb
refactor SecurityHelper
vananiev Nov 4, 2024
f179b6a
refactor TinkoffSecurityQuoteTable
vananiev Nov 4, 2024
cdb7b80
refactor uralsib CashFlowTable
vananiev Nov 5, 2024
6db9494
revert uralsib CouponAmortizationRedemptionTable logic
vananiev Nov 5, 2024
0d2c3ca
bugfix a2982ff0
vananiev Nov 5, 2024
8f68914
refactor VtbSecurityDepositAndWithdrawalTable
vananiev Nov 6, 2024
4bde784
remove unused code
vananiev Nov 6, 2024
c5409f0
restore jakarta validation annotations
vananiev Nov 6, 2024
43af15a
security description sector allows null
vananiev Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Unit Tests

on:
workflow_dispatch:
pull_request:
branches:
- 'master'
- 'develop'
push:
branches:
- 'master'
- 'develop'

jobs:
tests:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '22'
distribution: 'liberica'
cache: maven

- name: Maven Tests
run: mvn --batch-mode clean test

- name: Test Coverage
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: SonarCloud Analyze
run: >
mvn --batch-mode sonar:sonar
-Dsonar.projectKey=spacious-team_investbook
-Dsonar.organization=spacious-team
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.login=$SONAR_TOKEN
-Dsonar.coverage.jacoco.xmlReportPaths=./target/site/jacoco/jacoco.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[![spring-boot-version](https://img.shields.io/badge/spring--boot-3.3.4-brightgreen?style=flat-square)](https://github.com/spring-projects/spring-boot/releases)
[![hits-of-code](https://img.shields.io/badge/dynamic/json?style=flat-square&color=lightblue&label=hits-of-code&url=https://hitsofcode.com/github/spacious-team/investbook/json?branch=develop&query=$.count)](https://hitsofcode.com/github/spacious-team/investbook/view?branch=develop)
[![github-closed-pull-requests](https://img.shields.io/github/issues-pr-closed/spacious-team/investbook?style=flat-square&color=brightgreen)](https://github.com/spacious-team/investbook/pulls?q=is%3Apr+is%3Aclosed)
[![Unit tests](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fspacious-team%2Finvestbook%2Fbadge%3Fref%3Ddevelop&style=flat-square&label=test&logo=none)](
https://github.com/spacious-team/investbook/actions/workflows/unit-tests.yml)
[![github-workflow-status](https://img.shields.io/github/actions/workflow/status/spacious-team/investbook/publish-docker.yml?style=flat-square&branch=master)](https://github.com/spacious-team/investbook/actions/workflows/publish-docker.yml)
[![github-all-releases](https://img.shields.io/github/downloads/spacious-team/investbook/total?style=flat-square&logo=github&color=lightblue)](https://github.com/spacious-team/investbook/releases/latest)
[![docker-pulls](https://img.shields.io/docker/pulls/spaciousteam/investbook?style=flat-square&logo=docker&color=lightblue&logoColor=white)](https://hub.docker.com/r/spaciousteam/investbook)
Expand Down
76 changes: 76 additions & 0 deletions checkerframework.astub
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* InvestBook
* Copyright (C) 2024 Spacious Team <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;

package java.util;
public class Objects {

@EnsuresNonNull("#1")
static <T> T requireNonNull(@Nullable T obj);

@EnsuresNonNull("#1")
static <T> T requireNonNull(@Nullable T obj, String message);

@EnsuresNonNull("#1")
static <T> T requireNonNull(@Nullable T obj, Supplier<String> messageSupplier);

@EnsuresNonNullIf(expression="#1", result=true)
static boolean nonNull(@Nullable Object obj);

@EnsuresNonNullIf(expression="#1", result=false)
static boolean isNull(@Nullable Object obj);
}


package org.springframework.util;
class StringUtils {

@EnsuresNonNullIf(expression="#1", result=true)
static boolean hasText(@Nullable CharSequence str);

@EnsuresNonNullIf(expression="#1", result=true)
static boolean hasText(@Nullable String str);

@EnsuresNonNullIf(expression="#1", result=true)
static boolean hasLength(@Nullable CharSequence str);

@EnsuresNonNullIf(expression="#1", result=true)
static boolean hasLength(@Nullable String str);
}


package org.springframework.util;
class CollectionUtils {

@EnsuresNonNullIf(expression="#1", result=false)
static boolean isEmpty(@Nullable Collection<?> collection);

@EnsuresNonNullIf(expression="#1", result=false)
static boolean isEmpty(@Nullable Map<?, ?> map);
}


package org.slf4j;
interface Logger {

void warn(String format, @Nullable Object arg1, @Nullable Object arg2);

void warn(String format, @Nullable Object... arguments);
}
124 changes: 117 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@

<properties>
<!-- Valid version is (0-255).(0-255).(0-65535) -->
<win.msi.version>24.2</win.msi.version>
<win.msi.version>24.2</win.msi.version> <!-- TODO: remove dependencyManagement table-wrapper-api before release -->
<java.version>22</java.version>
<lombok.version>1.18.34</lombok.version>
<checkerframework.version>3.48.1</checkerframework.version>
</properties>

<repositories>
Expand All @@ -86,17 +88,23 @@
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<!-- version is same as for hibernate-jpamodelgen dep, just scope is changed -->
<!-- scope is changed, CbrForeignExchangeRateServiceXmlImpl.class requires -->
<scope>compile</scope>
</dependency>
<!-- TODO: remove before release -->
<dependency>
<groupId>com.github.spacious-team</groupId>
<artifactId>table-wrapper-api</artifactId>
<version>f2341ce264</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.github.spacious-team</groupId>
<artifactId>broker-report-parser-api</artifactId>
<version>2024.1</version>
<version>109c37e4a9</version>
</dependency>
<dependency>
<groupId>com.github.spacious-team</groupId>
Expand Down Expand Up @@ -164,10 +172,6 @@
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down Expand Up @@ -209,6 +213,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand All @@ -222,10 +227,95 @@
<artifactId>poi-scratchpad</artifactId>
<version>5.2.5</version> <!-- use same version as table-wrapper-spring-boot-starter provides -->
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<version>${checkerframework.version}</version>
<scope>provided</scope> <!-- for static analysis tools only -->
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.17.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.1</version> <!-- JUnit 5 requirement -->
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork> <!-- Must fork or else JVM arguments are ignored. -->
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.version}</version>
</path>
<path>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>${checkerframework.version}</version>
</path>
</annotationProcessorPaths>
<annotationProcessors>
<annotationProcessor>
lombok.launch.AnnotationProcessorHider$AnnotationProcessor
</annotationProcessor>
<annotationProcessor>
org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
</annotationProcessor>
<annotationProcessor>
org.checkerframework.checker.nullness.NullnessChecker
</annotationProcessor>
</annotationProcessors>
<compilerArgs combine.children="append">
<!--arg>-Awarns</arg-->
<!-- V2022_1_0_1.class нельзя изменять, чтобы не менялась чек сумма миграции -->
<!-- Классы Entity(Pk)?_ сгенерированы hibernate-jpamodelgen -->
<arg>-AskipDefs=(Test$|V2022_1_0_1|Entity(Pk)?_$|generated.ValCurs)</arg>
<!-- Checker framework inner file https://github.com/typetools/checker-framework/blob/master/checker/src/main/java/org/checkerframework/checker/nullness/permit-nullness-assertion-exception.astub -->
<arg>-Astubs=permit-nullness-assertion-exception.astub${path.separator}${project.basedir}/checkerframework.astub</arg>
<arg>-AsuppressWarnings=methodref,type.arguments.not.inferred,lambda.param,expression.unparsable</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down Expand Up @@ -287,6 +377,26 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import jakarta.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -93,7 +94,7 @@
log.error("Can't INSERT by optimized deprecated Hibernate method save(): {}", object, e);
}
}
Boolean result = transactionTemplateRequired.execute(_ -> createIfAbsent(object));
@Nullable Boolean result = transactionTemplateRequired.execute(_ -> createIfAbsent(object));

Check warning on line 97 in src/main/java/ru/investbook/api/AbstractEntityRepositoryService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/ru/investbook/api/AbstractEntityRepositoryService.java#L97

Added line #L97 was not covered by tests
return Boolean.TRUE.equals(result);
}

Expand Down Expand Up @@ -123,14 +124,14 @@
* @implSpec Should be called in transaction
*/
private Optional<Entity> createIfAbsentInternal(Pojo object) {
Entity entity = null;
@Nullable Entity entity = null;
if (repository instanceof ConstraintAwareRepository<Entity, ID> caRepository) {
entity = converter.toEntity(object);
if (caRepository.exists(entity)) {
return Optional.empty();
}
} else {
ID id = getId(object);
@Nullable ID id = getId(object);
if (id != null && existsById(id)) {
return Optional.empty();
}
Expand All @@ -153,13 +154,13 @@
* @implSpec Should be called in transaction
*/
private CreateResult<Pojo> createIfAbsentAndGetInternal(Pojo object) {
Entity entity = null;
@Nullable Entity entity = null;

Check warning on line 157 in src/main/java/ru/investbook/api/AbstractEntityRepositoryService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/ru/investbook/api/AbstractEntityRepositoryService.java#L157

Added line #L157 was not covered by tests
Optional<Entity> selectedEntity;
if (repository instanceof ConstraintAwareRepository<Entity, ID> caRepository) {
entity = converter.toEntity(object);
selectedEntity = caRepository.findBy(entity);
} else {
ID id = getId(object);
@Nullable ID id = getId(object);

Check warning on line 163 in src/main/java/ru/investbook/api/AbstractEntityRepositoryService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/ru/investbook/api/AbstractEntityRepositoryService.java#L163

Added line #L163 was not covered by tests
selectedEntity = Optional.ofNullable(id)
.flatMap(repository::findById);
}
Expand Down
Loading
Loading