package com.google.sps;

import com.google.sps.data.Event;
import com.google.sps.data.User;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;


/** */
@RunWith(JUnit4.class)
public final class UserTest {
  private static final String NAME = "Bob Smith";
  private static final String EMAIL = "bobsmith@example.com";
  private static final Set<String> INTERESTS =
      new HashSet<>(Arrays.asList("Conservation", "Food"));
  private static final Set<String> NEW_INTERESTS =
      new HashSet<>(Arrays.asList("Conservation", "Food", "Music"));
  private static final Set<String> SKILLS =
      new HashSet<>(Arrays.asList("Cooking"));
  private static final String NEW_INTEREST = "Music";

  // The following fields will be instantiated with meaningful Events after the Events class is
  // written to follow the Builder pattern.
  private static final Set<Event> EVENTS_HOSTING = Collections.emptySet();
  private static final Set<Event> EVENTS_PARTICIPATING = Collections.emptySet();
  private static final Set<Event> EVENTS_VOLUNTEERING = Collections.emptySet();

  @Test
  public void buildInstanceWithAllFields() {
    // Create a User with all fields set, and verify that all fields are correctly set
    User user = new User.Builder(NAME, EMAIL)
        .setInterests(INTERESTS)
        .setSkills(SKILLS)
        .setEventsHosting(EVENTS_HOSTING)
        .setEventsParticipating(EVENTS_PARTICIPATING)
        .setEventsVolunteering(EVENTS_VOLUNTEERING)
        .build();
    
    Assert.assertEquals(NAME, user.getName());
    Assert.assertEquals(EMAIL, user.getEmail());
    Assert.assertEquals(INTERESTS, user.getInterests());
    Assert.assertEquals(SKILLS, user.getSkills());
    Assert.assertEquals(EVENTS_HOSTING, user.getEventsHosting());
    Assert.assertEquals(EVENTS_PARTICIPATING, user.getEventsParticipating());
    Assert.assertEquals(EVENTS_VOLUNTEERING, user.getEventsVolunteering());
  }

  @Test
  public void transferInstanceToBuilderWithAllFields() {
    // Create a User with all fields set, and check that its fields can be correctly transferred to its Builder.
    User expectedUser = new User.Builder(NAME, EMAIL)
        .setInterests(INTERESTS)
        .setSkills(SKILLS)
        .setEventsHosting(EVENTS_HOSTING)
        .setEventsParticipating(EVENTS_PARTICIPATING)
        .setEventsVolunteering(EVENTS_VOLUNTEERING)
        .build();
    
    User actualUser = expectedUser.toBuilder().build();
    Assert.assertTrue(EqualsBuilder.reflectionEquals(expectedUser, actualUser));
  }

  @Test
  public void addToExistingInterests() {
    // Add a new interest to a User's existing set of interests.
    User user = new User.Builder(NAME, EMAIL)
        .setInterests(INTERESTS)
        .build();
    
    user = user.toBuilder().addInterest(NEW_INTEREST).build();

    Assert.assertEquals(NEW_INTERESTS, user.getInterests());
  }
}

@@ -272,33 +272,8 @@
 rt;%0A
-import org.junit.Ignore;%0A
 impo
@@ -569,38 +569,32 @@
 ing%3E INTERESTS =
-%0A     
  new HashSet%3C%3E(A
@@ -682,16 +682,17 @@
 ERESTS =
+ 
 %0A      n
@@ -796,22 +796,16 @@
 SKILLS =
-%0A     
  new Has
@@ -1418,32 +1418,41 @@
     User user = 
+%0A        
 new User.Builder
@@ -1465,32 +1465,36 @@
  EMAIL)%0A        
+    
 .setInterests(IN
@@ -1494,32 +1494,36 @@
 ests(INTERESTS)%0A
+    
         .setSkil
@@ -1533,32 +1533,36 @@
 SKILLS)%0A        
+    
 .setEventsHostin
@@ -1571,32 +1571,36 @@
 EVENTS_HOSTING)%0A
+    
         .setEven
@@ -1637,32 +1637,36 @@
 PATING)%0A        
+    
 .setEventsVolunt
@@ -1685,32 +1685,36 @@
 S_VOLUNTEERING)%0A
+    
         .build()
@@ -2313,16 +2313,23 @@
 erred to
+%0A    //
  its Bui
@@ -2353,24 +2353,32 @@
 pectedUser =
+%0A       
  new User.Bu
@@ -2396,32 +2396,36 @@
  EMAIL)%0A        
+    
 .setInterests(IN
@@ -2433,32 +2433,36 @@
 ERESTS)%0A        
+ 
+   
 .setSkills(SKILL
@@ -2456,32 +2456,36 @@
 tSkills(SKILLS)%0A
+    
         .setEven
@@ -2510,32 +2510,36 @@
 OSTING)%0A        
+   
+ 
 .setEventsPartic
@@ -2568,32 +2568,36 @@
 PATING)%0A        
+    
 .setEventsVolunt
@@ -2616,32 +2616,36 @@
 S_VOLUNTEERING)%0A
+    
         .build()
@@ -2952,25 +2952,16 @@
 , EMAIL)
-%0A        
 .setInte
@@ -2976,25 +2976,16 @@
 TERESTS)
-%0A        
 .build()
@@ -2982,29 +2982,24 @@
 S).build();%0A
-    %0A
     user = u

Fix PreSubmit failures in UserTest.java