### Question:
EndpointManager implements AutoCloseable { public EgKey getEgKey(Endpoint endpoint) { if (!isValidEp(endpoint)) return null; return new EgKey(endpoint.getTenant(), endpoint.getEndpointGroup()); } EndpointManager(DataBroker dataProvider,PacketProcessingService packetProcessingService,
            SalFlowService flowService, NotificationService notificationService,
            ScheduledExecutorService executor, SwitchManager switchManager); void registerListener(EndpointListener listener); synchronized Set<EgKey> getGroupsForNode(NodeId nodeId); synchronized Set<NodeId> getNodesForGroup(final EgKey egKey); synchronized Collection<Endpoint> getEndpointsForNode(NodeId nodeId, EgKey eg); synchronized Collection<Endpoint> getEndpointsForNode(final NodeId nodeId); Endpoint getEndpoint(EpKey epKey); HashSet<Endpoint> getEndpoints(); synchronized Collection<Endpoint> getEndpointsForGroup(EgKey eg); synchronized Collection<Endpoint> getExtEpsNoLocForGroup(final EgKey eg); @Override void close(); static boolean isExternal(Endpoint ep, @Nullable Collection<ExternalImplicitGroup> eigs); static boolean isInternal(Endpoint ep, @Nullable Collection<ExternalImplicitGroup> eigs); Endpoint getL2EndpointFromL3(EndpointL3 endpointL3); EndpointL3 getL3Endpoint(L3ContextId l3c, IpAddress ipAddress, @Nullable TenantId tenantId); Collection<EndpointL3Prefix> getEndpointsL3PrefixForTenant(final TenantId tenantId); @Nonnull Collection<EndpointL3> getL3EndpointsWithNat(); @SuppressWarnings({"UnusedParameters", "EmptyMethod"}) void setLearningMode(OfOverlayConfig.LearningMode learningMode); List<ConditionName> getConditionsForEndpoint(Endpoint endpoint); NodeId getEndpointNodeId(Endpoint endpoint); NodeConnectorId getEndpointNodeConnectorId(Endpoint endpoint); Set<EgKey> getEgKeysForEndpoint(Endpoint ep); EgKey getEgKey(Endpoint endpoint);  }### Answer:
@Test public void getEgKeyTest() { assertNotNull(manager.getEgKey(endpoint1)); assertNull(manager.getEgKey(null)); when(endpoint1.getTenant()).thenReturn(null); assertNull(manager.getEgKey(endpoint1)); when(endpoint1.getTenant()).thenReturn(tenantId); when(endpoint1.getEndpointGroup()).thenReturn(null); assertNull(manager.getEgKey(endpoint1)); when(endpoint1.getEndpointGroup()).thenReturn(endpointGroupId); when(endpoint1.getEndpointGroups()).thenReturn(null); assertNotNull(manager.getEgKey(endpoint1)); when(endpoint1.getEndpointGroup()).thenReturn(null); assertNull(manager.getEgKey(endpoint1)); when(endpoint1.getEndpointGroup()).thenReturn(endpointGroupId); when(endpoint1.getL2Context()).thenReturn(null); assertNull(manager.getEgKey(endpoint1)); when(endpoint1.getL2Context()).thenReturn(l2BridgeDomainId); when(endpoint1.getMacAddress()).thenReturn(null); assertNull(manager.getEgKey(endpoint1)); }