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.hamcrest.Matchers;
import org.junit.Assert;
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> SKILLS =
      Collections.unmodifiableSet(new HashSet<>(Arrays.asList("Cooking")));
  private static final String MUSIC = "Music";

  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(MUSIC).build();

    for (String interest : INTERESTS) {
      Assert.assertThat(
          user.getInterests(), Matchers.hasItem(Matchers.equalToIgnoringCase(interest)));
    }
    Assert.assertThat(user.getInterests(), Matchers.hasItem(Matchers.equalToIgnoringCase(MUSIC)));
  }
}

@@ -1213,32 +1213,40 @@
 %0A    User user =
+%0A       
  new User.Builde
@@ -1268,32 +1268,24 @@
             
-      
-  
 .setInterest
@@ -1305,32 +1305,24 @@
             
-        
 .setSkills(S
@@ -1336,32 +1336,24 @@
             
-    
-    
 .setEventsHo
@@ -1370,32 +1370,24 @@
 TS_HOSTING)%0A
-        
             
@@ -1440,32 +1440,24 @@
             
-  
-      
 .setEventsVo
@@ -1484,32 +1484,24 @@
 LUNTEERING)%0A
-        
             
@@ -2144,24 +2144,32 @@
 pectedUser =
+%0A       
  new User.Bu
@@ -2187,32 +2187,16 @@
  EMAIL)%0A
-                
         
@@ -2224,32 +2224,16 @@
 ERESTS)%0A
-                
         
@@ -2255,32 +2255,16 @@
 SKILLS)%0A
-                
         
@@ -2313,32 +2313,16 @@
         
-         
-       
 .setEven
@@ -2371,32 +2371,16 @@
         
-      
-          
 .setEven
@@ -2415,32 +2415,16 @@
 EERING)%0A
-                
         

Revert changes to UserTest.java.