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();

    String actualName = opportunity.getName();
    String expectedName = NAME;
    int actualNumSpotsLeft = opportunity.getNumSpotsLeft();
    int expectedNumSpotsLeft = NUMBER_OF_SPOTS;
    Set<String> actualSkills = opportunity.getRequiredSkills();
    Set<String> expectedSkills = SKILLS;

    Assert.assertEquals(actualName, expectedName);
    Assert.assertEquals(actualNumSpotsLeft, expectedNumSpotsLeft);
    Assert.assertEquals(actualSkills, expectedSkills);
  }

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

    String actualName = copyOfOpportunity.getName();
    String expectedName = NAME;
    int actualNumSpotsLeft = copyOfOpportunity.getNumSpotsLeft();
    int expectedNumSpotsLeft = NUMBER_OF_SPOTS;
    Set<String> actualSkills = copyOfOpportunity.getRequiredSkills();
    Set<String> expectedSkills = SKILLS;

    Assert.assertEquals(actualName, expectedName);
    Assert.assertEquals(actualNumSpotsLeft, expectedNumSpotsLeft);
    Assert.assertEquals(actualSkills, expectedSkills);
  }

  @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();

    Set<String> actual = changedOpportunity.getRequiredSkills();
    Set<String> expected = SKILLS_WITH_DANCING;

    Assert.assertEquals(expected, actual);
  }

  @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();

    Set<String> actual = changedOpportunity.getRequiredSkills();
    Set<String> expected = SKILLS;

    Assert.assertEquals(expected, actual);
  }
}

@@ -1092,36 +1092,36 @@
 );%0A%0A    
-String actualName = 
+Assert.assertEquals(
 opportun
@@ -1137,71 +1137,41 @@
 me()
-;%0A    String expectedName =
+,
  NAME
+)
 ;%0A    
-int actualNumSpotsLeft = 
+Assert.assertEquals(
 oppo
@@ -1199,40 +1199,9 @@
 ft()
-;%0A    int expectedNumSpotsLeft =
+,
  NUM
@@ -1216,41 +1216,35 @@
 POTS
+)
 ;%0A    
-Set%3CString%3E actualSkills = 
+Assert.assertEquals(
 oppo
@@ -1274,222 +1274,16 @@
 ls()
-;%0A    Set%3CString%3E expectedSkills = SKILLS;%0A%0A    Assert.assertEquals(actualName, expectedName);%0A    Assert.assertEquals(actualNumSpotsLeft, expectedNumSpotsLeft);%0A    Assert.assertEquals(actualSkills, expectedSkills
+, SKILLS
 );%0A 
@@ -1595,28 +1595,28 @@
     
-String actualName = 
+Assert.assertEquals(
 copy
@@ -1642,71 +1642,41 @@
 me()
-;%0A    String expectedName =
+,
  NAME
+)
 ;%0A    
-int actualNumSpotsLeft = 
+Assert.assertEquals(
 copy
@@ -1710,40 +1710,9 @@
 ft()
-;%0A    int expectedNumSpotsLeft =
+,
  NUM
@@ -1727,41 +1727,35 @@
 POTS
+)
 ;%0A    
-Set%3CString%3E actualSkills = 
+Assert.assertEquals(
 copy
@@ -1791,222 +1791,16 @@
 ls()
-;%0A    Set%3CString%3E expectedSkills = SKILLS;%0A%0A    Assert.assertEquals(actualName, expectedName);%0A    Assert.assertEquals(actualNumSpotsLeft, expectedNumSpotsLeft);%0A    Assert.assertEquals(actualSkills, expectedSkills
+, SKILLS
 );%0A 
@@ -2273,163 +2273,96 @@
 ();%0A
+    
 %0A    
-Set%3CString%3E actual = changedOpportunity.getRequiredSkills();%0A    Set%3CString%3E expected = SKILLS_WITH_DANCING;%0A%0A    Assert.assertEquals(expected, actual
+Assert.assertEquals(SKILLS_WITH_DANCING, changedOpportunity.getRequiredSkills()
 );%0A 
@@ -2871,28 +2871,35 @@
     
-Set%3CString%3E actual =
+Assert.assertEquals(SKILLS,
  cha
@@ -2937,86 +2937,8 @@
 ls()
-;%0A    Set%3CString%3E expected = SKILLS;%0A%0A    Assert.assertEquals(expected, actual
 );%0A 

Fix from code review.