@CheckForNull
String getBranch();
+ /**
+ * @throws IllegalStateException if root component ref has not been set
+ */
+ int getRootComponentRef();
+
}
import static com.google.common.base.Preconditions.checkState;
public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder {
- @CheckForNull
+
private InitializedProperty<Long> analysisDate = new InitializedProperty<>();
private InitializedProperty<Snapshot> baseProjectSnapshot = new InitializedProperty<>();
- @CheckForNull
private InitializedProperty<Boolean> crossProjectDuplicationEnabled = new InitializedProperty<>();
private InitializedProperty<String> branch = new InitializedProperty<>();
+ private InitializedProperty<Integer> rootComponentRef = new InitializedProperty<>();
+
@Override
public void setAnalysisDate(Date date) {
checkNotNull(date, "Date must not be null");
return branch.getProperty();
}
+ @Override
+ public void setRootComponentRef(int rootComponentRef) {
+ checkState(!this.rootComponentRef.isInitialized(), "Root component ref has already been set");
+ this.rootComponentRef.setProperty(rootComponentRef);
+ }
+
+ @Override
+ public int getRootComponentRef() {
+ checkState(rootComponentRef.isInitialized(), "Root component ref has not been set");
+ return rootComponentRef.getProperty();
+ }
+
private static class InitializedProperty<E> {
private E property;
private boolean initialized = false;
return initialized;
}
}
+
}
*/
void setBranch(@Nullable String branch);
+ /**
+ * @throws IllegalStateException if root component ref has already been set
+ */
+ void setRootComponentRef(int rootComponentRef);
+
}
expectedException.expectMessage("Branch has already been set");
underTest.setBranch("origin/master");
}
+
+ @Test
+ public void getRootComponentRef() throws InterruptedException {
+ AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
+
+ underTest.setRootComponentRef(10);
+
+ assertThat(underTest.getRootComponentRef()).isEqualTo(10);
+ }
+
+ @Test
+ public void getRootComponentRef_throws_ISE_when_holder_is_not_initialized() {
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Root component ref has not been set");
+
+ new AnalysisMetadataHolderImpl().getRootComponentRef();
+ }
+
+ @Test
+ public void setRootComponentRef_throws_ISE_when_called_twice() {
+ AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
+ underTest.setRootComponentRef(10);
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Root component ref has already been set");
+ underTest.setRootComponentRef(9);
+ }
}
public void setBranch(@Nullable String branch) {
delegate.setBranch(branch);
}
+
+ @Override
+ public void setRootComponentRef(int rootComponentRef) {
+ delegate.setRootComponentRef(rootComponentRef);
+ }
+
+ @Override
+ public int getRootComponentRef() {
+ return delegate.getRootComponentRef();
+ }
}