Skip to content

Commit

Permalink
#3103 test moved to a better place
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 3, 2024
1 parent a0c917e commit 2dca92d
Showing 1 changed file with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,51 @@
/*
* @checkstyle PackageNameCheck (10 lines)
*/
package EOorg.EOeolang;
package org.eolang;

import com.google.common.reflect.ClassPath;
import com.jcabi.log.Logger;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.util.Set;
import java.util.stream.Collectors;
import org.eolang.Phi;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

/**
* Test that all EO.. classes are public.
* Test case for {@link XmirObject}.
*
* @since 0.38
*/
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
public class EoClassesArePublicTest {
public class XmirObjectTest {

@Test
@SuppressWarnings("JTCOP.RulePresentTense")
public void arePublic() throws IOException {
public void annotatesOnlyPublicClasses() throws IOException {
final Set<Class<?>> clazzes = ClassPath.from(ClassLoader.getSystemClassLoader())
.getAllClasses()
.stream()
.filter(clazz -> clazz.getPackageName().equals("EOorg.EOeolang"))
.map(ClassPath.ClassInfo::load)
.filter(EoClassesArePublicTest::isEoClass)
.filter(
clazz -> clazz.getSimpleName().startsWith("EO")
&& Phi.class.isAssignableFrom(clazz)
)
.collect(Collectors.toSet());
assert !clazzes.isEmpty();
Logger.info(this.getClass(), "Found %d EO classes", clazzes.size());
MatcherAssert.assertThat(
"All EO.. classes should be public",
"Some EOxx classes are found",
clazzes.stream()
.filter(clazz -> !Modifier.isPublic(clazz.getModifiers()))
.collect(Collectors.toList()),
Matchers.empty()
);
MatcherAssert.assertThat(
"All EOxx classes are public",
clazzes.stream()
.filter(clazz -> !Modifier.isPublic(clazz.getModifiers()))
.collect(Collectors.toList()),
Matchers.empty()
);
}

/**
* Is EO.. class and is instance of {@link Phi}.
* @param clazz Class.
* @return True if is.
*/
private static boolean isEoClass(final Class<?> clazz) {
return clazz.getSimpleName().startsWith("EO")
&& Phi.class.isAssignableFrom(clazz);
}
}

0 comments on commit 2dca92d

Please sign in to comment.