// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/UserEvents.java
// public interface UserEvents {
//   void registerEvent(@NotNull String eventName);
// 
//   void registerEvent(@NotNull String eventName, @Nullable Object additionalData);
// 
//   long getLastEventTime(@NotNull String eventName);
// 
//   // most recent first
//   @NotNull
//   List<Long> getEventTimes(@NotNull String eventName);
// 
//   int getNumberOfEvents(@NotNull String eventName);
// 
//   float getEventsRate(@NotNull String eventName, int timeIntervalSeconds);
// }
// 
// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/impl/UserEventsRegistryImpl.java
// public class UserEventsRegistryImpl implements UserEventsRegistry {
//   private final EventDispatcher<UserEventsListener> myEventDispatcher = EventDispatcher.create(UserEventsListener.class);
//   private Map<Long, UserEvents> myUserEvents = new HashMap<Long, UserEvents>();
//   private final TimeService myTimeService;
// 
//   public UserEventsRegistryImpl(@NotNull TimeService timeService) {
//     myTimeService = timeService;
//   }
// 
//   @NotNull
//   public UserEvents getUserEvents(@NotNull final User user) {
//     UserEvents userEvents = myUserEvents.get(user.getId());
//     if (userEvents == null) {
//       userEvents = new UserEventsImpl(myTimeService) {
//         @Override
//         public synchronized void registerEvent(@NotNull String eventName) {
//           super.registerEvent(eventName);
//           myEventDispatcher.getMulticaster().userEventPublished(user, eventName, null);
//         }
// 
//         public void registerEvent(@NotNull String eventName, @Nullable Object additionalData) {
//           super.registerEvent(eventName);
//           myEventDispatcher.getMulticaster().userEventPublished(user, eventName, additionalData);
//         }
//       };
//       myUserEvents.put(user.getId(), userEvents);
//     }
//     return userEvents;
//   }
// 
// 
//   public void addListener(@NotNull UserEventsListener listener) {
//     myEventDispatcher.addListener(listener);
//   }
// 
//   public void removeListener(@NotNull UserEventsListener listener) {
//     myEventDispatcher.removeListener(listener);
//   }
// }


import jetbrains.buildServer.BaseTestCase;
import jetbrains.buildServer.users.SUser;
import org.jetbrains.buildserver.achievements.UserEvents;
import org.jetbrains.buildserver.achievements.impl.UserEventsRegistryImpl;
import org.jmock.Mock;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.Date;
import java.util.List;
/*
 * Copyright 2000-2021 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jetbrains.buildserver.achievements.impl;



@Test
public class UserEventsRegistryImplTest extends AchievementsTestCase {
  public void test_register_event() {
    UserEvents userEvents = getUserEvents(createUser());
    userEvents.registerEvent("event1");
    assertEquals(1, userEvents.getNumberOfEvents("event1"));

    userEvents.registerEvent("event2");
    assertEquals(1, userEvents.getNumberOfEvents("event2"));

    userEvents.registerEvent("event1");
    assertEquals(2, userEvents.getNumberOfEvents("event1"));

    assertTrue(userEvents.getEventsRate("event1", 1) > 1.5);
  }

  public void test_event_times() throws InterruptedException {
// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/UserEvents.java
// public interface UserEvents {
//   void registerEvent(@NotNull String eventName);
// 
//   void registerEvent(@NotNull String eventName, @Nullable Object additionalData);
// 
//   long getLastEventTime(@NotNull String eventName);
// 
//   // most recent first
//   @NotNull
//   List<Long> getEventTimes(@NotNull String eventName);
// 
//   int getNumberOfEvents(@NotNull String eventName);
// 
//   float getEventsRate(@NotNull String eventName, int timeIntervalSeconds);
// }
// 
// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/impl/UserEventsRegistryImpl.java
// public class UserEventsRegistryImpl implements UserEventsRegistry {
//   private final EventDispatcher<UserEventsListener> myEventDispatcher = EventDispatcher.create(UserEventsListener.class);
//   private Map<Long, UserEvents> myUserEvents = new HashMap<Long, UserEvents>();
//   private final TimeService myTimeService;
// 
//   public UserEventsRegistryImpl(@NotNull TimeService timeService) {
//     myTimeService = timeService;
//   }
// 
//   @NotNull
//   public UserEvents getUserEvents(@NotNull final User user) {
//     UserEvents userEvents = myUserEvents.get(user.getId());
//     if (userEvents == null) {
//       userEvents = new UserEventsImpl(myTimeService) {
//         @Override
//         public synchronized void registerEvent(@NotNull String eventName) {
//           super.registerEvent(eventName);
//           myEventDispatcher.getMulticaster().userEventPublished(user, eventName, null);
//         }
// 
//         public void registerEvent(@NotNull String eventName, @Nullable Object additionalData) {
//           super.registerEvent(eventName);
//           myEventDispatcher.getMulticaster().userEventPublished(user, eventName, additionalData);
//         }
//       };
//       myUserEvents.put(user.getId(), userEvents);
//     }
//     return userEvents;
//   }
// 
// 
//   public void addListener(@NotNull UserEventsListener listener) {
//     myEventDispatcher.addListener(listener);
//   }
// 
//   public void removeListener(@NotNull UserEventsListener listener) {
//     myEventDispatcher.removeListener(listener);
//   }
// }


// Path: achievements-server/src/test/java/org/jetbrains/buildServer/achievements/impl/UserEventsRegistryImplTest.java
import jetbrains.buildServer.BaseTestCase;
import jetbrains.buildServer.users.SUser;
import org.jetbrains.buildserver.achievements.UserEvents;
import org.jetbrains.buildserver.achievements.impl.UserEventsRegistryImpl;
import org.jmock.Mock;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.Date;
import java.util.List;

/*
 * Copyright 2000-2021 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jetbrains.buildserver.achievements.impl;



@Test
public class UserEventsRegistryImplTest extends AchievementsTestCase {
  public void test_register_event() {
    UserEvents userEvents = getUserEvents(createUser());
    userEvents.registerEvent("event1");
    assertEquals(1, userEvents.getNumberOfEvents("event1"));

    userEvents.registerEvent("event2");
    assertEquals(1, userEvents.getNumberOfEvents("event2"));

    userEvents.registerEvent("event1");
    assertEquals(2, userEvents.getNumberOfEvents("event1"));

    assertTrue(userEvents.getEventsRate("event1", 1) > 1.5);
  }

  public void test_event_times() throws InterruptedException {
    UserEvents userEvents = getUserEvents(createUser());