### Question:
CcCourtChartXSettingsGenerator implements XSettingsGenerator { @Override public XSettings generateXSettings(JudgmentGlobalFilter judgmentGlobalFilter) { Preconditions.checkArgument(canGenerateXSettings(judgmentGlobalFilter)); XSettings xsettings = new XSettings(); CourtCriteria courtCriteria = judgmentGlobalFilter.getCourtCriteria(); if (courtCriteria.getCcCourtId() == null) { xsettings.setField(XField.CC_APPEAL); return xsettings; } CommonCourt commonCourt = commonCourtRepository.findOne(courtCriteria.getCcCourtId()); if (CommonCourtType.APPEAL == commonCourt.getType()) { xsettings.setField(XField.CC_REGION); xsettings.setFieldValuePrefix(""+commonCourt.getId()); return xsettings; } if (CommonCourtType.REGIONAL == commonCourt.getType()) { xsettings.setField(XField.CC_DISTRICT); xsettings.setFieldValuePrefix(""+commonCourt.getId()); return xsettings; } throw new IllegalStateException("may not generate xsettings"); }  @Override XSettings generateXSettings(JudgmentGlobalFilter judgmentGlobalFilter); @Override boolean canGenerateXSettings(JudgmentGlobalFilter judgmentGlobalFilter); @Override boolean handles(ChartCode chartCode); @Autowired void setCommonCourtRepository(CommonCourtRepository commonCourtRepository);  }### Answer:
@Test(expected = NullPointerException.class) public void generateXSettings_NULL() { xsettingsGenerator.generateXSettings(null); }
@Test(expected = IllegalArgumentException.class) public void generateXSettings_CanGenerateFALSE() { xsettingsGenerator.generateXSettings(new JudgmentGlobalFilter()); }
@Test public void generateXSettings_CourtTypeCommon_CourtIdNull() { JudgmentGlobalFilter globalFilter = new JudgmentGlobalFilter(); globalFilter.getCourtCriteria().setCourtType(CourtType.COMMON); globalFilter.getCourtCriteria().setCcCourtId(null); XSettings xsettings = xsettingsGenerator.generateXSettings(globalFilter); assertNotNull(xsettings); assertEquals(XField.CC_APPEAL, xsettings.getField()); assertTrue(StringUtils.isBlank(xsettings.getFieldValuePrefix())); }
@Test public void generateXSettings_CourtTypeCommon_CourtIdNotNull_APPEAL() { JudgmentGlobalFilter globalFilter = new JudgmentGlobalFilter(); globalFilter.getCourtCriteria().setCourtType(CourtType.COMMON); globalFilter.getCourtCriteria().setCcIncludeDependentCourtJudgments(true); globalFilter.getCourtCriteria().setCcCourtId(12L); CommonCourt commonCourt = new CommonCourt(); Whitebox.setInternalState(commonCourt, "id", 12L); commonCourt.setType(CommonCourtType.APPEAL); when(commonCourtRepository.findOne(12L)).thenReturn(commonCourt); XSettings xsettings = xsettingsGenerator.generateXSettings(globalFilter); assertNotNull(xsettings); assertEquals(XField.CC_REGION, xsettings.getField()); assertEquals("12", xsettings.getFieldValuePrefix()); }
@Test public void generateXSettings_CourtTypeCommon_CourtIdNotNull_REGIONAL() { JudgmentGlobalFilter globalFilter = new JudgmentGlobalFilter(); globalFilter.getCourtCriteria().setCourtType(CourtType.COMMON); globalFilter.getCourtCriteria().setCcIncludeDependentCourtJudgments(true); globalFilter.getCourtCriteria().setCcCourtId(12L); CommonCourt commonCourt = new CommonCourt(); Whitebox.setInternalState(commonCourt, "id", 12L); commonCourt.setType(CommonCourtType.REGIONAL); when(commonCourtRepository.findOne(12L)).thenReturn(commonCourt); XSettings xsettings = xsettingsGenerator.generateXSettings(globalFilter); assertNotNull(xsettings); assertEquals(XField.CC_DISTRICT, xsettings.getField()); assertEquals("12", xsettings.getFieldValuePrefix()); }