package com.codeaffine.extras.launch.internal;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Before;
import org.junit.Test;

import com.codeaffine.extras.launch.internal.LaunchConfigSearchPattern;

public class LaunchConfigSearchPatternTest {

  private LaunchConfigSearchPattern searchPattern;

  @Before
  public void setUp() {
    searchPattern = new LaunchConfigSearchPattern();
  }

  @Test
  public void testSetPatternToEmptyString() {
    searchPattern.setPattern( "" );

    assertThat( searchPattern.getPattern() ).isEmpty();
  }

  @Test
  public void testSetPatternToSpace() {
    searchPattern.setPattern( " " );

    assertThat( searchPattern.getPattern() ).isEqualTo( "* *" );
  }

  @Test
  public void testSetPatternToTrailingSpace() {
    searchPattern.setPattern( "pattern " );

    assertThat( searchPattern.getPattern() ).isEqualTo( "*pattern *" );
  }

  @Test
  public void testSetPatternToNonEmptyString() {
    searchPattern.setPattern( "pattern" );

    assertThat( searchPattern.getPattern() ).isEqualTo( "*pattern*" );
  }

  @Test
  public void testSetPatternToStringStartingWithAsterisk() {
    searchPattern.setPattern( "*" );

    assertThat( searchPattern.getPattern() ).isEqualTo( "*" );
  }

  @Test
  public void testMatchEmptyPattern() {
    searchPattern.setPattern( "" );

    assertThat( searchPattern.matches( "foo" ) ).isTrue();
  }

  @Test
  public void testMatchPrefixPattern() {
    searchPattern.setPattern( "pref" );

    assertThat( searchPattern.matches( "prefix" ) ).isTrue();
  }

  @Test
  public void testMatchSuffixPattern() {
    searchPattern.setPattern( "fix" );

    assertThat( searchPattern.matches( "prefix" ) ).isTrue();
  }

  @Test
  public void testMatchAsteriskWildcardPattern() {
    searchPattern.setPattern( "f*o" );

    assertThat( searchPattern.matches( "fooo" ) ).isTrue();
  }

  @Test
  public void testMatchQuestionMarkWildcardPattern() {
    searchPattern.setPattern( "f?o" );

    assertThat( searchPattern.matches( "foo" ) ).isTrue();
  }

  @Test
  public void testMatchCamelCasePattern() {
    searchPattern.setPattern( "CC" );

    assertThat( searchPattern.matches( "CamelCase" ) ).isTrue();
  }
}

@@ -1079,183 +1079,8 @@
  %7D%0A%0A
-  @Test%0A  public void testSetPatternToStringStartingWithAsterisk() %7B%0A    searchPattern.setPattern( %22*%22 );%0A%0A    assertThat( searchPattern.getPattern() ).isEqualTo( %22*%22 );%0A  %7D%0A%0A
   @T
@@ -2027,11 +2027,178 @@
 e();%0A  %7D
+%0A%0A  @Test%0A  public void testMatchTrailingSpacePattern() %7B%0A    searchPattern.setPattern( %22two %22 );%0A%0A    assertThat( searchPattern.matches( %22two words%22 ) ).isTrue();%0A  %7D
 %0A%7D%0A

Improve LaunchConfigSearchPatternTest