Code formatting.
[svjatoslav_commons.git] / src / test / java / eu / svjatoslav / commons / string / String2Test.java
1 /*
2  * Svjatoslav Commons - shared library of common functionality.
3  * Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.commons.string;
11
12 import org.junit.Test;
13
14 import static org.junit.Assert.assertEquals;
15
16 public class String2Test {
17
18     @Test
19     public void testTrimPrefix() {
20
21         final String2 s = new String2("this is a test");
22
23         assertEquals("is a test", s.trimPrefix(5).toString());
24         assertEquals("a test", s.trimPrefix(3).toString());
25         assertEquals("test", s.trimPrefix(2).toString());
26         assertEquals("", s.trimPrefix(500).toString());
27     }
28
29     @Test
30     public void testTrimSuffix() {
31
32         final String2 s = new String2("this is a test");
33
34         assertEquals("this is a", s.trimSuffix(5).toString());
35         assertEquals("this is", s.trimSuffix(2).toString());
36         assertEquals("this", s.trimSuffix(3).toString());
37         assertEquals("", s.trimSuffix(500).toString());
38     }
39
40
41     @Test
42     public void testEnforceLength() {
43         final String2 s = new String2("12345678");
44         s.enforceLength(3);
45         assertEquals("123", s.toString());
46
47         s.enforceLength(5);
48         assertEquals("123  ", s.toString());
49     }
50
51     @Test
52     public void testSuffixAndPrefix() {
53         final String2 s = new String2("experiment");
54         s.addPrefix("The ").addSuffix(" !");
55
56         assertEquals("The experiment !", s.toString());
57     }
58
59 }