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
79fc630a
Commit
79fc630a
authored
12 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Use mocks rather than real plugins for better coverage of error cases.
parent
d18fc133
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
briar-tests/src/net/sf/briar/plugins/PluginManagerImplTest.java
+70
-26
70 additions, 26 deletions
...tests/src/net/sf/briar/plugins/PluginManagerImplTest.java
with
70 additions
and
26 deletions
briar-tests/src/net/sf/briar/plugins/PluginManagerImplTest.java
+
70
−
26
View file @
79fc630a
package
net.sf.briar.plugins
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
net.sf.briar.BriarTestCase
;
import
net.sf.briar.api.TransportConfig
;
import
net.sf.briar.api.TransportProperties
;
import
net.sf.briar.TestUtils
;
import
net.sf.briar.api.android.AndroidExecutor
;
import
net.sf.briar.api.db.DatabaseComponent
;
import
net.sf.briar.api.messaging.TransportId
;
import
net.sf.briar.api.plugins.duplex.DuplexPlugin
;
import
net.sf.briar.api.plugins.duplex.DuplexPluginCallback
;
import
net.sf.briar.api.plugins.duplex.DuplexPluginConfig
;
import
net.sf.briar.api.plugins.duplex.DuplexPluginFactory
;
import
net.sf.briar.api.plugins.simplex.SimplexPlugin
;
import
net.sf.briar.api.plugins.simplex.SimplexPluginCallback
;
import
net.sf.briar.api.plugins.simplex.SimplexPluginConfig
;
import
net.sf.briar.api.plugins.simplex.SimplexPluginFactory
;
import
net.sf.briar.api.transport.ConnectionDispatcher
;
import
net.sf.briar.api.ui.UiCallback
;
import
net.sf.briar.plugins.file.RemovableDrivePluginFactory
;
import
net.sf.briar.plugins.tcp.LanTcpPluginFactory
;
import
org.jmock.Expectations
;
import
org.jmock.Mockery
;
...
...
@@ -26,7 +26,6 @@ import org.junit.Test;
public
class
PluginManagerImplTest
extends
BriarTestCase
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testStartAndStop
()
throws
Exception
{
Mockery
context
=
new
Mockery
();
...
...
@@ -42,31 +41,76 @@ public class PluginManagerImplTest extends BriarTestCase {
final
ConnectionDispatcher
dispatcher
=
context
.
mock
(
ConnectionDispatcher
.
class
);
final
UiCallback
uiCallback
=
context
.
mock
(
UiCallback
.
class
);
// One simplex plugin
final
SimplexPluginFactory
removableDrive
=
new
RemovableDrivePluginFactory
(
pluginExecutor
);
// One duplex plugin
final
DuplexPluginFactory
lanTcp
=
new
LanTcpPluginFactory
(
pluginExecutor
);
// Two simplex plugin factories: both create plugins, one fails to start
final
SimplexPluginFactory
simplexFactory
=
context
.
mock
(
SimplexPluginFactory
.
class
);
final
SimplexPlugin
simplexPlugin
=
context
.
mock
(
SimplexPlugin
.
class
);
final
TransportId
simplexId
=
new
TransportId
(
TestUtils
.
getRandomId
());
final
SimplexPluginFactory
simplexFailFactory
=
context
.
mock
(
SimplexPluginFactory
.
class
,
"simplexFailFactory"
);
final
SimplexPlugin
simplexFailPlugin
=
context
.
mock
(
SimplexPlugin
.
class
,
"simplexFailPlugin"
);
final
TransportId
simplexFailId
=
new
TransportId
(
TestUtils
.
getRandomId
());
// Two duplex plugin factories: one creates a plugin, the other fails
final
DuplexPluginFactory
duplexFactory
=
context
.
mock
(
DuplexPluginFactory
.
class
);
final
DuplexPlugin
duplexPlugin
=
context
.
mock
(
DuplexPlugin
.
class
);
final
TransportId
duplexId
=
new
TransportId
(
TestUtils
.
getRandomId
());
final
DuplexPluginFactory
duplexFailFactory
=
context
.
mock
(
DuplexPluginFactory
.
class
,
"duplexFailFactory"
);
final
TransportId
duplexFailId
=
new
TransportId
(
TestUtils
.
getRandomId
());
context
.
checking
(
new
Expectations
()
{{
// Start
// Start
the simplex plugins
oneOf
(
simplexPluginConfig
).
getFactories
();
will
(
returnValue
(
Arrays
.
asList
(
removableDrive
)));
will
(
returnValue
(
Arrays
.
asList
(
simplexFactory
,
simplexFailFactory
)));
oneOf
(
simplexFactory
).
getId
();
will
(
returnValue
(
simplexId
));
oneOf
(
simplexFactory
).
createPlugin
(
with
(
any
(
SimplexPluginCallback
.
class
)));
will
(
returnValue
(
simplexPlugin
));
// Created
oneOf
(
db
).
addTransport
(
simplexId
);
will
(
returnValue
(
true
));
oneOf
(
simplexPlugin
).
start
();
will
(
returnValue
(
true
));
// Started
oneOf
(
simplexFailFactory
).
getId
();
will
(
returnValue
(
simplexFailId
));
oneOf
(
simplexFailFactory
).
createPlugin
(
with
(
any
(
SimplexPluginCallback
.
class
)));
will
(
returnValue
(
simplexFailPlugin
));
// Created
oneOf
(
db
).
addTransport
(
simplexFailId
);
will
(
returnValue
(
true
));
oneOf
(
simplexFailPlugin
).
start
();
will
(
returnValue
(
false
));
// Failed to start
// Start the duplex plugins
oneOf
(
duplexPluginConfig
).
getFactories
();
will
(
returnValue
(
Arrays
.
asList
(
lanTcp
)));
exactly
(
2
).
of
(
db
).
addTransport
(
with
(
any
(
TransportId
.
class
)));
will
(
returnValue
(
Arrays
.
asList
(
duplexFactory
,
duplexFailFactory
)));
oneOf
(
duplexFactory
).
getId
();
will
(
returnValue
(
duplexId
));
oneOf
(
duplexFactory
).
createPlugin
(
with
(
any
(
DuplexPluginCallback
.
class
)));
will
(
returnValue
(
duplexPlugin
));
// Created
oneOf
(
db
).
addTransport
(
duplexId
);
will
(
returnValue
(
true
));
oneOf
(
duplexPlugin
).
start
();
will
(
returnValue
(
true
));
// Started
oneOf
(
duplexFailFactory
).
getId
();
will
(
returnValue
(
duplexFailId
));
oneOf
(
db
).
addTransport
(
duplexFailId
);
will
(
returnValue
(
true
));
oneOf
(
poller
).
start
(
with
(
any
(
Collection
.
class
)));
allowing
(
db
).
getConfig
(
with
(
any
(
TransportId
.
class
)));
will
(
returnValue
(
new
TransportConfig
()));
allowing
(
db
).
getLocalProperties
(
with
(
any
(
TransportId
.
class
)));
will
(
returnValue
(
new
TransportProperties
()));
allowing
(
db
).
getRemoteProperties
(
with
(
any
(
TransportId
.
class
)));
will
(
returnValue
(
new
TransportProperties
()));
allowing
(
db
).
mergeLocalProperties
(
with
(
any
(
TransportId
.
class
)),
with
(
any
(
TransportProperties
.
class
)));
// Stop
oneOf
(
duplexFailFactory
).
createPlugin
(
with
(
any
(
DuplexPluginCallback
.
class
)));
will
(
returnValue
(
null
));
// Failed to create a plugin
// Start the poller
oneOf
(
poller
).
start
(
Arrays
.
asList
(
simplexPlugin
,
duplexPlugin
));
// Stop the poller
oneOf
(
poller
).
stop
();
// Stop the plugins
oneOf
(
simplexPlugin
).
stop
();
oneOf
(
duplexPlugin
).
stop
();
// Shut down the executor
oneOf
(
androidExecutor
).
shutdown
();
}});
PluginManagerImpl
p
=
new
PluginManagerImpl
(
pluginExecutor
,
...
...
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