Skip to content

Commit bc9a578

Browse files
surajdm123google-java-format Team
authored andcommitted
Added JUnit Test Cases for Replacement
### Changes This PR adds the missing unit test case for Replacement. **Before:** <img width="938" height="315" alt="Screenshot 2025-07-16 at 10 26 05 PM" src="https://github.com/user-attachments/assets/47a08af5-b240-40ba-8abf-9f20dce46c22" /> **After:** <img width="947" height="315" alt="Screenshot 2025-07-16 at 10 24 41 PM" src="https://github.com/user-attachments/assets/2a18ffca-0b75-4e18-b071-7246c438ce29" /> ### Test Plan > mvn -Dtest=ReplacementTest test ``` ... [INFO] Running com.google.googlejavaformat.java.ReplacementTest [INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.068 s - in com.google.googlejavaformat.java.ReplacementTest [INFO] [INFO] Results: [INFO] [INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ ``` ---- > mvn test ``` [INFO] Results: [INFO] [INFO] Tests run: 1533, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 12.168 s [INFO] Finished at: 2025-07-16T22:30:47-07:00 [INFO] ------------------------------------------------------------------------ ``` ### Next Steps - Add more missing test cases to make this codebase more resilient. Fixes #1268 COPYBARA_INTEGRATE_REVIEW=#1268 from surajdm123:add-test 1bad87c PiperOrigin-RevId: 784313467
1 parent e895346 commit bc9a578

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2025 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
package com.google.googlejavaformat.java;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
import static org.junit.Assert.assertThrows;
19+
20+
import com.google.common.collect.Range;
21+
import com.google.common.testing.EqualsTester;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.junit.runners.JUnit4;
25+
26+
/** {@link Replacement}Test */
27+
@RunWith(JUnit4.class)
28+
public class ReplacementTest {
29+
30+
@Test
31+
public void testCreateWithValidInput() {
32+
Replacement replacement = Replacement.create(3, 7, "replacementText");
33+
assertThat(replacement.getReplaceRange()).isEqualTo(Range.closedOpen(3, 7));
34+
assertThat(replacement.getReplacementString()).isEqualTo("replacementText");
35+
}
36+
37+
@Test
38+
public void invalidReplacementRange() {
39+
assertThrows(IllegalArgumentException.class, () -> Replacement.create(-1, 5, "text"));
40+
assertThrows(IllegalArgumentException.class, () -> Replacement.create(10, 5, "text"));
41+
}
42+
43+
@Test
44+
public void testEqualsAndHashCode() {
45+
new EqualsTester()
46+
.addEqualityGroup(Replacement.create(0, 4, "abc"), Replacement.create(0, 4, "abc"))
47+
.addEqualityGroup(Replacement.create(1, 4, "abc"))
48+
.addEqualityGroup(Replacement.create(0, 4, "def"))
49+
.testEquals();
50+
}
51+
}

0 commit comments

Comments
 (0)