Package com.netflix.infix

Source Code of com.netflix.infix.RegexValuePredicateTest

package com.netflix.infix;

import com.netflix.infix.RegexValuePredicate.MatchPolicy;

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

import static org.junit.Assert.assertEquals;

public class RegexValuePredicateTest {

  @Before
  public void setUp() throws Exception {
  }

  @After
  public void tearDown() throws Exception {
  }

  @Test
  public void testNormalMatch() throws Exception {
    Object[][] inputs = {
      {"a123cd", "a[0-9]+cd", MatchPolicy.FULL, true},
      {"", "",  MatchPolicy.FULL, true},
      {"", "^$",  MatchPolicy.FULL, true},
      {"32abde23", "[a-z]+",  MatchPolicy.FULL, false},
      {"32abde23", "[a-z]+", MatchPolicy.PARTIAL, true},
      {null, ".*", MatchPolicy.PARTIAL, false},
      {null, ".*",  MatchPolicy.FULL, false},
      {null, "", MatchPolicy.PARTIAL, false}
    };
   
    for(Object[] input : inputs){
      String value = (String)input[0];
      String regex = (String)input[1];
      MatchPolicy policy = (MatchPolicy)input[2];
      boolean expected = (Boolean) input[3];
     
      RegexValuePredicate pred = new RegexValuePredicate(regex, policy);
   
      assertEquals(
        String.format("Given regex = %s, isPartial = %s, and input = %s", regex, policy, value),
        expected,
        pred.apply(value));
    }
   
  }

  @Test(expected = IllegalArgumentException.class)
  public void testNullPatternIsNotAllowed(){
    new RegexValuePredicate(null, MatchPolicy.FULL);
  }
}
TOP

Related Classes of com.netflix.infix.RegexValuePredicateTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.