Test that uncovered the NPE fixed in last commit

This commit is contained in:
Paul Schaub 2019-12-26 08:48:38 +01:00
parent 6cb9ce5362
commit 86c16f32bf
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -6,6 +6,10 @@ import org.mercury_im.messenger.data.di.InMemoryDatabaseComponent;
import org.mercury_im.messenger.entity.Account;
import org.mercury_im.messenger.entity.IAccount;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.inject.Inject;
import io.reactivex.disposables.CompositeDisposable;
@ -14,6 +18,8 @@ import io.requery.reactivex.ReactiveEntityStore;
public class AccountRepositoryTest {
private static final Logger LOGGER = Logger.getLogger(AccountRepositoryTest.class.getName());
@Inject
ReactiveEntityStore<Persistable> dataStore;
@ -78,4 +84,37 @@ public class AccountRepositoryTest {
Thread.sleep(100);
}
@Test
public void observeDeletionTest() throws InterruptedException {
CompositeDisposable d = new CompositeDisposable();
UUID uuid = UUID.randomUUID();
d.add(accountRepository.observeAccount(uuid)
.subscribe(optAccount -> {
LOGGER.log(Level.INFO, "Changed");
if (!optAccount.isPresent()) {
LOGGER.log(Level.INFO, "Changed: Account " + uuid.toString() + " is not present.");
} else {
LOGGER.log(Level.INFO, "Changed: Account " + uuid.toString() + ": " + optAccount.getItem().toString());
}
}));
Account account = new IAccount(uuid);
account.setEnabled(true);
account.setAddress("hello@world");
account.setPassword("wooooooh");
d.add(accountRepository.insertAccount(account)
.subscribe(insert -> LOGGER.log(Level.INFO, "Inserted."),
error -> LOGGER.log(Level.SEVERE, "Inserted", error)));
Thread.sleep(100);
d.add(accountRepository.deleteAccount(uuid)
.subscribe(() -> LOGGER.log(Level.INFO, "Deleted")));
Thread.sleep(1000);
d.dispose();
}
}