|
| 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