22
33import static org .hamcrest .MatcherAssert .assertThat ;
44import static org .hamcrest .Matchers .containsString ;
5+ import static org .hamcrest .Matchers .hasSize ;
56import static org .hamcrest .Matchers .is ;
7+
8+ import java .io .File ;
9+ import java .util .List ;
10+
611import jdepend .framework .JDepend ;
712
813import org .apache .maven .enforcer .rule .api .EnforcerRuleException ;
@@ -24,8 +29,6 @@ protected JDepend createJDepend() {
2429 }
2530 }
2631
27- private static final String MAVEN_WAR_PACKAGING = "war" ;
28-
2932 @ Rule
3033 public TemporaryFolder temporaryFolder = new TemporaryFolder ();
3134
@@ -62,18 +65,13 @@ public void result_IsNotValid() {
6265
6366 @ Test
6467 public void execute_checkNotNecessary_ClassesDirNotFound () throws Exception {
65- jdependMock .setContainsCycles (true );
66- helper .setTargetDir (temporaryFolder .newFolder ());
67- rule .execute (helper );
68- }
69-
70- @ Test
71- public void execute_checkNotNecessary_PackagingNotJar () throws Exception {
72- jdependMock .setContainsCycles (true );
73- helper .setPackaging (MAVEN_WAR_PACKAGING );
74- expectedException .expect (EnforcerRuleException .class );
75- expectedException .expectMessage (containsString ("There are package cycles" ));
68+ File newFolder = temporaryFolder .newFolder ();
69+ helper .setTargetDir (newFolder );
7670 rule .execute (helper );
71+ List <String > infoLogs = helper .getLogMock ().getInfo ();
72+ assertThat (infoLogs , hasSize (2 ));
73+ assertSearchingInfo (newFolder , infoLogs );
74+ assertThat (infoLogs .get (1 ), is ("Directory " + getTargetDirectory (newFolder ) + " could not be found." ));
7775 }
7876
7977 @ Test
@@ -95,6 +93,9 @@ public void execute_JdependAddDirectoryFailed_ThrowsException() throws Exception
9593 @ Test
9694 public void execute_ContainsNoCycles () throws Exception {
9795 rule .execute (helper );
96+ List <String > infoLogs = helper .getLogMock ().getInfo ();
97+ assertThat (infoLogs , hasSize (1 ));
98+ assertSearchingInfo (temporaryFolder .getRoot (), infoLogs );
9899 }
99100
100101 @ Test
@@ -104,4 +105,13 @@ public void execute_ContainsCycles() throws Exception {
104105 expectedException .expectMessage (containsString ("There are package cycles" ));
105106 rule .execute (helper );
106107 }
108+
109+ private void assertSearchingInfo (File projectDirectory , List <String > infoLogs ) {
110+ assertThat (infoLogs .get (0 ), is ("Searching directory " + getTargetDirectory (projectDirectory )
111+ + " for package cycles." ));
112+ }
113+
114+ private String getTargetDirectory (File newFolder ) {
115+ return new File (newFolder , NoPackageCyclesRule .MAVEN_CLASSES_DIR ).getAbsolutePath ();
116+ }
107117}
0 commit comments