Permalink
Browse files

improve eunit coverage

  • Loading branch information...
1 parent 42c95b2 commit 32ebf35ca0e45d75e2b6636828436404d4fc2f1c @jamespharaoh committed Apr 7, 2012
Showing with 118 additions and 0 deletions.
  1. +48 −0 test/misc/notes_openid_test.erl
  2. +70 −0 test/misc/notes_test_server.erl
@@ -0,0 +1,48 @@
+-module (notes_openid_test).
+
+-include_lib ("nitrogen_core/include/wf.hrl").
+
+-include ("notes_test.hrl").
+-include ("notes_data.hrl").
+
+-compile (export_all).
+
+-define (MOCK_MODULES, [
+ notes_test_server_target ]).
+
+-define (TARGET,
+ notes_openid).
+
+prepare_test () ->
+
+ { ok, Server } =
+ notes_test_server:start_link (
+ openid,
+ notes_test_server_target),
+
+ ?EXPECT,
+
+ em:strict (Em, notes_test_server_target, handle_call,
+
+ [ { prepare,
+ "session id",
+ "open id url",
+ true },
+ em:any () ],
+
+ { return, ok }),
+
+ ?REPLAY,
+
+ ?assertEqual (
+
+ ok,
+
+ ?TARGET:prepare (
+ "session id",
+ "open id url",
+ true)),
+
+ ?VERIFY,
+
+ ok = notes_test_server:stop (Server).
@@ -0,0 +1,70 @@
+-module (notes_test_server).
+
+-behaviour (gen_server).
+
+-export ([
+
+ % public api
+
+ start_link/2,
+ stop/1,
+
+ % callbacks
+
+ init/1,
+ handle_call/3,
+ handle_cast/2,
+ handle_info/2,
+ terminate/2,
+ code_change/3 ]).
+
+% public api
+
+start_link (Name, Target) ->
+
+ gen_server:start_link (
+ { local, Name },
+ ?MODULE,
+ [ Target ],
+ []).
+
+stop (Pid) ->
+
+ gen_server:call (
+ Pid,
+ stop).
+
+% callbacks
+
+init ([ Target ]) ->
+
+ { ok, Target }.
+
+handle_call (stop, _From, Target) ->
+
+ { stop, normal, ok, Target };
+
+handle_call (Request, From, Target) ->
+
+ case Target:handle_call (Request, From) of
+
+ ok ->
+ { reply, ok, Target }
+
+ end.
+
+handle_cast (Message, Target) ->
+
+ Target:handle_cast (Message).
+
+handle_info (Info, Target) ->
+
+ Target:handle_info (Info).
+
+terminate (_Reason, _Target) ->
+
+ ok.
+
+code_change (_OldVersion, Target, _Extra) ->
+
+ { ok, Target }.

0 comments on commit 32ebf35

Please sign in to comment.