Switched to Mockito rather than manually written mock class.
This commit is contained in:
parent
1b51ce467b
commit
086e56548c
6
pom.xml
6
pom.xml
@ -115,6 +115,12 @@
|
|||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>2.6.5</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.1stleg</groupId>
|
<groupId>com.1stleg</groupId>
|
||||||
<artifactId>jnativehook</artifactId>
|
<artifactId>jnativehook</artifactId>
|
||||||
|
@ -7,6 +7,11 @@ import org.jaudiotagger.tag.Tag;
|
|||||||
import org.jaudiotagger.tag.id3.ID3v23Tag;
|
import org.jaudiotagger.tag.id3.ID3v23Tag;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -17,10 +22,14 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class HibernateDatabaseTest {
|
public class HibernateDatabaseTest {
|
||||||
|
|
||||||
private IDatabase database;
|
private IDatabase database;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
ILibrary library;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp(){
|
public void setUp(){
|
||||||
database = new HibernateDatabase(true);
|
database = new HibernateDatabase(true);
|
||||||
@ -222,41 +231,8 @@ public class HibernateDatabaseTest {
|
|||||||
Path dir = new File(HibernateDatabaseTest.class.getResource("/sample.mp3").getFile()).getParentFile().toPath();
|
Path dir = new File(HibernateDatabaseTest.class.getResource("/sample.mp3").getFile()).getParentFile().toPath();
|
||||||
List<Path> dirList = new ArrayList<>();
|
List<Path> dirList = new ArrayList<>();
|
||||||
dirList.add(dir);
|
dirList.add(dir);
|
||||||
FakeLibrary library = new FakeLibrary(database);
|
|
||||||
database.processSongsWithCallback(library, dirList);
|
database.processSongsWithCallback(library, dirList);
|
||||||
assertEquals(1, database.listAllT(Song.class).get().size());
|
assertEquals(1, database.listAllT(Song.class).get().size());
|
||||||
assertTrue(library.success);
|
verify(library).libraryUpdated();
|
||||||
assertFalse(library.failed);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class FakeLibrary extends ILibrary{
|
|
||||||
|
|
||||||
public boolean success = false;
|
|
||||||
public boolean failed = false;
|
|
||||||
|
|
||||||
public FakeLibrary(IDatabase database) {
|
|
||||||
super(database);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void showSongs() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends HasSongs & Comparable<T>> void showGroupedSongs(Class<T> grouping) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateLibrary() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshLibrary() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void libraryUpdateFailed(String message) { failed = true;}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void libraryUpdated() { success = true;}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void currentlyUpdating(String name) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user