Files
github-api/src/test/java/org/kohsuke/github/GHEventTest.java
Liam Newman c00d562b48 Remove internal map-only enum
We took a change that added an enum that was used purely for mapping from
EventInfo.type to GHEvent. This seemed fine but that enum is used only by EventInfo.

This change removed that enum and adds a map to EventInfo to do the required mapping.
This avoids shoehorning mapping behavior in to the EnumUtils.
2021-06-01 15:57:39 -07:00

34 lines
1.0 KiB
Java

package org.kohsuke.github;
import org.junit.Test;
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() {
assertThat(GHEventInfo.transformTypeToGHEvent("NewlyAddedOrBogusEvent"), is(GHEvent.UNKNOWN));
for (String eventInfoType : GHEventInfo.mapTypeStringToEvent.keySet()) {
assertThat(GHEventInfo.transformTypeToGHEvent(eventInfoType), is(oldTransformationFunction(eventInfoType)));
}
}
}