// Project: UnitTests // Module: teststring // Source code file: StringTest.java // The unittest class StringTest tests methods // in the String class. // No String class is defined in this // module; use a fake class (e.g., FakeClass) // to use for creating a test class. import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class StringTest { private String s, t; // Initialize String objects to use in the // unit test methods test1, test2, and test3. @BeforeEach void setUp() { s = "elephant"; t = "Dog"; } // Test String toUpperCase method. @Test void test1( ) { assertEquals("ELEPHANT", s.toUpperCase()); assertEquals("dog", t.toLowerCase()); } // Test string concatenation. @Test void test2( ) { assertEquals("elephantDog", s.concat(t)); assertEquals("elephantDog", s + t); } // Test String length method. @Test void test3( ) { assertEquals(8, s.length( )); assertEquals(3, t.length( )); } }