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
Snippets
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
Julian Dehm
briar
Commits
3c4513b9
Verified
Commit
3c4513b9
authored
6 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Convert test to BrambleMockTestCase.
parent
5320737d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bramble-core/src/test/java/org/briarproject/bramble/sync/SimplexOutgoingSessionTest.java
+18
-34
18 additions, 34 deletions
...briarproject/bramble/sync/SimplexOutgoingSessionTest.java
with
18 additions
and
34 deletions
bramble-core/src/test/java/org/briarproject/bramble/sync/SimplexOutgoingSessionTest.java
+
18
−
34
View file @
3c4513b9
...
...
@@ -8,11 +8,9 @@ import org.briarproject.bramble.api.sync.Ack;
import
org.briarproject.bramble.api.sync.MessageId
;
import
org.briarproject.bramble.api.sync.SyncRecordWriter
;
import
org.briarproject.bramble.api.transport.StreamWriter
;
import
org.briarproject.bramble.test.BrambleTestCase
;
import
org.briarproject.bramble.test.Bramble
Mock
TestCase
;
import
org.briarproject.bramble.test.ImmediateExecutor
;
import
org.briarproject.bramble.test.TestUtils
;
import
org.jmock.Expectations
;
import
org.jmock.Mockery
;
import
org.junit.Test
;
import
java.util.Arrays
;
...
...
@@ -20,36 +18,26 @@ import java.util.Collections;
import
java.util.concurrent.Executor
;
import
static
org
.
briarproject
.
bramble
.
api
.
sync
.
SyncConstants
.
MAX_MESSAGE_IDS
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getRandomId
;
// TODO: Convert to BrambleMockTestCase
public
class
SimplexOutgoingSessionTest
extends
BrambleTestCase
{
public
class
SimplexOutgoingSessionTest
extends
BrambleMockTestCase
{
private
final
Mockery
context
;
private
final
DatabaseComponent
db
;
private
final
Executor
dbExecutor
;
private
final
EventBus
eventBus
;
private
final
ContactId
contactId
;
private
final
MessageId
messageId
;
private
final
int
maxLatency
;
private
final
StreamWriter
streamWriter
;
private
final
SyncRecordWriter
recordWriter
;
private
static
final
int
MAX_LATENCY
=
Integer
.
MAX_VALUE
;
public
SimplexOutgoingSessionTest
()
{
context
=
new
Mockery
();
db
=
context
.
mock
(
DatabaseComponent
.
class
);
dbExecutor
=
new
ImmediateExecutor
();
eventBus
=
context
.
mock
(
EventBus
.
class
);
streamWriter
=
context
.
mock
(
StreamWriter
.
class
);
recordWriter
=
context
.
mock
(
SyncRecordWriter
.
class
);
contactId
=
new
ContactId
(
234
);
messageId
=
new
MessageId
(
TestUtils
.
getRandomId
());
maxLatency
=
Integer
.
MAX_VALUE
;
}
private
final
DatabaseComponent
db
=
context
.
mock
(
DatabaseComponent
.
class
);
private
final
EventBus
eventBus
=
context
.
mock
(
EventBus
.
class
);
private
final
StreamWriter
streamWriter
=
context
.
mock
(
StreamWriter
.
class
);
private
final
SyncRecordWriter
recordWriter
=
context
.
mock
(
SyncRecordWriter
.
class
);
private
final
Executor
dbExecutor
=
new
ImmediateExecutor
();
private
final
ContactId
contactId
=
new
ContactId
(
234
);
private
final
MessageId
messageId
=
new
MessageId
(
getRandomId
());
@Test
public
void
testNothingToSend
()
throws
Exception
{
SimplexOutgoingSession
session
=
new
SimplexOutgoingSession
(
db
,
dbExecutor
,
eventBus
,
contactId
,
maxLatency
,
streamWriter
,
dbExecutor
,
eventBus
,
contactId
,
MAX_LATENCY
,
streamWriter
,
recordWriter
);
Transaction
noAckTxn
=
new
Transaction
(
null
,
false
);
Transaction
noMsgTxn
=
new
Transaction
(
null
,
false
);
...
...
@@ -68,7 +56,7 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase {
oneOf
(
db
).
startTransaction
(
false
);
will
(
returnValue
(
noMsgTxn
));
oneOf
(
db
).
generateBatch
(
with
(
noMsgTxn
),
with
(
contactId
),
with
(
any
(
int
.
class
)),
with
(
maxLatency
));
with
(
any
(
int
.
class
)),
with
(
MAX_LATENCY
));
will
(
returnValue
(
null
));
oneOf
(
db
).
commitTransaction
(
noMsgTxn
);
oneOf
(
db
).
endTransaction
(
noMsgTxn
);
...
...
@@ -79,8 +67,6 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase {
}});
session
.
run
();
context
.
assertIsSatisfied
();
}
@Test
...
...
@@ -88,7 +74,7 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase {
Ack
ack
=
new
Ack
(
Collections
.
singletonList
(
messageId
));
byte
[]
raw
=
new
byte
[
1234
];
SimplexOutgoingSession
session
=
new
SimplexOutgoingSession
(
db
,
dbExecutor
,
eventBus
,
contactId
,
maxLatency
,
streamWriter
,
dbExecutor
,
eventBus
,
contactId
,
MAX_LATENCY
,
streamWriter
,
recordWriter
);
Transaction
ackTxn
=
new
Transaction
(
null
,
false
);
Transaction
noAckTxn
=
new
Transaction
(
null
,
false
);
...
...
@@ -110,7 +96,7 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase {
oneOf
(
db
).
startTransaction
(
false
);
will
(
returnValue
(
msgTxn
));
oneOf
(
db
).
generateBatch
(
with
(
msgTxn
),
with
(
contactId
),
with
(
any
(
int
.
class
)),
with
(
maxLatency
));
with
(
any
(
int
.
class
)),
with
(
MAX_LATENCY
));
will
(
returnValue
(
Arrays
.
asList
(
raw
)));
oneOf
(
db
).
commitTransaction
(
msgTxn
);
oneOf
(
db
).
endTransaction
(
msgTxn
);
...
...
@@ -126,7 +112,7 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase {
oneOf
(
db
).
startTransaction
(
false
);
will
(
returnValue
(
noMsgTxn
));
oneOf
(
db
).
generateBatch
(
with
(
noMsgTxn
),
with
(
contactId
),
with
(
any
(
int
.
class
)),
with
(
maxLatency
));
with
(
any
(
int
.
class
)),
with
(
MAX_LATENCY
));
will
(
returnValue
(
null
));
oneOf
(
db
).
commitTransaction
(
noMsgTxn
);
oneOf
(
db
).
endTransaction
(
noMsgTxn
);
...
...
@@ -137,7 +123,5 @@ public class SimplexOutgoingSessionTest extends BrambleTestCase {
}});
session
.
run
();
context
.
assertIsSatisfied
();
}
}
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