|
2 | 2 |
|
3 | 3 | import android.content.Context;
|
4 | 4 |
|
| 5 | +import androidx.room.Room; |
5 | 6 | import androidx.test.core.app.ApplicationProvider;
|
6 | 7 |
|
7 | 8 | import org.junit.Before;
|
|
12 | 13 | import java.util.List;
|
13 | 14 |
|
14 | 15 | import ro.tav.pavgame.data.GameEntity;
|
| 16 | +import ro.tav.pavgame.data.localDB.AppDatabase; |
| 17 | +import ro.tav.pavgame.data.localDB.GameDao; |
15 | 18 | import ro.tav.pavgame.domain.GameRemoteRepository;
|
| 19 | +import ro.tav.pavgame.domain.GameUseCase; |
16 | 20 |
|
17 | 21 | @RunWith( RobolectricTestRunner.class )
|
18 | 22 |
|
19 | 23 | //@RunWith( AndroidJUnit4.class )
|
20 | 24 | public class jUnitTests {
|
21 |
| - // private GameDao gameDao; |
22 |
| -// private AppDatabase db; |
| 25 | + |
23 | 26 | Context context;
|
24 | 27 | GameEntity mGame;
|
25 | 28 |
|
@@ -48,52 +51,31 @@ public void test1() {
|
48 | 51 | assert ok;
|
49 | 52 | }
|
50 | 53 |
|
51 |
| -// @Test |
52 |
| -// public void test2() { |
53 |
| -// GameUseCase gameUseCase = new GameUseCase(ApplicationProvider.getApplicationContext()); |
54 |
| -// gameUseCase.insertGame( mGame ); |
55 |
| -// GameRemoteRepository gameRemoteRepository = new GameRemoteRepository(); |
56 |
| -// List < GameEntity > l = gameRemoteRepository.getAllGames(); |
57 |
| -// boolean ok = false; |
58 |
| -// for ( GameEntity gameEntity : l ) { |
59 |
| -// if ( gameEntity.equals( mGame ) ) { |
60 |
| -// ok = true; |
61 |
| -// break; |
62 |
| -// } |
63 |
| -// } |
64 |
| -// assert ok; |
65 |
| -// } |
66 |
| -// |
67 |
| -// @Test |
68 |
| -// public void test3() { |
69 |
| -// db = Room.inMemoryDatabaseBuilder( context, AppDatabase.class ).allowMainThreadQueries().build(); |
70 |
| -// gameDao = db.gameDao(); |
71 |
| -// gameDao.insertGame( mGame ); |
72 |
| -// |
73 |
| -// AppDatabase.databaseWriteExecutor.execute( new Runnable() { |
74 |
| -// @Override |
75 |
| -// public void run() { |
76 |
| -// gameDao.insertGame( mGame ); |
77 |
| -// } |
78 |
| -// } ); |
79 |
| -// PavGameApplication pavGameApplication = mock(PavGameApplication.class); |
80 |
| -// GameLocalRepository gameLocalRepository = new GameLocalRepository(context); |
81 |
| -// |
| 54 | + @Test |
| 55 | + public void test2() { |
| 56 | + AppDatabase db = Room.inMemoryDatabaseBuilder( context, AppDatabase.class ).allowMainThreadQueries().build(); |
| 57 | + GameDao gameDao = db.gameDao(); |
| 58 | + gameDao.insertGame( mGame ); |
| 59 | + |
| 60 | + List < GameEntity > l = gameDao.getSpecificGamesbyUserNameStatic( "myTest" ); |
| 61 | + |
| 62 | + try { |
| 63 | + assert !l.isEmpty(); |
| 64 | + } catch ( Exception e ) { |
| 65 | + assert false; |
| 66 | + } |
| 67 | + db.close(); |
| 68 | + } |
| 69 | + |
| 70 | + @Test //TODO |
| 71 | + public void test3() { |
| 72 | +// GameLocalRepository gameLocalRepository = new GameLocalRepository( ApplicationProvider.getApplicationContext() ); |
82 | 73 | // gameLocalRepository.insertGame( mGame );
|
83 |
| -// List < GameEntity > l = gameLocalRepository.getAllGames().getValue(); |
84 |
| -// try { |
85 |
| -// Boolean ok = false; |
86 |
| -// for ( GameEntity gameEntity : l ) { |
87 |
| -// if ( gameEntity.equals( mGame ) ) { |
88 |
| -// ok = true; |
89 |
| -// } |
90 |
| -// } |
91 |
| -// db.close(); |
92 |
| -// assert ok; |
93 |
| -// } catch ( Exception e ) { |
94 |
| -// assert false; |
95 |
| -// } |
96 |
| -// assert gameDao.getSpecificGamesbyUserName( "myTest" ).getValue().isEmpty(); |
97 |
| -// } |
| 74 | +// List < GameEntity > l = gameLocalRepository.getSpecificGamesbyUserNameStatic( "myTest" ); |
| 75 | + GameUseCase gameUseCase = new GameUseCase( ApplicationProvider.getApplicationContext() ); |
| 76 | + gameUseCase.insertGame( mGame ); |
| 77 | + List < GameEntity > l = gameUseCase.getSpecificGamesbyUserNameStatic( "myTest" ); |
| 78 | + assert !l.isEmpty(); |
| 79 | + } |
98 | 80 | }
|
99 | 81 |
|
0 commit comments