/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shardingsphere.api.hint;

import org.apache.shardingsphere.core.hint.HintManagerHolder;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public final class HintManagerTest {
    
    @Test
    public void assertSetDatabaseShardingValue() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setDatabaseShardingValue("1");
            assertTrue(HintManagerHolder.isDatabaseShardingOnly());
            assertThat(HintManagerHolder.getDatabaseShardingValues("").iterator().next().toString(), is("1"));
        }
    }
    
    @Test
    public void assertAddDatabaseShardingValueForEquals() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.addDatabaseShardingValue("logicTable", 1);
            assertThat(HintManagerHolder.getDatabaseShardingValues("logicTable").iterator().next(), is((Comparable) 1));
        }
    }
    
    @Test
    public void assertAddDatabaseShardingValueForIn() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.addDatabaseShardingValue("logicTable", 1);
            hintManager.addDatabaseShardingValue("logicTable", 3);
            hintManager.addDatabaseShardingValue("logicTable", 5);
            assertThat(HintManagerHolder.getDatabaseShardingValues("logicTable").size(), is(3));
        }
    }
    
    @Test
    public void assertAddTableShardingValueForEquals() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.addTableShardingValue("logicTable", 1);
            assertThat(HintManagerHolder.getTableShardingValues("logicTable").iterator().next(), is((Comparable) 1));
        }
    }
    
    @Test
    public void assertAddTableShardingValueForIn() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.addTableShardingValue("logicTable", 1);
            hintManager.addTableShardingValue("logicTable", 3);
            hintManager.addTableShardingValue("logicTable", 5);
            assertThat(HintManagerHolder.getTableShardingValues("logicTable").size(), is(3));
        }
    }
    
    @Test
    public void assertSetMasterRouteOnly() {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setMasterRouteOnly();
            assertTrue(HintManagerHolder.isMasterRouteOnly());
        }
    }
}

@@ -1278,19 +1278,70 @@
 ngValue(
-%221%22
+1);%0A            hintManager.setDatabaseShardingValue(3
 );%0A     
@@ -1478,44 +1478,20 @@
 %22%22).
-iterator().next().toString
+size
 (), is(
-%221%22
+1
 ));%0A
@@ -1502,343 +1502,81 @@
     
-%7D%0A
     
-%7D%0A    %0A    @Test%0A    public void assertAddDatabaseShardingValueForEquals() %7B%0A        try (HintManager hintManager = HintManager.getInstance()) %7B%0A            hintManager.addDatabaseShardingValue(%22logicTable%22, 1);%0A            assertThat(HintManagerHolder.getDatabaseShardingValues(%22logicTable%22).iterator().next(), is((Comparable) 1
+assertTrue(HintManagerHolder.getDatabaseShardingValues(%22%22).contains(3
 ));%0A
@@ -1644,37 +1644,32 @@
 aseShardingValue
-ForIn
 () %7B%0A        try
@@ -1863,75 +1863,8 @@
 3);%0A
-            hintManager.addDatabaseShardingValue(%22logicTable%22, 5);%0A
     
@@ -1943,33 +1943,33 @@
 le%22).size(), is(
-3
+2
 ));%0A        %7D%0A  
@@ -1968,187 +1968,51 @@
     
-%7D%0A    %7D%0A    %0A    @Test%0A    public void assertAddTableShardingValueForEquals() %7B%0A        try (HintManager hintManager = HintManager.getInstance()) %7B%0A            hintManager.addTabl
+    assertTrue(HintManagerHolder.getDatabas
 eSha
@@ -2013,32 +2013,33 @@
 aseShardingValue
+s
 (%22logicTable%22, 1
@@ -2027,36 +2027,46 @@
 ues(%22logicTable%22
-, 
+).contains(
 1)
+)
 ;%0A            as
@@ -2062,35 +2062,35 @@
          assertT
-hat
+rue
 (HintManagerHold
@@ -2087,36 +2087,39 @@
 anagerHolder.get
-Tabl
+Databas
 eShardingValues(
@@ -2136,44 +2136,18 @@
 e%22).
-iterator().next(), is((Comparable) 1
+contains(3
 ));%0A
@@ -2224,13 +2224,8 @@
 alue
-ForIn
 () %7B
@@ -2429,39 +2429,56 @@
             
-hintManager.add
+assertThat(HintManagerHolder.get
 TableShardin
@@ -2475,32 +2475,33 @@
 bleShardingValue
+s
 (%22logicTable%22, 5
@@ -2501,11 +2501,23 @@
 ble%22
-, 5
+).size(), is(2)
 );%0A 
@@ -2526,35 +2526,35 @@
          assertT
-hat
+rue
 (HintManagerHold
@@ -2593,25 +2593,115 @@
 Table%22).
-size(), i
+contains(1));%0A            assertTrue(HintManagerHolder.getTableShardingValues(%22logicTable%22).contain
 s(3));%0A 

refactor HintManagerTest