Search in sources :

Example 1 with InputHandler

use of org.codehaus.plexus.components.interactivity.InputHandler in project maven-plugins by apache.

the class EvaluateMojoTest method testEvaluateWithoutExpressionWithOutput.

/**
     * Tests evaluation of an expression in interactive mode with a mock input handler, when "output" is set.
     * @throws Exception in case of errors.
     */
public void testEvaluateWithoutExpressionWithOutput() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/evaluate/plugin-config-output.xml");
    EvaluateMojo mojo = (EvaluateMojo) lookupMojo("evaluate", testPom);
    InputHandler inputHandler = mock(InputHandler.class);
    when(inputHandler.readLine()).thenReturn("${project.artifactId}", "0");
    ExpressionEvaluator expressionEvaluator = mock(PluginParameterExpressionEvaluator.class);
    when(expressionEvaluator.evaluate(anyString())).thenReturn("My result");
    setUpMojo(mojo, inputHandler, expressionEvaluator);
    mojo.execute();
    String ls = System.getProperty("line.separator");
    assertTrue(interceptingLogger.infoLogs.contains(ls + "My result"));
    assertFalse(interceptingLogger.warnLogs.isEmpty());
    verify(expressionEvaluator).evaluate("${project.artifactId}");
    verify(inputHandler, times(2)).readLine();
}
Also used : InputHandler(org.codehaus.plexus.components.interactivity.InputHandler) Mockito.anyString(org.mockito.Mockito.anyString) File(java.io.File) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)

Example 2 with InputHandler

use of org.codehaus.plexus.components.interactivity.InputHandler in project maven-plugins by apache.

the class EvaluateMojoTest method testEvaluateWithoutExpression.

/**
     * Tests evaluation of an expression in interactive mode with a mock input handler.
     * @throws Exception in case of errors.
     */
public void testEvaluateWithoutExpression() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/evaluate/plugin-config.xml");
    EvaluateMojo mojo = (EvaluateMojo) lookupMojo("evaluate", testPom);
    InputHandler inputHandler = mock(InputHandler.class);
    when(inputHandler.readLine()).thenReturn("${project.groupId}", "0");
    ExpressionEvaluator expressionEvaluator = mock(PluginParameterExpressionEvaluator.class);
    when(expressionEvaluator.evaluate(anyString())).thenReturn("My result");
    setUpMojo(mojo, inputHandler, expressionEvaluator);
    mojo.execute();
    String ls = System.getProperty("line.separator");
    assertTrue(interceptingLogger.infoLogs.contains(ls + "My result"));
    assertTrue(interceptingLogger.warnLogs.isEmpty());
    verify(expressionEvaluator).evaluate("${project.groupId}");
    verify(inputHandler, times(2)).readLine();
}
Also used : InputHandler(org.codehaus.plexus.components.interactivity.InputHandler) Mockito.anyString(org.mockito.Mockito.anyString) File(java.io.File) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) ExpressionEvaluator(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)

Aggregations

File (java.io.File)2 PluginParameterExpressionEvaluator (org.apache.maven.plugin.PluginParameterExpressionEvaluator)2 ExpressionEvaluator (org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator)2 InputHandler (org.codehaus.plexus.components.interactivity.InputHandler)2 Mockito.anyString (org.mockito.Mockito.anyString)2