Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
briar
Commits
a9ddb001
Verified
Commit
a9ddb001
authored
8 years ago
by
Torsten Grote
Browse files
Options
Downloads
Patches
Plain Diff
Add missing IdentityManager unit tests
parent
2d7cb7b2
No related branches found
No related tags found
1 merge request
!440
Add missing IdentityManager unit tests
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-tests/src/org/briarproject/bramble/identity/IdentityManagerImplTest.java
+44
-21
44 additions, 21 deletions
...riarproject/bramble/identity/IdentityManagerImplTest.java
with
44 additions
and
21 deletions
briar-tests/src/org/briarproject/bramble/identity/IdentityManagerImplTest.java
+
44
−
21
View file @
a9ddb001
package
org.briarproject.bramble.identity
;
import
org.briarproject.BriarTestCase
;
import
org.briarproject.Briar
Mock
TestCase
;
import
org.briarproject.TestUtils
;
import
org.briarproject.bramble.api.contact.Contact
;
import
org.briarproject.bramble.api.contact.ContactId
;
...
...
@@ -12,48 +12,73 @@ import org.briarproject.bramble.api.identity.AuthorId;
import
org.briarproject.bramble.api.identity.IdentityManager
;
import
org.briarproject.bramble.api.identity.LocalAuthor
;
import
org.jmock.Expectations
;
import
org.jmock.Mockery
;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
OURSELVES
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
UNKNOWN
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
UNVERIFIED
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
Author
.
Status
.
VERIFIED
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
fail
;
public
class
IdentityManagerImplTest
extends
BriarTestCase
{
public
class
IdentityManagerImplTest
extends
Briar
Mock
TestCase
{
private
final
Mockery
context
;
private
final
IdentityManager
identityManager
;
private
final
DatabaseComponent
db
;
private
final
Transaction
txn
;
private
final
DatabaseComponent
db
=
context
.
mock
(
DatabaseComponent
.
class
);
private
final
Transaction
txn
=
new
Transaction
(
null
,
false
);
private
final
LocalAuthor
localAuthor
=
new
LocalAuthor
(
new
AuthorId
(
TestUtils
.
getRandomId
()),
TestUtils
.
getRandomString
(
8
),
TestUtils
.
getRandomBytes
(
42
),
TestUtils
.
getRandomBytes
(
42
),
0
);
private
final
Collection
<
LocalAuthor
>
localAuthors
=
Collections
.
singletonList
(
localAuthor
);
public
IdentityManagerImplTest
()
{
context
=
new
Mockery
();
db
=
context
.
mock
(
DatabaseComponent
.
class
);
txn
=
new
Transaction
(
null
,
false
);
identityManager
=
new
IdentityManagerImpl
(
db
);
}
@Test
public
void
testUnitTestsExist
()
{
fail
();
// FIXME: Write more tests
public
void
testRegisterLocalAuthor
()
throws
DbException
{
expectRegisterLocalAuthor
();
identityManager
.
registerLocalAuthor
(
localAuthor
);
}
private
void
expectRegisterLocalAuthor
()
throws
DbException
{
context
.
checking
(
new
Expectations
()
{{
oneOf
(
db
).
startTransaction
(
false
);
will
(
returnValue
(
txn
));
oneOf
(
db
).
addLocalAuthor
(
txn
,
localAuthor
);
oneOf
(
db
).
commitTransaction
(
txn
);
oneOf
(
db
).
endTransaction
(
txn
);
}});
}
@Test
public
void
testGetLocalAuthor
()
throws
DbException
{
context
.
checking
(
new
Expectations
()
{{
oneOf
(
db
).
startTransaction
(
true
);
will
(
returnValue
(
txn
));
oneOf
(
db
).
getLocalAuthors
(
txn
);
will
(
returnValue
(
localAuthors
));
oneOf
(
db
).
commitTransaction
(
txn
);
oneOf
(
db
).
endTransaction
(
txn
);
}});
assertEquals
(
localAuthor
,
identityManager
.
getLocalAuthor
());
}
@Test
public
void
testGetCachedLocalAuthor
()
throws
DbException
{
expectRegisterLocalAuthor
();
identityManager
.
registerLocalAuthor
(
localAuthor
);
assertEquals
(
localAuthor
,
identityManager
.
getLocalAuthor
());
}
@Test
public
void
testGetAuthorStatus
()
throws
DbException
{
final
AuthorId
authorId
=
new
AuthorId
(
TestUtils
.
getRandomId
());
final
Collection
<
LocalAuthor
>
localAuthors
=
new
ArrayList
<>();
LocalAuthor
localAuthor
=
new
LocalAuthor
(
new
AuthorId
(
TestUtils
.
getRandomId
()),
TestUtils
.
getRandomString
(
8
),
TestUtils
.
getRandomBytes
(
42
),
TestUtils
.
getRandomBytes
(
42
),
0
);
localAuthors
.
add
(
localAuthor
);
final
Collection
<
Contact
>
contacts
=
new
ArrayList
<>();
context
.
checking
(
new
Expectations
()
{{
...
...
@@ -96,8 +121,6 @@ public class IdentityManagerImplTest extends BriarTestCase {
}});
assertEquals
(
OURSELVES
,
identityManager
.
getAuthorStatus
(
localAuthor
.
getId
()));
context
.
assertIsSatisfied
();
}
private
void
checkAuthorStatusContext
(
final
AuthorId
authorId
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment