I have example to ilustrate my problem:
package com.example;
public class ExamplePublicClass {
public void doSomething() {
// a lot of code
String message = new ExamplePublicClass.MessageBuilder().withName("someName").build();
// a lot of code
}
private static class MessageBuilder {
private String name;
public MessageBuilder withName(String name) {
this.name = name;
return this;
}
public String build() {
return this.name + 1;
}
}
}
doSomething() method doing a lot o things and there is a lot o legacy code but it works and I don't want to touch her.
Only what I want to do is a change a builder to creating a log message and write a test for him. The problem is the fact that MessageBuilder is a private class and is doesn't make sense to change it to public.In additonal I don't want to changing visibility through reflection.
I added a class for test in the same package
package com.example;
import org.junit.Test;
public class MessageBuilderTest {
@Test
public void testMessageBuilder() {
String s = MessageBuilder..
}
}
but I don't have access to this private class :(
Working code is located in
src/main/java
and test code is located
src/test/java
What do you thing? Should I change project structure to
src |/main/java |/test/java
?
Or exist better solution?
Best Regards T