Skip to main content
summaryrefslogtreecommitdiffstats
blob: b412c4f617c9553c60057feab7c4b036b999cc37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.jdk.core.type;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.TreeMap;
import org.eclipse.osee.framework.jdk.core.type.PropertyStore;
import org.junit.Assert;

/**
 * @author Roberto E. Escobar
 */
public final class PropertyStoreTestUtil {

   private PropertyStoreTestUtil() {
      // Utility Class
   }

   public static void checkArrays(String[] expArray, String[] actualArray) {
      Assert.assertEquals(expArray.length, actualArray.length);
      for (int index = 0; index < expArray.length; index++) {
         Assert.assertEquals(expArray[index], actualArray[index]);
      }
   }

   public static PropertyStore createPropertyStore() {
      PropertyStore store = new PropertyStore();
      Assert.assertEquals("", store.getId());
      Assert.assertNotNull(store.getItems());
      Assert.assertNotNull(store.getArrays());
      Assert.assertTrue(store.isEmpty());
      return store;
   }

   public static PropertyStore createPropertyStore(String id) {
      PropertyStore store = new PropertyStore(id);
      Assert.assertEquals(id, store.getId());
      Assert.assertNotNull(store.getItems());
      Assert.assertNotNull(store.getArrays());
      return store;
   }

   public static PropertyStore createPropertyStore(Map<String, Object> properties) {
      PropertyStore store = new PropertyStore(properties);
      Assert.assertEquals(properties, store.getItems());
      Assert.assertEquals(String.valueOf(properties.hashCode()), store.getId());
      Assert.assertNotNull(store.getItems());
      Assert.assertNotNull(store.getArrays());
      return store;
   }

   public static void checkEquals(PropertyStore expected, PropertyStore actual) {
      Assert.assertEquals(expected.getId(), actual.getId());
      checkPropertiesEqual(expected.getItems(), actual.getItems());
      checkPropertiesEqual(expected.getArrays(), actual.getArrays());
      checkPropertiesEqual(expected.getPropertyStores(), actual.getPropertyStores());
   }

   public static void checkPropertiesEqual(Map<String, Object> expected, Map<String, Object> actual) {
      Assert.assertEquals(expected.size(), actual.size());
      for (Entry<String, Object> expectedEntry : expected.entrySet()) {
         Object expectedValue = expectedEntry.getValue();
         Object actualValue = actual.get(expectedEntry.getKey());
         if (expectedValue instanceof String[]) {
            String[] expArray = (String[]) expectedValue;
            String[] actualArray = (String[]) actualValue;
            checkArrays(expArray, actualArray);
         } else {
            Assert.assertEquals(expectedValue, actualValue);
         }
      }
   }

   public static Map<String, Object> convertPropertiesToMap(Properties props) {
      Map<String, Object> result = new TreeMap<String, Object>();
      for (Entry<Object, Object> entry : props.entrySet()) {
         result.put((String) entry.getKey(), entry.getValue());
      }
      return result;
   }

}

Back to the top