1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package com.qulice.maven;
32
33 import com.qulice.spi.Environment;
34 import com.qulice.spi.ResourceValidator;
35 import com.qulice.spi.Validator;
36 import org.apache.maven.plugin.logging.Log;
37 import org.apache.maven.project.MavenProject;
38 import org.codehaus.plexus.context.Context;
39 import org.junit.jupiter.api.Test;
40 import org.mockito.Mockito;
41
42
43
44
45
46 final class CheckMojoTest {
47
48
49
50
51
52 @Test
53 void skipsExecutionOnSkipFlag() throws Exception {
54 final CheckMojo mojo = new CheckMojo();
55 final Log log = Mockito.mock(Log.class);
56 mojo.setLog(log);
57 mojo.setSkip(true);
58 mojo.execute();
59 Mockito.verify(log).info("Execution skipped");
60 }
61
62
63
64
65
66 @Test
67 void validatesUsingAllProvidedValidators() throws Exception {
68 final CheckMojo mojo = new CheckMojo();
69 final Validator external = Mockito.mock(Validator.class);
70 Mockito.when(external.name()).thenReturn("somename");
71 final ResourceValidator rexternal =
72 Mockito.mock(ResourceValidator.class);
73 Mockito.when(rexternal.name()).thenReturn("other");
74 final MavenValidator internal = Mockito.mock(MavenValidator.class);
75 final ValidatorsProvider provider = new ValidatorsProviderMocker()
76 .withInternal(internal)
77 .withExternal(external)
78 .withExternalResource(rexternal)
79 .mock();
80 mojo.setValidatorsProvider(provider);
81 final MavenProject project = Mockito.mock(MavenProject.class);
82 mojo.setProject(project);
83 mojo.setLog(Mockito.mock(Log.class));
84 final Context context = Mockito.mock(Context.class);
85 mojo.contextualize(context);
86 mojo.execute();
87 Mockito.verify(internal).validate(Mockito.any(MavenEnvironment.class));
88 Mockito.verify(external).validate(Mockito.any(Environment.class));
89 Mockito.verify(rexternal, Mockito.atLeastOnce())
90 .validate(Mockito.anyCollection());
91 }
92
93 }