-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added configuration for excluding validators by name
- Loading branch information
1 parent
6ed93ab
commit 498ad4d
Showing
7 changed files
with
121 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/java/io/github/dimitrovvlado/proto/lint/validation/ValidatorServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.github.dimitrovvlado.proto.lint.validation; | ||
|
||
import com.squareup.wire.schema.internal.parser.ProtoFileElement; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Tests for {@link ValidatorService} class | ||
*/ | ||
public class ValidatorServiceTest { | ||
|
||
@Test | ||
public void instantiateAndExclude() { | ||
ValidatorService instance = ValidatorService.getInstance(); | ||
assertNotNull(instance); | ||
Map<String, Validator> validators = instance.getValidators(); | ||
assertNotNull(validators); | ||
assertEquals(2, validators.size()); //Expected 2 default validators | ||
assertTrue(validators.get("messagesValidator") instanceof MessagesValidator); | ||
assertTrue(validators.get("servicesValidator") instanceof ServicesValidator); | ||
|
||
instance.excludeValidator("servicesValidator"); | ||
validators = instance.getValidators(); | ||
assertNotNull(validators); | ||
assertEquals(1, validators.size()); | ||
assertTrue(validators.get("messagesValidator") instanceof MessagesValidator); | ||
|
||
instance.excludeValidator("messagesValidator"); | ||
validators = instance.getValidators(); | ||
assertNotNull(validators); | ||
assertEquals(0, validators.size()); | ||
} | ||
|
||
@Test | ||
public void instantiateAndInclude() { | ||
ValidatorService instance = ValidatorService.getInstance(); | ||
assertNotNull(instance); | ||
Map<String, Validator> validators = instance.getValidators(); | ||
assertNotNull(validators); | ||
assertEquals(2, validators.size()); //Expected 2 default validators | ||
|
||
instance.includeValidator(new Validator() { | ||
@Override | ||
public List<ValidationResult> validate(ProtoFileElement protoFile) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "foobar"; | ||
} | ||
}); | ||
|
||
validators = instance.getValidators(); | ||
assertNotNull(validators); | ||
assertEquals(3, validators.size()); | ||
} | ||
} |