Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingjian Wu committed Mar 8, 2024
1 parent d1f3036 commit b3cdf65
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@ default Lookup addValues(final String name, final Set<String> values, boolean in
default Lookup setValues(final String name, final Set<String> values) {
return null;
}

/**
* @param name lookup name
* @param value lookup value
* @return returns the lookup with the given name.
*/

default Lookup setValue(final String name, final String value) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class MySqlLookupServiceSpec extends Specification{
["1", "2", "3", "3", "4"] | 4 | true
["3", "4"] | 4 | true
["6"] | 5 | true
["1", "6"] | 6 | true
["1", "6"] | 5 | true
["1", "2", "3"] | 0 | false
["1", "2", "3", "4"] | 0 | false
["1", "2", "3", "3", "4"] | 0 | false
Expand All @@ -129,12 +129,25 @@ class MySqlLookupServiceSpec extends Specification{
def mock2LookUp = mySqlLookupService.addValues("addValues_mock2", ["4", "5", "6"] as Set<String>, true)

expect:
mock1LookUp.values == ["1", "2", "3"] as Set<String>
mock1LookUp.values.isEmpty()
mock1LookUp.values == mySqlLookupService.getValues("addValues_mock1")
areLookupsEqual(mock1LookUp, mySqlLookupService.get("addValues_mock1", false))
mock2LookUp.values == ["4", "5", "6"] as Set<String>
mock2LookUp.values == mySqlLookupService.getValues("addValues_mock2")
areLookupsEqual(mock2LookUp, mySqlLookupService.get("addValues_mock2", true))
}

def "test setValue for different id"(){
when:
def mock1LookUp = mySqlLookupService.setValues("mock1", ["1", "2", "3"] as Set<String>)
def mock2LookUp = mySqlLookupService.setValues("mock2", ["4", "5", "6"] as Set<String>)
then:
mock1LookUp.values == ["1", "2", "3"] as Set<String>
mock1LookUp.values == mySqlLookupService.getValues("mock1")
areLookupsEqual(mock1LookUp, mySqlLookupService.get("mock1", true))
mock2LookUp.values == ["4", "5", "6"] as Set<String>
mock2LookUp.values == mySqlLookupService.getValues("mock2")
areLookupsEqual(mock2LookUp, mySqlLookupService.get("mock2", true))
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.sql.Statement;
import java.sql.Types;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -230,6 +229,8 @@ public Lookup addValues(final String name, final Set<String> values, final boole
} else {
lookup.getValues().addAll(values);
}
} else {
lookup.setValues(values);
}
return lookup;
} catch (Exception e) {
Expand Down Expand Up @@ -264,4 +265,15 @@ public Lookup setValues(final String name, final Set<String> values) {
throw new UserMetadataServiceException(message, e);
}
}
/**
* Saves the lookup value.
*
* @param name lookup name
* @param value lookup value
* @return returns the lookup with the given name.
*/
@Override
public Lookup setValue(final String name, final String value) {
return setValues(name, Sets.newHashSet(value));
}
}

0 comments on commit b3cdf65

Please sign in to comment.