Skip to content

Commit

Permalink
Feature/upgrade mockito (#172)
Browse files Browse the repository at this point in the history
* Bump mockito.version from 4.6.1 to 5.11.0

Bumps `mockito.version` from 4.6.1 to 5.11.0.

Updates `org.mockito:mockito-core` from 4.6.1 to 5.11.0
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v4.6.1...v5.11.0)

Updates `org.mockito:mockito-junit-jupiter` from 4.6.1 to 5.11.0
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v4.6.1...v5.11.0)

---
updated-dependencies:
- dependency-name: org.mockito:mockito-core
  dependency-type: direct:development
  update-type: version-update:semver-major
- dependency-name: org.mockito:mockito-junit-jupiter
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* [issue-#171] - upgrade Mockito

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
finnyb and dependabot[bot] authored Mar 16, 2024
1 parent a4f2d6a commit fd3722d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 54 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<junit.jupiter.version>5.10.2</junit.jupiter.version>
<mockito.version>4.6.1</mockito.version>
<mockito.version>5.11.0</mockito.version>
<sonar.projectKey>finnyb_javampd</sonar.projectKey>
<sonar.organization>finnyb</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/bff/javampd/player/MPDPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.bff.javampd.playlist.MPDPlaylistSong;
import org.bff.javampd.playlist.PlaylistSongConverter;
import org.bff.javampd.server.ServerStatus;
import org.bff.javampd.song.SongConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -39,7 +38,6 @@ public MPDPlayer(
ServerStatus serverStatus,
PlayerProperties playerProperties,
CommandExecutor commandExecutor,
SongConverter songConverter,
PlaylistSongConverter playlistSongConverter) {
this.serverStatus = serverStatus;
this.playerProperties = playerProperties;
Expand Down
102 changes: 51 additions & 51 deletions src/test/java/org/bff/javampd/player/MPDPlayerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.*;

Expand All @@ -13,34 +14,41 @@
import org.bff.javampd.playlist.MPDPlaylistSong;
import org.bff.javampd.playlist.PlaylistSongConverter;
import org.bff.javampd.server.ServerStatus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class MPDPlayerTest {

@Mock private ServerStatus serverStatus;
@Mock private PlayerProperties playerProperties;
private PlayerProperties playerProperties;

@Mock private CommandExecutor commandExecutor;

@Mock private PlaylistSongConverter playlistSongConverter;

@InjectMocks private MPDPlayer mpdPlayer;
private MPDPlayer mpdPlayer;

@Captor private ArgumentCaptor<String> stringArgumentCaptor;

@Captor private ArgumentCaptor<Integer> integerArgumentCaptor;

@Captor private ArgumentCaptor<String> paramArgumentCaptor;

@BeforeEach
void setUp() {
this.playerProperties = new PlayerProperties();
this.mpdPlayer =
new MPDPlayer(serverStatus, playerProperties, commandExecutor, playlistSongConverter);
}

@Test
void testGetCurrentSong() {
List<String> responseList = new ArrayList<>();
Expand All @@ -52,7 +60,6 @@ void testGetCurrentSong() {
List<MPDPlaylistSong> testSongResponse = new ArrayList<>();
testSongResponse.add(testSong);

when(playerProperties.getCurrentSong()).thenCallRealMethod();
when(commandExecutor.sendCommand(playerProperties.getCurrentSong())).thenReturn(responseList);
when(playlistSongConverter.convertResponseToSongs(responseList)).thenReturn(testSongResponse);

Expand All @@ -71,7 +78,6 @@ void testGetCurrentSongEmpty() {
var responseList = new ArrayList<String>();
var testSongResponse = new ArrayList<MPDPlaylistSong>();

when(playerProperties.getCurrentSong()).thenCallRealMethod();
when(commandExecutor.sendCommand(playerProperties.getCurrentSong())).thenReturn(responseList);

when(playlistSongConverter.convertResponseToSongs(responseList)).thenReturn(testSongResponse);
Expand All @@ -81,7 +87,6 @@ void testGetCurrentSongEmpty() {

@Test
void testPlay() {
when(playerProperties.getPlay()).thenCallRealMethod();
mpdPlayer.play();
verify(commandExecutor).sendCommand(stringArgumentCaptor.capture());
assertThat(stringArgumentCaptor.getValue(), is(equalTo((playerProperties.getPlay()))));
Expand All @@ -95,7 +100,6 @@ void testPlaySong() {
MPDPlaylistSong testSong =
MPDPlaylistSong.builder().file(testFile).title(testTitle).id(id).build();

when(playerProperties.getPlayId()).thenCallRealMethod();
mpdPlayer.playSong(testSong);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), integerArgumentCaptor.capture());
Expand All @@ -122,21 +126,35 @@ void testSeek() {
List<MPDPlaylistSong> testSongResponse = new ArrayList<>();
testSongResponse.add(testSong);

when(playerProperties.getCurrentSong()).thenCallRealMethod();
when(commandExecutor.sendCommand(playerProperties.getCurrentSong())).thenReturn(responseList);
when(playlistSongConverter.convertResponseToSongs(responseList)).thenReturn(testSongResponse);

when(playerProperties.getSeekId()).thenCallRealMethod();
mpdPlayer.seek(seconds);

verify(commandExecutor).sendCommand(stringArgumentCaptor.capture());
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), paramArgumentCaptor.capture());

assertThat(stringArgumentCaptor.getValue(), is(equalTo((playerProperties.getSeekId()))));
assertThat(
paramArgumentCaptor.getAllValues().get(0),
is(equalTo((Integer.toString(testSong.getId())))));
assertThat(paramArgumentCaptor.getAllValues().get(1), is(equalTo((Integer.toString(seconds)))));
.sendCommand(
stringArgumentCaptor.capture(),
paramArgumentCaptor.capture(),
paramArgumentCaptor.capture());

assertAll(
() ->
assertThat(
stringArgumentCaptor.getAllValues().get(0),
is(equalTo((playerProperties.getCurrentSong())))),
() ->
assertThat(
stringArgumentCaptor.getAllValues().get(1),
is(equalTo((playerProperties.getSeekId())))),
() ->
assertThat(
paramArgumentCaptor.getAllValues().get(0),
is(equalTo((Integer.toString(testSong.getId()))))),
() ->
assertThat(
paramArgumentCaptor.getAllValues().get(1),
is(equalTo((Integer.toString(seconds))))));
}

@Test
Expand All @@ -158,7 +176,6 @@ void testSeekSongLengthLessThanRequest() {
List<MPDPlaylistSong> testSongResponse = new ArrayList<>();
testSongResponse.add(testSong);

when(playerProperties.getCurrentSong()).thenCallRealMethod();
when(commandExecutor.sendCommand(playerProperties.getCurrentSong())).thenReturn(responseList);
when(playlistSongConverter.convertResponseToSongs(responseList)).thenReturn(testSongResponse);

Expand All @@ -183,25 +200,33 @@ void testSeekSong() {
.length(seconds + 1)
.build();

when(playerProperties.getSeekId()).thenCallRealMethod();
mpdPlayer.seekSong(testSong, seconds);

verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), paramArgumentCaptor.capture());

assertThat(stringArgumentCaptor.getValue(), is(equalTo((playerProperties.getSeekId()))));
assertThat(
paramArgumentCaptor.getAllValues().get(0),
is(equalTo((Integer.toString(testSong.getId())))));
assertThat(paramArgumentCaptor.getAllValues().get(1), is(equalTo((Integer.toString(seconds)))));
.sendCommand(
stringArgumentCaptor.capture(),
paramArgumentCaptor.capture(),
paramArgumentCaptor.capture());

assertAll(
() ->
assertThat(
stringArgumentCaptor.getValue(), is(equalTo((playerProperties.getSeekId())))),
() ->
assertThat(
paramArgumentCaptor.getAllValues().get(0),
is(equalTo((Integer.toString(testSong.getId()))))),
() ->
assertThat(
paramArgumentCaptor.getAllValues().get(1),
is(equalTo((Integer.toString(seconds))))));
}

@Test
void testPlayerChangeEventStarted() {
final PlayerChangeEvent.Event[] playerChangeEvent = {null};
mpdPlayer.addPlayerChangeListener(event -> playerChangeEvent[0] = event.getEvent());

when(playerProperties.getPlay()).thenCallRealMethod();
mpdPlayer.play();

assertThat(playerChangeEvent[0], is(equalTo((PlayerChangeEvent.Event.PLAYER_STARTED))));
Expand All @@ -214,8 +239,6 @@ void testPlayerChangeEventSongSet() {

MPDPlaylistSong testSong = MPDPlaylistSong.builder().file("").title("").build();

when(playerProperties.getPlay()).thenCallRealMethod();
when(playerProperties.getPlayId()).thenCallRealMethod();
mpdPlayer.play();
mpdPlayer.playSong(testSong);

Expand All @@ -230,12 +253,10 @@ void testRemovePlayerChangedListener() {

mpdPlayer.addPlayerChangeListener(playerChangeListener);

when(playerProperties.getPlay()).thenCallRealMethod();
mpdPlayer.play();

assertThat(playerChangeEvent[0], is(equalTo((PlayerChangeEvent.Event.PLAYER_STARTED))));

when(playerProperties.getStop()).thenCallRealMethod();
mpdPlayer.stop();
assertThat(playerChangeEvent[0], is(equalTo((PlayerChangeEvent.Event.PLAYER_STOPPED))));

Expand All @@ -246,39 +267,34 @@ void testRemovePlayerChangedListener() {

@Test
void testStop() {
when(playerProperties.getStop()).thenCallRealMethod();
mpdPlayer.stop();
verify(commandExecutor).sendCommand(stringArgumentCaptor.capture());
assertThat(stringArgumentCaptor.getValue(), is(equalTo((playerProperties.getStop()))));
}

@Test
void testPause() {
when(playerProperties.getPause()).thenCallRealMethod();
mpdPlayer.pause();
verify(commandExecutor).sendCommand(stringArgumentCaptor.capture());
assertThat(stringArgumentCaptor.getValue(), is(equalTo((playerProperties.getPause()))));
}

@Test
void testPlayNext() {
when(playerProperties.getNext()).thenCallRealMethod();
mpdPlayer.playNext();
verify(commandExecutor).sendCommand(stringArgumentCaptor.capture());
assertThat(stringArgumentCaptor.getValue(), is(equalTo((playerProperties.getNext()))));
}

@Test
void testPlayPrevious() {
when(playerProperties.getPrevious()).thenCallRealMethod();
mpdPlayer.playPrevious();
verify(commandExecutor).sendCommand(stringArgumentCaptor.capture());
assertThat(stringArgumentCaptor.getValue(), is(equalTo((playerProperties.getPrevious()))));
}

@Test
void testMute() {
when(playerProperties.getSetVolume()).thenCallRealMethod();
mpdPlayer.mute();
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), integerArgumentCaptor.capture());
Expand All @@ -288,7 +304,6 @@ void testMute() {

@Test
void testUnMute() {
when(playerProperties.getSetVolume()).thenCallRealMethod();
mpdPlayer.setVolume(1);
mpdPlayer.unMute();
verify(commandExecutor, times(2))
Expand All @@ -303,7 +318,6 @@ void testAddVolumeChangeListener() {
final VolumeChangeEvent[] volumeChangeEvent = {null};
mpdPlayer.addVolumeChangeListener(event -> volumeChangeEvent[0] = event);

when(playerProperties.getSetVolume()).thenCallRealMethod();
mpdPlayer.setVolume(5);

assertThat(volumeChangeEvent[0].getVolume(), is(equalTo((5))));
Expand All @@ -314,7 +328,6 @@ void testAddVolumeChangeListenerOutOfRange() {
final VolumeChangeEvent[] volumeChangeEvent = {null};
mpdPlayer.addVolumeChangeListener(event -> volumeChangeEvent[0] = event);

when(playerProperties.getSetVolume()).thenCallRealMethod();
mpdPlayer.setVolume(0);
mpdPlayer.setVolume(101);

Expand All @@ -329,7 +342,6 @@ void testRemoveVolumeChangedListener() {

mpdPlayer.addVolumeChangeListener(volumeChangeListener);

when(playerProperties.getSetVolume()).thenCallRealMethod();
mpdPlayer.setVolume(5);

assertThat(volumeChangeEvent[0].getVolume(), (is(equalTo((5)))));
Expand All @@ -342,7 +354,6 @@ void testRemoveVolumeChangedListener() {

@Test
void testRandomizePlay() {
when(playerProperties.getRandom()).thenCallRealMethod();
mpdPlayer.randomizePlay();
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), stringArgumentCaptor.capture());
Expand All @@ -353,7 +364,6 @@ void testRandomizePlay() {

@Test
void testUnrandomizePlay() {
when(playerProperties.getRandom()).thenCallRealMethod();
mpdPlayer.unRandomizePlay();
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), stringArgumentCaptor.capture());
Expand All @@ -365,7 +375,6 @@ void testUnrandomizePlay() {

@Test
void testSetRandomTrue() {
when(playerProperties.getRandom()).thenCallRealMethod();
mpdPlayer.setRandom(true);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), stringArgumentCaptor.capture());
Expand All @@ -376,7 +385,6 @@ void testSetRandomTrue() {

@Test
void testSetRandomFalse() {
when(playerProperties.getRandom()).thenCallRealMethod();
mpdPlayer.setRandom(false);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), stringArgumentCaptor.capture());
Expand All @@ -393,7 +401,6 @@ void testIsRandom() {

@Test
void testSetRepeatTrue() {
when(playerProperties.getRepeat()).thenCallRealMethod();
mpdPlayer.setRepeat(true);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), stringArgumentCaptor.capture());
Expand All @@ -404,7 +411,6 @@ void testSetRepeatTrue() {

@Test
void testSetRepeatFalse() {
when(playerProperties.getRepeat()).thenCallRealMethod();
mpdPlayer.setRepeat(false);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), stringArgumentCaptor.capture());
Expand Down Expand Up @@ -433,7 +439,6 @@ void testGetVolume() {

@Test
void testSetVolume() {
when(playerProperties.getSetVolume()).thenCallRealMethod();
mpdPlayer.setVolume(0);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), integerArgumentCaptor.capture());
Expand Down Expand Up @@ -463,7 +468,6 @@ void testGetXFade() {

@Test
void testSetXFade() {
when(playerProperties.getXFade()).thenCallRealMethod();
mpdPlayer.setXFade(5);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), integerArgumentCaptor.capture());
Expand All @@ -474,7 +478,6 @@ void testSetXFade() {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void testSetSingle(boolean single) {
when(playerProperties.getSingle()).thenCallRealMethod();
mpdPlayer.setSingle(single);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), stringArgumentCaptor.capture());
Expand All @@ -486,7 +489,6 @@ void testSetSingle(boolean single) {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void testSetConsume(boolean consume) {
when(playerProperties.getConsume()).thenCallRealMethod();
mpdPlayer.setConsume(consume);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), stringArgumentCaptor.capture());
Expand All @@ -498,7 +500,6 @@ void testSetConsume(boolean consume) {
@ParameterizedTest
@ValueSource(ints = {5, -5})
void testSetMixRampDb(int db) {
when(playerProperties.getMixRampDb()).thenCallRealMethod();
mpdPlayer.setMixRampDb(db);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), integerArgumentCaptor.capture());
Expand All @@ -510,7 +511,6 @@ void testSetMixRampDb(int db) {
@ParameterizedTest
@ValueSource(ints = {5, 0, -5})
void testSetMixRampDelay(int delay) {
when(playerProperties.getMixRampDelay()).thenCallRealMethod();
mpdPlayer.setMixRampDelay(delay);
verify(commandExecutor)
.sendCommand(stringArgumentCaptor.capture(), stringArgumentCaptor.capture());
Expand Down

0 comments on commit fd3722d

Please sign in to comment.