1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /** 19 * @author Vladimir N. Molotkov 20 * @version $Revision$ 21 */ 22 23 package org.apache.harmony.security.tests.support; 24 25 import java.util.Properties; 26 27 /** 28 * Test utility class 29 */ 30 public class TestUtils { 31 32 /** 33 * No need to instantiate 34 */ 35 private TestUtils() { 36 } 37 38 /** 39 * Prints byte array <code>data</code> as hex to the 40 * <code>System.out</code> in the customizable form. 41 * 42 * @param perLine how many numbers put on single line 43 * @param prefix custom output number prefix 44 * @param delimiter custom output number delimiter 45 * @param data data to be printed 46 */ 47 public static void printAsHex(int perLine, 48 String prefix, 49 String delimiter, 50 byte[] data) { 51 for (int i=0; i<data.length; i++) { 52 String tail = Integer.toHexString(0x000000ff & data[i]); 53 if (tail.length() == 1) { 54 tail = "0" + tail; 55 } 56 System.out.print(prefix + "0x" + tail + delimiter); 57 58 if (((i+1)%perLine) == 0) { 59 System.out.println(""); 60 } 61 } 62 System.out.println(""); 63 } 64 65 /** 66 * Sets system property 67 * 68 * @param key - the name of the system property. 69 * @param value - the value to be set 70 */ 71 public static void setSystemProperty(String key, String value) { 72 Properties properties = System.getProperties(); 73 if (value == null) { 74 properties.remove(key); 75 } else { 76 properties.setProperty(key, value); 77 } 78 System.setProperties(properties); 79 } 80 } 81