Clover icon

sunshower-core

  1. Project Clover database Fri Apr 6 2018 03:27:42 UTC
  2. Package io.sunshower.net.validation

File UrlValidator.java

 

Coverage histogram

../../../../img/srcFileCovDistChart7.png
24% of files have more coverage

Code metrics

0
1
2
1
21
15
2
2
0.5
2
1

Classes

Class Line # Actions
UrlValidator 8 1 2
0.666666766.7%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    package io.sunshower.net.validation;
2   
3    import java.util.regex.Pattern;
4    import javax.validation.ConstraintValidator;
5    import javax.validation.ConstraintValidatorContext;
6   
7    /** Created by haswell on 5/22/17. */
 
8    public class UrlValidator implements ConstraintValidator<Url, String> {
9   
10    static final Pattern pattern =
11    Pattern.compile(
12    "^((http[s]?|ftp):/)?/?([^:\\/\\s]+)((\\/\\w+)*\\/)([\\w\\-\\.]+[^#?\\s]+)(.*)?(#[\\w\\-]+)?$");
13   
 
14  0 toggle @Override
15    public void initialize(Url constraintAnnotation) {}
16   
 
17  3 toggle @Override
18    public boolean isValid(String value, ConstraintValidatorContext context) {
19  3 return value != null && pattern.matcher(value).matches();
20    }
21    }