mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-04 15:50:52 +00:00
(refactor) Replace complex parsing logic from GHEvent.type to GHEvent with static mapping
[https://github.com/hub4j/github-api/issues/1099]
This commit is contained in:
34
src/test/java/org/kohsuke/github/GHEventTest.java
Normal file
34
src/test/java/org/kohsuke/github/GHEventTest.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.kohsuke.github.GHEvent.GitHubEventType;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class GHEventTest {
|
||||
|
||||
/**
|
||||
* Function from GHEventInfo to transform string event to GHEvent which has been replaced by static mapping due to
|
||||
* complex parsing logic below
|
||||
*/
|
||||
private static GHEvent oldTransformationFunction(String t) {
|
||||
if (t.endsWith("Event")) {
|
||||
t = t.substring(0, t.length() - 5);
|
||||
}
|
||||
for (GHEvent e : GHEvent.values()) {
|
||||
if (e.name().replace("_", "").equalsIgnoreCase(t)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return GHEvent.UNKNOWN;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regressionTest() {
|
||||
for (GitHubEventType gitHubEventType : GitHubEventType.values()) {
|
||||
assertThat(GitHubEventType.transformToGHEvent(gitHubEventType.name()),
|
||||
is(oldTransformationFunction(gitHubEventType.name())));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user