Created
May 2, 2019 03:16
-
-
Save cdmunoz/86aca95af2df5d7cc83f36ecdc540ca4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(JUnit4::class) | |
class AuctionCreationViewModelTest { | |
@get:Rule | |
val instantTaskExecutorRule = InstantTaskExecutorRule() | |
lateinit var auctionsCreationViewModel: AuctionsCreationViewModel | |
lateinit var auctionCreationRepository: AuctionCreationRepository | |
val auction = Auction() | |
@Before | |
fun setUp() { | |
auctionCreationRepository = AuctionCreationRepository() | |
auctionsCreationViewModel = AuctionsCreationViewModel() | |
insertAuction() //in order to test the query, we directly insert it | |
} | |
private fun insertAuction() { | |
auction.apply { | |
id = 854L | |
title = "auction1" | |
status = Auction.Status.COMPLETE | |
} | |
auctionCreationRepository.save(Arrays.asList(auction)) | |
} | |
private fun removeAuction() { | |
val auctionsToRemove = mutableListOf<Long>() | |
auctionsToRemove.add(854L) | |
auctionCreationRepository.deleteAuctions(auctionsToRemove, false) | |
} | |
@Test | |
fun queryAuctionById_WithAuctionValue() { | |
auctionsCreationViewModel.queryAuctionById(auction.id) | |
auctionsCreationViewModel.getAuction().observeOnce { | |
assertEquals(auction.id, it.id) | |
} | |
} | |
@Test | |
fun queryAuctionById_WithNoAuctionValue() { | |
removeAuction() | |
auctionsCreationViewModel.queryAuctionById(auction.id) | |
auctionsCreationViewModel.getAuction().observeOnce { | |
assertEquals(it, null) | |
} | |
} | |
@After | |
fun afterTest() { | |
removeAuction() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment