@Test public void testFromProtobuf() { List<IGameEvent> gameEvents = new ArrayList<>(); gameEvents.add(new AimlessKick(botId(), location(), location())); gameEvents.add(new AttackerDoubleTouchedBall(botId(), location())); gameEvents.add(new AttackerTouchedBallInDefenseArea(botId(), location(), number())); gameEvents.add(new AttackerTooCloseToDefenseArea(botId(), location(), number(), location())); gameEvents.add(new BallLeftFieldGoalLine(botId(), location())); gameEvents.add(new BallLeftFieldTouchLine(botId(), location())); gameEvents.add(new BotCrashDrawn(yellowBot(), blueBot(), location(), number(), number(), number())); gameEvents.add(new BotCrashUnique(botId(), botId(), location(), number(), number(), number())); gameEvents.add(new BotDribbledBallTooFar(botId(), location(), location())); gameEvents.add(new BotHeldBallDeliberately(botId(), location(), number())); gameEvents.add(new BotInterferedPlacement(botId(), location())); gameEvents.add(new BotKickedBallToFast(botId(), location(), number(), BotKickedBallToFast.EKickType.STRAIGHT)); gameEvents.add(new BotPushedBot(botId(), botId(), location(), number())); gameEvents.add(new BotSubstitution(team())); gameEvents.add(new BotTippedOver(botId(), location(), location())); gameEvents.add(new BotTooFastInStop(botId(), location(), number())); gameEvents.add(new DefenderInDefenseArea(botId(), location(), number())); gameEvents.add(new DefenderTooCloseToKickPoint(botId(), location(), number())); gameEvents.add(new Goal(team(), botId(), location(), location(), number(), intNumber(), timestamp())); gameEvents.add(new InvalidGoal(team(), botId(), location(), location(), number(), intNumber(), timestamp())); gameEvents.add(new KeeperHeldBall(team(), location(), number())); gameEvents.add(new MultipleCards(team())); gameEvents.add(new MultipleFouls(team())); gameEvents.add(new NoProgressInGame(location(), number())); gameEvents.add(new PlacementFailed(team(), number())); gameEvents.add(new PlacementSucceeded(team(), number(), number(), number())); gameEvents.add(new PossibleGoal(team(), botId(), location(), location(), number(), intNumber(), timestamp())); gameEvents.add(new TooManyRobots(team(), intNumber(), intNumber(), location())); gameEvents.add(new UnsportingBehaviorMajor(team(), "reason")); gameEvents.add(new UnsportingBehaviorMinor(team(), "reason")); gameEvents.add(new BoundaryCrossing(team(), location())); gameEvents.add(new PenaltyKickFailed(team(), location())); for (IGameEvent gameEvent : gameEvents) { final SslGcGameEvent.GameEvent protoGameEvent = gameEvent.toProtobuf(); final Optional<IGameEvent> convertedGameEvent = GameEventFactory.fromProtobuf(protoGameEvent); assertThat(convertedGameEvent).isPresent(); assertThat(convertedGameEvent.get()).isEqualTo(gameEvent); } assertThat(gameEvents.stream().map(IGameEvent::getType)) .containsAll(Arrays.asList(EGameEvent.values())); }
public static Optional<IGameEvent> fromProtobuf(SslGcGameEvent.GameEvent event) { if (event.getType() == SslGcGameEvent.GameEvent.Type.UNKNOWN_GAME_EVENT_TYPE) { return Optional.empty(); } try { final EGameEvent gameEvent = EGameEvent.fromProto(event.getType()); if (gameEvent == null) { return Optional.empty(); } return Optional.of((IGameEvent) gameEvent.getInstanceableClass().newInstance(event)); } catch (InstanceableClass.NotCreateableException e) { log.warn("Could not convert game event: " + event, e); } return Optional.empty(); }
GameEventFactory { public static Optional<IGameEvent> fromProtobuf(SslGcGameEvent.GameEvent event) { if (event.getType() == SslGcGameEvent.GameEvent.Type.UNKNOWN_GAME_EVENT_TYPE) { return Optional.empty(); } try { final EGameEvent gameEvent = EGameEvent.fromProto(event.getType()); if (gameEvent == null) { return Optional.empty(); } return Optional.of((IGameEvent) gameEvent.getInstanceableClass().newInstance(event)); } catch (InstanceableClass.NotCreateableException e) { log.warn("Could not convert game event: " + event, e); } return Optional.empty(); } }
GameEventFactory { public static Optional<IGameEvent> fromProtobuf(SslGcGameEvent.GameEvent event) { if (event.getType() == SslGcGameEvent.GameEvent.Type.UNKNOWN_GAME_EVENT_TYPE) { return Optional.empty(); } try { final EGameEvent gameEvent = EGameEvent.fromProto(event.getType()); if (gameEvent == null) { return Optional.empty(); } return Optional.of((IGameEvent) gameEvent.getInstanceableClass().newInstance(event)); } catch (InstanceableClass.NotCreateableException e) { log.warn("Could not convert game event: " + event, e); } return Optional.empty(); } private  GameEventFactory(); }
GameEventFactory { public static Optional<IGameEvent> fromProtobuf(SslGcGameEvent.GameEvent event) { if (event.getType() == SslGcGameEvent.GameEvent.Type.UNKNOWN_GAME_EVENT_TYPE) { return Optional.empty(); } try { final EGameEvent gameEvent = EGameEvent.fromProto(event.getType()); if (gameEvent == null) { return Optional.empty(); } return Optional.of((IGameEvent) gameEvent.getInstanceableClass().newInstance(event)); } catch (InstanceableClass.NotCreateableException e) { log.warn("Could not convert game event: " + event, e); } return Optional.empty(); } private  GameEventFactory(); static Optional<IGameEvent> fromProtobuf(SslGcGameEvent.GameEvent event); }
GameEventFactory { public static Optional<IGameEvent> fromProtobuf(SslGcGameEvent.GameEvent event) { if (event.getType() == SslGcGameEvent.GameEvent.Type.UNKNOWN_GAME_EVENT_TYPE) { return Optional.empty(); } try { final EGameEvent gameEvent = EGameEvent.fromProto(event.getType()); if (gameEvent == null) { return Optional.empty(); } return Optional.of((IGameEvent) gameEvent.getInstanceableClass().newInstance(event)); } catch (InstanceableClass.NotCreateableException e) { log.warn("Could not convert game event: " + event, e); } return Optional.empty(); } private  GameEventFactory(); static Optional<IGameEvent> fromProtobuf(SslGcGameEvent.GameEvent event);  }