Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure prompter does not double colon #10

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,18 @@ public class DefaultPrompter
*/
private InputHandler inputHandler;

public String prompt( String message )
public DefaultPrompter()
{
super();
}

public DefaultPrompter( OutputHandler outputHandler, InputHandler inputHandler )
{
this.outputHandler = outputHandler;
this.inputHandler = inputHandler;
}

public String prompt(String message )
throws PrompterException
{
try
Expand Down Expand Up @@ -207,7 +218,7 @@ private String formatMessage( String message, List<String> possibleValues, Strin

if ( defaultReply != null )
{
formatted.append( ' ' ).append( defaultReply ).append( ": " );
formatted.append( ' ' ).append( defaultReply );
}

return formatted.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.codehaus.plexus.components.interactivity;

/*
* The MIT License
*
* Copyright (c) 2005, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import org.junit.Test;

import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;
import static org.junit.Assert.assertEquals;

public class DefaultPrompterTest
{
@Test
public void promptSimple() throws PrompterException {
final InMemoryOutput out = new InMemoryOutput();
final Prompter prompter = new DefaultPrompter( out, new InMemoryInput( "ok" ) );
prompter.prompt( "test" );
assertEquals( "test: ", out.builder.toString() );
}

@Test
public void promptOption() throws PrompterException {
final InMemoryOutput out = new InMemoryOutput();
final Prompter prompter = new DefaultPrompter( out, new InMemoryInput( "ok" ) );
prompter.prompt( "test", "value" );
assertEquals("test value: ", out.builder.toString());
}

@Test
public void promptOptions() throws PrompterException {
final InMemoryOutput out = new InMemoryOutput();
final Prompter prompter = new DefaultPrompter( out, new InMemoryInput( "yes" ) );
prompter.prompt( "test", asList( "yes", "no" ), "value" );
assertEquals("test (yes/no) value: ", out.builder.toString());
}

private static class InMemoryInput implements InputHandler
{
private final String line;

private InMemoryInput( String line )
{
this.line = requireNonNull(line);
}

@Override
public String readLine() {
return line;
}

@Override
public String readPassword()
{
throw new UnsupportedOperationException();
}

@Override
public List<String> readMultipleLines()
{
throw new UnsupportedOperationException();
}
}

private static class InMemoryOutput implements OutputHandler
{
private final StringBuilder builder = new StringBuilder();

@Override
public void write( String line )
{
builder.append( line );
}

@Override
public void writeLine( String line )
{
builder.append( line );
}
}
}
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>