Skip to content

Commit

Permalink
#3058: Made it java test
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Apr 28, 2024
1 parent aa68d37 commit 4eb3413
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 76 deletions.
15 changes: 12 additions & 3 deletions eo-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,18 @@ SOFTWARE.
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.bcel</groupId>
<artifactId>bcel</artifactId>
<version>5.2</version>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.0.0-jre</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
73 changes: 0 additions & 73 deletions eo-runtime/src/test/groovy/check-eo-classes-are-public.groovy

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package EOorg.EOeolang;

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

/**
* Test that all EO.. classes are public.
*/
public class EOClassesArePublicTest {

@Test
public void arePublic() throws IOException {
final Set<Class<?>> clazzes = ClassPath.from(ClassLoader.getSystemClassLoader())
.getAllClasses()
.stream()
.filter(clazz -> clazz.getPackageName()
.equalsIgnoreCase("EOorg.EOeolang"))
.map(ClassPath.ClassInfo::load)
.filter(EOClassesArePublicTest::isEoClass)
.collect(Collectors.toSet());
assert !clazzes.isEmpty();
Logger.info(this.getClass(), "Found %d EO classes", clazzes.size());
MatcherAssert.assertThat(
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 4eb3413

Please sign in to comment.