(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:
Akash Rindhe
2021-04-21 20:07:10 +08:00
parent f6e8a2c7c6
commit 72dc5c5d18
3 changed files with 84 additions and 8 deletions

View 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())));
}
}
}