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 15cad69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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 15cad69

Please sign in to comment.