/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.security;

import org.junit.Assert;
import org.junit.Test;

import java.util.Set;

import javax.security.auth.Subject;

/**
 * Unit test for {@link User}.
 */
public final class UserTest {

  /**
   * This test verifies whether the {@link User} could be used in Java security
   * framework.
   */
  @Test
  public void usedInSecurityContext() {
    // Add new users into Subject.
    Subject subject = new Subject();
    subject.getPrincipals().add(new User("realUser"));
    subject.getPrincipals().add(new User("proxyUser"));

    // Fetch added users.
    Set<User> users = subject.getPrincipals(User.class);

    // Verification.
    Assert.assertEquals(2, users.size());

    // Test equals.
    Assert.assertTrue(users.contains(new User("realUser")));
    Assert.assertFalse(users.contains(new User("noExistingUser")));
  }

  /**
   * This test verifies that full realm format is valid as {@link User} name.
   */
  @Test
  public void realmAsUserName() {
    // Add new users into Subject.
    Subject subject = new Subject();
    subject.getPrincipals().add(new User("admin/admin@EXAMPLE.com"));
    subject.getPrincipals().add(new User("admin/mbox.example.com@EXAMPLE.com"));
    subject.getPrincipals().add(new User("imap/mbox.example.com@EXAMPLE.COM"));

    // Fetch added users.
    Set<User> users = subject.getPrincipals(User.class);
    Assert.assertEquals(3, users.size());

    // Add similar user name without domain name.
    subject.getPrincipals().add(new User("admin"));
    subject.getPrincipals().add(new User("imap"));

    users = subject.getPrincipals(User.class);
    Assert.assertEquals(5, users.size());
  }
}

@@ -533,32 +533,39 @@
 curity;%0A%0Aimport 
+static 
 org.junit.Assert
@@ -564,17 +564,119 @@
 t.Assert
-;
+.assertFalse;%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0A%0A
 %0Aimport 
@@ -1267,31 +1267,24 @@
 cation.%0A    
-Assert.
 assertEquals
@@ -1323,31 +1323,24 @@
 equals.%0A    
-Assert.
 assertTrue(u
@@ -1377,31 +1377,24 @@
 er%22)));%0A    
-Assert.
 assertFalse(
@@ -1958,39 +1958,32 @@
 ser.class);%0A    
-Assert.
 assertEquals(3, 
@@ -2203,23 +2203,16 @@
 s);%0A    
-Assert.
 assertEq

add static import for class UserTest