| 1 | package ezvcard.util; |
| 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | |
| 5 | import java.util.Arrays; |
| 6 | import java.util.Collection; |
| 7 | import java.util.HashMap; |
| 8 | import java.util.Map; |
| 9 | |
| 10 | import org.junit.Test; |
| 11 | |
| 12 | /* |
| 13 | Copyright (c) 2012-2023, Michael Angstadt |
| 14 | All rights reserved. |
| 15 | |
| 16 | Redistribution and use in source and binary forms, with or without |
| 17 | modification, are permitted provided that the following conditions are met: |
| 18 | |
| 19 | 1. Redistributions of source code must retain the above copyright notice, this |
| 20 | list of conditions and the following disclaimer. |
| 21 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 22 | this list of conditions and the following disclaimer in the documentation |
| 23 | and/or other materials provided with the distribution. |
| 24 | |
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 26 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 29 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 30 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 32 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 | |
| 36 | The views and conclusions contained in the software and documentation are those |
| 37 | of the authors and should not be interpreted as representing official policies, |
| 38 | either expressed or implied, of the FreeBSD Project. |
| 39 | */ |
| 40 | |
| 41 | /** |
| 42 | * @author Michael Angstadt |
| 43 | */ |
| 44 | public class StringUtilsTest { |
| 45 | @Test |
| 46 | public void join() { |
| 47 | Collection<Object> values = Arrays.<Object> asList("one", "two", 3); |
| 48 | String expected = "one,two,3"; |
| 49 | String actual = StringUtils.join(values, ","); |
| 50 | assertEquals(expected, actual); |
| 51 | |
| 52 | values = Arrays.<Object> asList("one"); |
| 53 | expected = "one"; |
| 54 | actual = StringUtils.join(values, ","); |
| 55 | assertEquals(expected, actual); |
| 56 | |
| 57 | values = Arrays.asList(); |
| 58 | expected = ""; |
| 59 | actual = StringUtils.join(values, ","); |
| 60 | assertEquals(expected, actual); |
| 61 | } |
| 62 | |
| 63 | @Test |
| 64 | public void toLowerCase() { |
| 65 | Map<String, String> input = new HashMap<>(); |
| 66 | input.put("ONE", "TWO"); |
| 67 | input.put(null, "THREE"); |
| 68 | input.put("FOUR", null); |
| 69 | |
| 70 | Map<String, String> expected = new HashMap<>(); |
| 71 | expected.put("one", "two"); |
| 72 | expected.put(null, "three"); |
| 73 | expected.put("four", null); |
| 74 | |
| 75 | Map<String, String> actual = StringUtils.toLowerCase(input); |
| 76 | |
| 77 | assertEquals(expected, actual); |
| 78 | } |
| 79 | } |