Add AuthorManager#getMyAuthorInfo() without transaction

and add test for it
This commit is contained in:
Torsten Grote
2020-11-24 12:11:36 -03:00
parent 6939d8d230
commit 5aa041f9e1
3 changed files with 26 additions and 1 deletions

View File

@@ -19,6 +19,11 @@ public interface AuthorManager {
*/
AuthorInfo getAuthorInfo(Transaction txn, AuthorId a) throws DbException;
/**
* Returns the {@link AuthorInfo} for the {@link LocalAuthor}.
*/
AuthorInfo getMyAuthorInfo() throws DbException;
/**
* Returns the {@link AuthorInfo} for the {@link LocalAuthor}.
*/

View File

@@ -59,6 +59,11 @@ class AuthorManagerImpl implements AuthorManager {
else return new AuthorInfo(UNVERIFIED, c.getAlias(), avatar);
}
@Override
public AuthorInfo getMyAuthorInfo() throws DbException {
return db.transactionWithResult(true, this::getMyAuthorInfo);
}
@Override
public AuthorInfo getMyAuthorInfo(Transaction txn) throws DbException {
AttachmentHeader avatar = avatarManager.getMyAvatarHeader(txn);

View File

@@ -106,7 +106,6 @@ public class AuthorManagerImplTest extends BrambleMockTestCase {
public void testGetAuthorInfoOurselves() throws DbException {
Transaction txn = new Transaction(null, true);
// check ourselves
context.checking(new Expectations() {{
oneOf(identityManager).getLocalAuthor(txn);
will(returnValue(localAuthor));
@@ -122,6 +121,22 @@ public class AuthorManagerImplTest extends BrambleMockTestCase {
assertEquals(avatarHeader, authorInfo.getAvatarHeader());
}
@Test
public void testGetMyAuthorInfo() throws DbException {
Transaction txn = new Transaction(null, true);
context.checking(new Expectations() {{
oneOf(avatarManager).getMyAvatarHeader(txn);
will(returnValue(avatarHeader));
}});
AuthorInfo authorInfo =
authorManager.getMyAuthorInfo(txn);
assertEquals(OURSELVES, authorInfo.getStatus());
assertNull(authorInfo.getAlias());
assertEquals(avatarHeader, authorInfo.getAvatarHeader());
}
private void checkAuthorInfoContext(Transaction txn, AuthorId authorId,
Collection<Contact> contacts) throws DbException {
context.checking(new Expectations() {{