-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
null and immutable list safe checks (#240)
* null and immutable list safe checks
- Loading branch information
Patrick Duin
authored
May 16, 2022
1 parent
ca9cdc6
commit f969d04
Showing
3 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/client/HiveUgiArgsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.hotels.bdp.waggledance.client; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
||
import org.junit.Test; | ||
|
||
public class HiveUgiArgsTest { | ||
|
||
@Test | ||
public void groups() throws Exception { | ||
HiveUgiArgs args = new HiveUgiArgs("user", new ArrayList<>()); | ||
assertThat("user", is(args.getUser())); | ||
asssertThatListIsMutatable(args); | ||
} | ||
|
||
private void asssertThatListIsMutatable(HiveUgiArgs args) { | ||
assertThat(args.getGroups().size(), is(0)); | ||
// List should be mutable, Hive code potentially mutates it. | ||
args.getGroups().add("user"); | ||
assertThat(args.getGroups().size(), is(1)); | ||
} | ||
|
||
@Test | ||
public void groupDefaults() throws Exception { | ||
HiveUgiArgs args = HiveUgiArgs.WAGGLE_DANCE_DEFAULT; | ||
assertThat("waggledance", is(args.getUser())); | ||
asssertThatListIsMutatable(args); | ||
} | ||
|
||
@Test | ||
public void groupsImmutable() throws Exception { | ||
HiveUgiArgs args = new HiveUgiArgs("user", Collections.emptyList()); | ||
assertThat("user", is(args.getUser())); | ||
asssertThatListIsMutatable(args); | ||
} | ||
|
||
@Test | ||
public void groupsNull() throws Exception { | ||
HiveUgiArgs args = new HiveUgiArgs("user", null); | ||
assertThat("user", is(args.getUser())); | ||
assertTrue(args.getGroups().isEmpty()); | ||
} | ||
|
||
} |