Skip to content

Commit

Permalink
Solves sonar: Only one method invocation is expected when testing run…
Browse files Browse the repository at this point in the history
…time exceptions
  • Loading branch information
damianszczepanik committed Jan 1, 2024
1 parent 5603807 commit 9bd987d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- package
# do not validate pull requests because SONAR_TOKEN is available only for project owner

jobs:
Expand All @@ -21,7 +22,7 @@ jobs:
distribution: adopt

- name: Build with Maven
run: mvn --batch-mode package sonar:sonar -Dsonar.projectKey=damianszczepanik_silencio -Dsonar.organization=damianszczepanik -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN
run: mvn --batch-mode package sonar:sonar -Dsonar.projectKey=damianszczepanik_silencio -Dsonar.organization=damianszczepanik -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=$SONAR_TOKEN
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
7 changes: 5 additions & 2 deletions src/test/java/pl/szczepanik/silencio/utils/IOUtilityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ void shouldFailOnIOException() throws Exception {

String errorMessage = "Something is wrong!";

// given
URL url = new URL(URL_ADDRESS);

// when
when(IOUtils.toString(new URL(URL_ADDRESS), StandardCharsets.UTF_8))
when(IOUtils.toString(url, StandardCharsets.UTF_8))
.thenThrow(new IOException(errorMessage));

// then
assertThatThrownBy(() -> IOUtility.urlToString(new URL(URL_ADDRESS)))
assertThatThrownBy(() -> IOUtility.urlToString(url))
.isInstanceOf(IntegrityException.class)
.hasMessage(errorMessage);
}
Expand Down

0 comments on commit 9bd987d

Please sign in to comment.