void () { String in = """ public class A { public class B<T> extends A implements java.io.Serializable {} }"""; String what = """ class '_A { class '_B {} }"""; String by = """ class $A$ { private class $B$ { } }"""; assertEquals(""" public class A { private class B<T> extends A implements java.io.Serializable { } }""", replace(in, what, by)); String in2 = """ public class A { void m1() {} public void m2() {} public class B<T> extends A implements java.io.Serializable { int zero() { return 0; } } void m3() {} }"""; assertEquals("should replace unmatched class content correctly", """ public class A { void m1() {} public void m2() {} private class B<T> extends A implements java.io.Serializable { int zero() { return 0; } } void m3() {} }""", replace(in2, what, by)); }