begin_unit|revision:0.9.5;language:Java;cregit-version:0.0.1
begin_comment
comment|// Copyright (C) 2014 The Android Open Source Project
end_comment

begin_comment
comment|//
end_comment

begin_comment
comment|// Licensed under the Apache License, Version 2.0 (the "License");
end_comment

begin_comment
comment|// you may not use this file except in compliance with the License.
end_comment

begin_comment
comment|// You may obtain a copy of the License at
end_comment

begin_comment
comment|//
end_comment

begin_comment
comment|// http://www.apache.org/licenses/LICENSE-2.0
end_comment

begin_comment
comment|//
end_comment

begin_comment
comment|// Unless required by applicable law or agreed to in writing, software
end_comment

begin_comment
comment|// distributed under the License is distributed on an "AS IS" BASIS,
end_comment

begin_comment
comment|// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
end_comment

begin_comment
comment|// See the License for the specific language governing permissions and
end_comment

begin_comment
comment|// limitations under the License.
end_comment

begin_package
DECL|package|com.google.gerrit.server.project
package|package
name|com
operator|.
name|google
operator|.
name|gerrit
operator|.
name|server
operator|.
name|project
package|;
end_package

begin_import
import|import static
name|org
operator|.
name|junit
operator|.
name|Assert
operator|.
name|assertEquals
import|;
end_import

begin_import
import|import static
name|org
operator|.
name|junit
operator|.
name|Assert
operator|.
name|assertNotNull
import|;
end_import

begin_import
import|import static
name|org
operator|.
name|junit
operator|.
name|Assert
operator|.
name|assertNull
import|;
end_import

begin_import
import|import static
name|org
operator|.
name|junit
operator|.
name|Assert
operator|.
name|assertTrue
import|;
end_import

begin_import
import|import static
name|org
operator|.
name|mockito
operator|.
name|ArgumentMatchers
operator|.
name|any
import|;
end_import

begin_import
import|import static
name|org
operator|.
name|mockito
operator|.
name|Mockito
operator|.
name|mock
import|;
end_import

begin_import
import|import static
name|org
operator|.
name|mockito
operator|.
name|Mockito
operator|.
name|times
import|;
end_import

begin_import
import|import static
name|org
operator|.
name|mockito
operator|.
name|Mockito
operator|.
name|verify
import|;
end_import

begin_import
import|import
name|com
operator|.
name|google
operator|.
name|gerrit
operator|.
name|common
operator|.
name|data
operator|.
name|GroupReference
import|;
end_import

begin_import
import|import
name|com
operator|.
name|google
operator|.
name|gerrit
operator|.
name|entities
operator|.
name|AccountGroup
import|;
end_import

begin_import
import|import
name|com
operator|.
name|google
operator|.
name|gerrit
operator|.
name|entities
operator|.
name|Project
import|;
end_import

begin_import
import|import
name|com
operator|.
name|google
operator|.
name|gerrit
operator|.
name|server
operator|.
name|git
operator|.
name|ValidationError
import|;
end_import

begin_import
import|import
name|java
operator|.
name|io
operator|.
name|IOException
import|;
end_import

begin_import
import|import
name|java
operator|.
name|util
operator|.
name|Collection
import|;
end_import

begin_import
import|import
name|java
operator|.
name|util
operator|.
name|Collections
import|;
end_import

begin_import
import|import
name|java
operator|.
name|util
operator|.
name|Set
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|Before
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|Test
import|;
end_import

begin_class
DECL|class|GroupListTest
specifier|public
class|class
name|GroupListTest
block|{
DECL|field|PROJECT
specifier|private
specifier|static
specifier|final
name|Project
operator|.
name|NameKey
name|PROJECT
init|=
name|Project
operator|.
name|nameKey
argument_list|(
literal|"project"
argument_list|)
decl_stmt|;
DECL|field|TEXT
specifier|private
specifier|static
specifier|final
name|String
name|TEXT
init|=
literal|"# UUID                                  \tGroup Name\n"
operator|+
literal|"#\n"
operator|+
literal|"d96b998f8a66ff433af50befb975d0e2bb6e0999\tNon-Interactive Users\n"
operator|+
literal|"ebe31c01aec2c9ac3b3c03e87a47450829ff4310\tAdministrators\n"
decl_stmt|;
DECL|field|groupList
specifier|private
name|GroupList
name|groupList
decl_stmt|;
annotation|@
name|Before
DECL|method|setup ()
specifier|public
name|void
name|setup
parameter_list|()
throws|throws
name|IOException
block|{
name|ValidationError
operator|.
name|Sink
name|sink
init|=
name|mock
argument_list|(
name|ValidationError
operator|.
name|Sink
operator|.
name|class
argument_list|)
decl_stmt|;
name|groupList
operator|=
name|GroupList
operator|.
name|parse
argument_list|(
name|PROJECT
argument_list|,
name|TEXT
argument_list|,
name|sink
argument_list|)
expr_stmt|;
block|}
annotation|@
name|Test
DECL|method|byUUID ()
specifier|public
name|void
name|byUUID
parameter_list|()
throws|throws
name|Exception
block|{
name|AccountGroup
operator|.
name|UUID
name|uuid
init|=
name|AccountGroup
operator|.
name|uuid
argument_list|(
literal|"d96b998f8a66ff433af50befb975d0e2bb6e0999"
argument_list|)
decl_stmt|;
name|GroupReference
name|groupReference
init|=
name|groupList
operator|.
name|byUUID
argument_list|(
name|uuid
argument_list|)
decl_stmt|;
name|assertEquals
argument_list|(
name|uuid
argument_list|,
name|groupReference
operator|.
name|getUUID
argument_list|()
argument_list|)
expr_stmt|;
name|assertEquals
argument_list|(
literal|"Non-Interactive Users"
argument_list|,
name|groupReference
operator|.
name|getName
argument_list|()
argument_list|)
expr_stmt|;
block|}
annotation|@
name|Test
DECL|method|put ()
specifier|public
name|void
name|put
parameter_list|()
block|{
name|AccountGroup
operator|.
name|UUID
name|uuid
init|=
name|AccountGroup
operator|.
name|uuid
argument_list|(
literal|"abc"
argument_list|)
decl_stmt|;
name|GroupReference
name|groupReference
init|=
operator|new
name|GroupReference
argument_list|(
name|uuid
argument_list|,
literal|"Hutzliputz"
argument_list|)
decl_stmt|;
name|groupList
operator|.
name|put
argument_list|(
name|uuid
argument_list|,
name|groupReference
argument_list|)
expr_stmt|;
name|assertEquals
argument_list|(
literal|3
argument_list|,
name|groupList
operator|.
name|references
argument_list|()
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
name|GroupReference
name|found
init|=
name|groupList
operator|.
name|byUUID
argument_list|(
name|uuid
argument_list|)
decl_stmt|;
name|assertEquals
argument_list|(
name|groupReference
argument_list|,
name|found
argument_list|)
expr_stmt|;
block|}
annotation|@
name|Test
DECL|method|references ()
specifier|public
name|void
name|references
parameter_list|()
throws|throws
name|Exception
block|{
name|Collection
argument_list|<
name|GroupReference
argument_list|>
name|result
init|=
name|groupList
operator|.
name|references
argument_list|()
decl_stmt|;
name|assertEquals
argument_list|(
literal|2
argument_list|,
name|result
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
name|AccountGroup
operator|.
name|UUID
name|uuid
init|=
name|AccountGroup
operator|.
name|uuid
argument_list|(
literal|"ebe31c01aec2c9ac3b3c03e87a47450829ff4310"
argument_list|)
decl_stmt|;
name|GroupReference
name|expected
init|=
operator|new
name|GroupReference
argument_list|(
name|uuid
argument_list|,
literal|"Administrators"
argument_list|)
decl_stmt|;
name|assertTrue
argument_list|(
name|result
operator|.
name|contains
argument_list|(
name|expected
argument_list|)
argument_list|)
expr_stmt|;
block|}
annotation|@
name|Test
DECL|method|uUIDs ()
specifier|public
name|void
name|uUIDs
parameter_list|()
throws|throws
name|Exception
block|{
name|Set
argument_list|<
name|AccountGroup
operator|.
name|UUID
argument_list|>
name|result
init|=
name|groupList
operator|.
name|uuids
argument_list|()
decl_stmt|;
name|assertEquals
argument_list|(
literal|2
argument_list|,
name|result
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
name|AccountGroup
operator|.
name|UUID
name|expected
init|=
name|AccountGroup
operator|.
name|uuid
argument_list|(
literal|"ebe31c01aec2c9ac3b3c03e87a47450829ff4310"
argument_list|)
decl_stmt|;
name|assertTrue
argument_list|(
name|result
operator|.
name|contains
argument_list|(
name|expected
argument_list|)
argument_list|)
expr_stmt|;
block|}
annotation|@
name|Test
DECL|method|validationError ()
specifier|public
name|void
name|validationError
parameter_list|()
throws|throws
name|Exception
block|{
name|ValidationError
operator|.
name|Sink
name|sink
init|=
name|mock
argument_list|(
name|ValidationError
operator|.
name|Sink
operator|.
name|class
argument_list|)
decl_stmt|;
name|groupList
operator|=
name|GroupList
operator|.
name|parse
argument_list|(
name|PROJECT
argument_list|,
name|TEXT
operator|.
name|replace
argument_list|(
literal|"\t"
argument_list|,
literal|"    "
argument_list|)
argument_list|,
name|sink
argument_list|)
expr_stmt|;
name|verify
argument_list|(
name|sink
argument_list|,
name|times
argument_list|(
literal|2
argument_list|)
argument_list|)
operator|.
name|error
argument_list|(
name|any
argument_list|(
name|ValidationError
operator|.
name|class
argument_list|)
argument_list|)
expr_stmt|;
block|}
annotation|@
name|Test
DECL|method|retainAll ()
specifier|public
name|void
name|retainAll
parameter_list|()
throws|throws
name|Exception
block|{
name|AccountGroup
operator|.
name|UUID
name|uuid
init|=
name|AccountGroup
operator|.
name|uuid
argument_list|(
literal|"d96b998f8a66ff433af50befb975d0e2bb6e0999"
argument_list|)
decl_stmt|;
name|groupList
operator|.
name|retainUUIDs
argument_list|(
name|Collections
operator|.
name|singleton
argument_list|(
name|uuid
argument_list|)
argument_list|)
expr_stmt|;
name|assertNotNull
argument_list|(
name|groupList
operator|.
name|byUUID
argument_list|(
name|uuid
argument_list|)
argument_list|)
expr_stmt|;
name|assertNull
argument_list|(
name|groupList
operator|.
name|byUUID
argument_list|(
name|AccountGroup
operator|.
name|uuid
argument_list|(
literal|"ebe31c01aec2c9ac3b3c03e87a47450829ff4310"
argument_list|)
argument_list|)
argument_list|)
expr_stmt|;
block|}
annotation|@
name|Test
DECL|method|asText ()
specifier|public
name|void
name|asText
parameter_list|()
throws|throws
name|Exception
block|{
name|assertTrue
argument_list|(
name|TEXT
operator|.
name|equals
argument_list|(
name|groupList
operator|.
name|asText
argument_list|()
argument_list|)
argument_list|)
expr_stmt|;
block|}
block|}
end_class

end_unit

