package com.google.sps;

import com.google.common.collect.ImmutableSet;
import com.google.sps.data.VolunteeringOpportunity;
import java.util.HashSet;
import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** */
@RunWith(JUnit4.class)
public final class VolunteerOpportunityTest {
  private static final String NAME = "Performer";
  private static final int NUMBER_OF_SPOTS = 240;
  private static final String PLAYING_AN_INSTRUMENT = "Playing an instrument";
  private static final String PERFORMING = "Performing";
  private static final String DANCING = "Dancing";
  private static final Set<String> SKILLS = ImmutableSet.of(PLAYING_AN_INSTRUMENT, PERFORMING);
  private static final Set<String> SKILLS_WITH_DANCING =
      ImmutableSet.of(PLAYING_AN_INSTRUMENT, PERFORMING, DANCING);

  @Test
  public void createInstanceUsingBuilder() {
    VolunteeringOpportunity opportunity =
        new VolunteeringOpportunity.Builder(NAME, NUMBER_OF_SPOTS)
            .setRequiredSkills(SKILLS)
            .build();

    Assert.assertEquals(opportunity.getName(), NAME);
    Assert.assertEquals(opportunity.getNumSpotsLeft(), NUMBER_OF_SPOTS);
    Assert.assertEquals(opportunity.getRequiredSkills(), SKILLS);
  }

  @Test
  public void getBuilderFromInstance() {
    VolunteeringOpportunity opportunity =
        new VolunteeringOpportunity.Builder(NAME, NUMBER_OF_SPOTS)
            .setRequiredSkills(SKILLS)
            .build();
    VolunteeringOpportunity copyOfOpportunity = opportunity.toBuilder().build();

    Assert.assertEquals(copyOfOpportunity.getName(), NAME);
    Assert.assertEquals(copyOfOpportunity.getNumSpotsLeft(), NUMBER_OF_SPOTS);
    Assert.assertEquals(copyOfOpportunity.getRequiredSkills(), SKILLS);
  }

  @Test
  public void addSkillsWithBuild() {
    Set<String> skills = new HashSet<String>();
    skills.add(PLAYING_AN_INSTRUMENT);
    skills.add(PERFORMING);
    VolunteeringOpportunity opportunityWithSkills =
        new VolunteeringOpportunity.Builder(NAME, NUMBER_OF_SPOTS)
            .setRequiredSkills(skills)
            .build();
    VolunteeringOpportunity changedOpportunity =
        opportunityWithSkills.toBuilder().addRequiredSkill(DANCING).build();
    
    Assert.assertEquals(SKILLS_WITH_DANCING, changedOpportunity.getRequiredSkills());
  }

  @Test
  public void removeSkillsWithBuild() {
    Set<String> skills = new HashSet<String>();
    skills.add(PLAYING_AN_INSTRUMENT);
    skills.add(PERFORMING);
    skills.add(DANCING);
    VolunteeringOpportunity opportunityWithSkills =
        new VolunteeringOpportunity.Builder(NAME, NUMBER_OF_SPOTS)
            .setRequiredSkills(skills)
            .build();
    VolunteeringOpportunity changedOpportunity =
        opportunityWithSkills.toBuilder().removeRequiredSkill(DANCING).build();

    Assert.assertEquals(SKILLS, changedOpportunity.getRequiredSkills());
  }
}

@@ -1104,32 +1104,38 @@
 rt.assertEquals(
+NAME, 
 opportunity.getN
@@ -1131,38 +1131,32 @@
 tunity.getName()
-, NAME
 );%0A    Assert.as
@@ -1158,32 +1158,49 @@
 rt.assertEquals(
+NUMBER_OF_SPOTS, 
 opportunity.getN
@@ -1212,33 +1212,16 @@
 tsLeft()
-, NUMBER_OF_SPOTS
 );%0A    A
@@ -1239,16 +1239,24 @@
 tEquals(
+SKILLS, 
 opportun
@@ -1274,32 +1274,24 @@
 iredSkills()
-, SKILLS
 );%0A  %7D%0A%0A  @T
@@ -1603,32 +1603,38 @@
 rt.assertEquals(
+NAME, 
 copyOfOpportunit
@@ -1648,14 +1648,8 @@
 me()
-, NAME
 );%0A 
@@ -1663,32 +1663,49 @@
 rt.assertEquals(
+NUMBER_OF_SPOTS, 
 copyOfOpportunit
@@ -1723,33 +1723,16 @@
 tsLeft()
-, NUMBER_OF_SPOTS
 );%0A    A
@@ -1750,16 +1750,24 @@
 tEquals(
+SKILLS, 
 copyOfOp
@@ -1799,16 +1799,8 @@
 ls()
-, SKILLS
 );%0A 

Fix from code review.