Skip to content

Commit

Permalink
make small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Nov 9, 2022
1 parent ad07814 commit f6055d9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# test-naming-conventions
# test-naming-conventions

```shell
mvn com.github.volodya-lombrozo:test-naming-conventions:check
```
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.github.volodya-lombrozo</groupId>
<artifactId>test-naming-conventions</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
<packaging>maven-plugin</packaging>
<description>Plugin for checking test naming rules</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public final class JavaTestCode {
Expand All @@ -34,8 +33,7 @@ public Collection<String> names() {
}
return names;
} catch (IOException ex) {
ex.printStackTrace();
throw new IllegalStateException(ex);
}
return Collections.emptyList();
}
}
14 changes: 2 additions & 12 deletions src/main/java/com/github/lombrozo/testnames/RuleForAllTests.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.github.lombrozo.testnames;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public final class RuleForAllTests implements Rule {

Expand All @@ -15,16 +13,8 @@ public RuleForAllTests(final JavaTestCode tests) {
@Override
public void validate() throws WrongTestName {
final Collection<String> names = tests.names();
final List<WrongTestName> exceptions = new ArrayList<>(names.size());
for (String test : names) {
try {
new PresentSimpleRule(test).validate();
} catch (WrongTestName ex){
exceptions.add(ex);
}
}
if(!exceptions.isEmpty()){
throw new WrongTestName(exceptions);
new PresentSimpleRule(test).validate();
}
}
}
}
13 changes: 11 additions & 2 deletions src/main/java/com/github/lombrozo/testnames/ValidateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.maven.plugin.AbstractMojo;
Expand All @@ -26,12 +27,20 @@ public void execute() throws MojoExecutionException, MojoFailureException {
Paths.get(project.getTestCompileSourceRoots().get(0)))
.filter(Files::exists)
.filter(Files::isRegularFile).collect(Collectors.toList());
final List<WrongTestName> exceptions = new ArrayList<>();
for (final Path test : tests) {
new RuleForAllTests(new JavaTestCode(test)).validate();
try {
new RuleForAllTests(new JavaTestCode(test)).validate();
} catch (final WrongTestName ex) {
exceptions.add(ex);
}
}
if (!exceptions.isEmpty()) {
throw new WrongTestName(exceptions);
}
} catch (final WrongTestName ex) {
throw new MojoFailureException(ex);
} catch (final Exception occasion){
} catch (final Exception occasion) {
throw new MojoExecutionException(occasion);
}
}
Expand Down

0 comments on commit f6055d9

Please sign in to comment.