mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-23 15:50:48 +00:00
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.
34 lines
1.0 KiB
Java
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)));
|
|
}
|
|
}
|
|
}
|