Best Mockito code snippet using org.mockito.moduletest.ModuleUtil
Source:ModuleUtilTest.java
...31import static org.hamcrest.Matchers.empty;32import static org.junit.Assert.assertThat;33import static org.mockito.Mockito.when;34/**35 * Tests methods on the {@link org.openmrs.module.ModuleUtil} class36 */37public class ModuleUtilTest extends BaseContextMockTest {38 39 @Mock40 MessageSourceService messageSourceService;41 42 @Mock43 AdministrationService administrationService;44 45 Properties initialRuntimeProperties;46 47 /**48 * @see {@link org.openmrs.module.ModuleUtil#checkMandatoryModulesStarted()}49 */50 @Test(expected = MandatoryModuleException.class)51 @Verifies(value = "should throw ModuleException if a mandatory module is not started", method = "checkMandatoryModulesStarted()")52 public void checkMandatoryModulesStarted_shouldThrowModuleExceptionIfAMandatoryModuleIsNotStarted() throws Exception {53 //given54 assertThat(ModuleFactory.getStartedModules(), empty());55 56 GlobalProperty gp1 = new GlobalProperty("module1.mandatory", "true");57 when(administrationService.getGlobalPropertiesBySuffix(".mandatory")).thenReturn(Arrays.asList(gp1));58 59 //when60 ModuleUtil.checkMandatoryModulesStarted();61 //then exception62 }63 64 @After65 public void revertRuntimeProperties() {66 if (initialRuntimeProperties != null) {67 Context.setRuntimeProperties(initialRuntimeProperties);68 initialRuntimeProperties = null;69 }70 }71 72 /**73 * @see {@link org.openmrs.module.ModuleUtil#getMandatoryModules()}74 */75 @Test76 @Verifies(value = "should return mandatory module ids", method = "getMandatoryModules()")77 public void getMandatoryModules_shouldReturnMandatoryModuleIds() throws Exception {78 //given79 GlobalProperty gp1 = new GlobalProperty("firstmodule.mandatory", "true");80 GlobalProperty gp2 = new GlobalProperty("secondmodule.mandatory", "false");81 82 when(administrationService.getGlobalPropertiesBySuffix(".mandatory")).thenReturn(Arrays.asList(gp1, gp2));83 84 //when85 //then86 assertThat(ModuleUtil.getMandatoryModules(), contains("firstmodule"));87 }88 89 /**90 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}91 */92 @Test93 @Verifies(value = "should allow ranged required version", method = "matchRequiredVersions(String,String)")94 public void matchRequiredVersions_shouldAllowRangedRequiredVersion() throws Exception {95 String openmrsVersion = "1.4.3";96 String requiredOpenmrsVersion = "1.2.3 - 1.4.4";97 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));98 }99 100 /**101 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}102 */103 @Test104 @Verifies(value = "should allow ranged required version with wild card", method = "matchRequiredVersions(String,String)")105 public void matchRequiredVersions_shouldAllowRangedRequiredVersionWithWildCard() throws Exception {106 String openmrsVersion = "1.4.3";107 String requiredOpenmrsVersion = "1.2.* - 1.4.*";108 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));109 }110 111 /**112 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}113 */114 @Test115 @Verifies(value = "should allow ranged required version with wild card on one end", method = "matchRequiredVersions(String,String)")116 public void matchRequiredVersions_shouldAllowRangedRequiredVersionWithWildCardOnOneEnd() throws Exception {117 String openmrsVersion = "1.4.3";118 String requiredOpenmrsVersion = "1.2.3 - 1.4.*";119 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));120 requiredOpenmrsVersion = "1.4.* - 1.4.5";121 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));122 }123 124 /**125 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}126 */127 @Test128 @Verifies(value = "should allow single entry for required version", method = "matchRequiredVersions(String,String)")129 public void matchRequiredVersions_shouldAllowSingleEntryForRequiredVersion() throws Exception {130 String openmrsVersion = "1.4.3";131 String requiredOpenmrsVersion = "1.4.2";132 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));133 }134 135 /**136 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}137 */138 @Test139 @Verifies(value = "should allow required version with wild card", method = "matchRequiredVersions(String,String)")140 public void matchRequiredVersions_shouldAllowRequiredVersionWithWildCard() throws Exception {141 String openmrsVersion = "1.4.3";142 String requiredOpenmrsVersion = "1.4.*";143 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));144 }145 146 /**147 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}148 */149 @Test150 @Verifies(value = "should allow non numeric character required version", method = "matchRequiredVersions(String,String)")151 public void matchRequiredVersions_shouldAllowNonNumericCharacterRequiredVersion() throws Exception {152 String openmrsVersion = "1.4.3";153 String requiredOpenmrsVersion = "1.4.3a";154 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));155 }156 157 /**158 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}159 */160 @Test161 @Verifies(value = "should allow ranged non numeric character required version", method = "matchRequiredVersions(String,String)")162 public void matchRequiredVersions_shouldAllowRangedNonNumericCharacterRequiredVersion() throws Exception {163 String openmrsVersion = "1.4.3";164 String requiredOpenmrsVersion = "1.4.1a - 1.4.3a";165 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));166 }167 168 /**169 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}170 */171 @Test172 @Verifies(value = "should allow ranged non numeric character with wild card", method = "matchRequiredVersions(String,String)")173 public void matchRequiredVersions_shouldAllowRangedNonNumericCharacterWithWildCard() throws Exception {174 String openmrsVersion = "1.4.3";175 String requiredOpenmrsVersion = "1.3.*a - 1.4.*a";176 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));177 }178 179 /**180 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}181 */182 @Test183 @Verifies(value = "should allow ranged non numeric character with wild card on one end", method = "matchRequiredVersions(String,String)")184 public void matchRequiredVersions_shouldAllowRangedNonNumericCharacterWithWildCardOnOneEnd() throws Exception {185 String openmrsVersion = "1.4.3";186 String requiredOpenmrsVersion = "1.2.3 - 1.4.*a";187 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));188 requiredOpenmrsVersion = "1.4.*a - 1.4.5a";189 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));190 }191 192 /**193 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}194 */195 @Test196 @Verifies(value = "should return false when openmrs version beyond wild card range", method = "matchRequiredVersions(String,String)")197 public void matchRequiredVersions_shouldReturnFalseWhenOpenmrsVersionBeyondWildCardRange() throws Exception {198 String openmrsVersion = "1.4.3";199 String requiredOpenmrsVersion = "1.3.*";200 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));201 requiredOpenmrsVersion = "1.5.*";202 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));203 }204 205 /**206 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}207 */208 @Test209 @Verifies(value = "should return false when required version beyond openmrs version", method = "matchRequiredVersions(String,String)")210 public void matchRequiredVersions_shouldReturnFalseWhenRequiredVersionBeyondOpenmrsVersion() throws Exception {211 String openmrsVersion = "1.4.3";212 String requiredOpenmrsVersion = "1.5.*";213 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));214 }215 216 /**217 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}218 */219 @Test220 @Verifies(value = "should return false when required version with wild card beyond openmrs version", method = "matchRequiredVersions(String,String)")221 public void matchRequiredVersions_shouldReturnFalseWhenRequiredVersionWithWildCardBeyondOpenmrsVersion()222 throws Exception {223 String openmrsVersion = "1.4.3";224 String requiredOpenmrsVersion = "1.5.* - 1.6.*";225 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));226 }227 228 /**229 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}230 */231 @Test232 @Verifies(value = "should return false when required version with wild card on one end beyond openmrs version", method = "matchRequiredVersions(String,String)")233 public void matchRequiredVersions_shouldReturnFalseWhenRequiredVersionWithWildCardOnOneEndBeyondOpenmrsVersion()234 throws Exception {235 String openmrsVersion = "1.4.3";236 String requiredOpenmrsVersion = "1.4.5 - 1.5.*";237 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));238 requiredOpenmrsVersion = "1.5.* - 1.6.0";239 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));240 }241 242 /**243 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}244 */245 @Test246 @Verifies(value = "should return false when single entry required version beyond openmrs version", method = "matchRequiredVersions(String,String)")247 public void matchRequiredVersions_shouldReturnFalseWhenSingleEntryRequiredVersionBeyondOpenmrsVersion() throws Exception {248 String openmrsVersion = "1.4.3";249 String requiredOpenmrsVersion = "1.5.0";250 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));251 }252 253 /**254 * @see {@link org.openmrs.module.ModuleUtil#matchRequiredVersions(String,String)}255 */256 @Test257 @Verifies(value = "should allow release type in the version", method = "matchRequiredVersions(String,String)")258 public void matchRequiredVersions_shouldAllowReleaseTypeInTheVersion() throws Exception {259 String openmrsVersion = "1.4.3";260 String requiredOpenmrsVersion = "1.4.1-dev - 1.5.*-alpha";261 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));262 requiredOpenmrsVersion = "1.5.*-dev - 1.6.0-dev";263 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredOpenmrsVersion));264 }265 266 /**267 * @see {@link ModuleUtil#matchRequiredVersions(String,String)}268 */269 @Test270 @Verifies(value = "should match when revision number is below maximum revision number", method = "matchRequiredVersions(String version, String versionRange)")271 public void matchRequiredVersions_shouldMatchWhenRevisionNumberIsBelowMaximumRevisionNumber() {272 String openmrsVersion = "1.4.1111";273 String requiredVersion = "1.4.*";274 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredVersion));275 }276 277 /**278 * @see {@link ModuleUtil#matchRequiredVersions(String,String)}279 */280 @Test281 @Verifies(value = "should not match when revision number is above maximum revision number", method = "matchRequiredVersions(String version, String versionRange)")282 public void matchRequiredVersions_shouldNotMatchWhenRevisionNumberIsAboveMaximumRevisionNumber() {283 Long revisionNumber = (long) Integer.MAX_VALUE + 2;284 String openmrsVersion = "1.4." + revisionNumber;285 String requiredVersion = "1.4.*";286 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredVersion));287 }288 289 /**290 * @see {@link ModuleUtil#matchRequiredVersions(String,String)}291 */292 @Test293 @Verifies(value = "should not match when version has wild card and is outside boundary", method = "matchRequiredVersions(String version, String versionRange)")294 public void matchRequiredVersions_shouldNotMatchWhenVersionHasWildCardAndIsOutsideBoundary() {295 String openmrsVersion = "1.*.4";296 String requiredVersion = "1.4.0 - 1.4.10";297 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredVersion));298 }299 300 /**301 * @see {@link ModuleUtil#matchRequiredVersions(String,String)}302 */303 @Test304 @Verifies(value = "should match when version has wild card and is within boundary", method = "matchRequiredVersions(String version, String versionRange)")305 public void matchRequiredVersions_shouldMatchWhenVersionHasWildCardAndIsWithinBoundary() {306 String openmrsVersion = "1.4.*";307 String requiredVersion = "1.4.0 - 1.4.10";308 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredVersion));309 }310 311 /**312 * @see {@link ModuleUtil#matchRequiredVersions(String,String)}313 */314 @Test315 @Verifies(value = "should not match when version has wild card plus qualifier and is outside boundary", method = "matchRequiredVersions(String version, String versionRange)")316 public void matchRequiredVersions_shouldNotMatchWhenVersionHasWildPlusQualifierCardAndIsOutsideBoundary() {317 String openmrsVersion = "1.*.4-SNAPSHOT";318 String requiredVersion = "1.4.0 - 1.4.10";319 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredVersion));320 }321 322 /**323 * @see {@link ModuleUtil#matchRequiredVersions(String,String)}324 */325 @Test326 @Verifies(value = "should match when version has wild card plus qualifier and is within boundary", method = "matchRequiredVersions(String version, String versionRange)")327 public void matchRequiredVersions_shouldMatchWhenVersionHasWildCardPlusQualifierAndIsWithinBoundary() {328 String openmrsVersion = "1.4.*-SNAPSHOT";329 String requiredVersion = "1.4.0 - 1.4.10";330 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredVersion));331 }332 333 /**334 * @see {@link ModuleUtil#matchRequiredVersions(String,String)}335 */336 @Test337 @Verifies(value = "should correctly set upper and lower limit for versionRange with qualifiers and wild card", method = "matchRequiredVersions(String version, String versionRange)")338 public void matchRequiredVersions_shouldCorrectlySetUpperAndLoweLimitForVersionRangeWithQualifiersAndWildCard() {339 String openmrsVersion = "1.4.11111";340 String requiredVersion = "1.4.200 - 1.4.*-SNAPSHOT";341 Long revisionNumber = (long) Integer.MAX_VALUE + 2;342 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredVersion));343 requiredVersion = "1.4.*-SNAPSHOT - 1.4.*";344 Assert.assertTrue(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredVersion));345 openmrsVersion = "1.4." + revisionNumber;346 Assert.assertFalse(ModuleUtil.matchRequiredVersions(openmrsVersion, requiredVersion));347 }348 349 /**350 * @see {@link org.openmrs.module.ModuleUtil#getPathForResource(org.openmrs.module.Module,String)}351 */352 @Test353 @Verifies(value = "should handle ui springmvc css ui dot css example", method = "getPathForResource(Module,String)")354 public void getPathForResource_shouldHandleUiSpringmvcCssUiDotCssExample() throws Exception {355 Module module = new Module("Unit test");356 module.setModuleId("ui.springmvc");357 String path = "/ui/springmvc/css/ui.css";358 Assert.assertEquals("/css/ui.css", ModuleUtil.getPathForResource(module, path));359 }360 361 /**362 * @see {@link org.openmrs.module.ModuleUtil#getModuleForPath(String)}363 */364 @Test365 @Verifies(value = "should handle ui springmvc css ui dot css when ui dot springmvc module is running", method = "getModuleForPath(String)")366 public void getModuleForPath_shouldHandleUiSpringmvcCssUiDotCssWhenUiDotSpringmvcModuleIsRunning() throws Exception {367 ModuleFactory.getStartedModulesMap().clear();368 Module module = new Module("For Unit Test");369 module.setModuleId("ui.springmvc");370 ModuleFactory.getStartedModulesMap().put(module.getModuleId(), module);371 372 String path = "/ui/springmvc/css/ui.css";373 Assert.assertEquals(module, ModuleUtil.getModuleForPath(path));374 }375 376 /**377 * @see {@link org.openmrs.module.ModuleUtil#getModuleForPath(String)}378 */379 @Test380 @Verifies(value = "should handle ui springmvc css ui dot css when ui module is running", method = "getModuleForPath(String)")381 public void getModuleForPath_shouldHandleUiSpringmvcCssUiDotCssWhenUiModuleIsRunning() throws Exception {382 ModuleFactory.getStartedModulesMap().clear();383 Module module = new Module("For Unit Test");384 module.setModuleId("ui");385 ModuleFactory.getStartedModulesMap().put(module.getModuleId(), module);386 387 String path = "/ui/springmvc/css/ui.css";388 Assert.assertEquals(module, ModuleUtil.getModuleForPath(path));389 }390 391 /**392 * @see {@link org.openmrs.module.ModuleUtil#getModuleForPath(String)}393 */394 @Test395 @Verifies(value = "should return null for ui springmvc css ui dot css when no relevant module is running", method = "getModuleForPath(String)")396 public void getModuleForPath_shouldReturnNullForUiSpringmvcCssUiDotCssWhenNoRelevantModuleIsRunning() throws Exception {397 ModuleFactory.getStartedModulesMap().clear();398 String path = "/ui/springmvc/css/ui.css";399 Assert.assertNull(ModuleUtil.getModuleForPath(path));400 }401 402 /**403 * @see {@link org.openmrs.module.ModuleUtil#checkRequiredVersion(String, String)}404 */405 @Test(expected = ModuleException.class)406 @Verifies(value = "should throw ModuleException if openmrs version beyond wild card range", method = "checkRequiredVersion(String, String)")407 public void checkRequiredVersion_shouldThrowModuleExceptionIfOpenmrsVersionBeyondWildCardRange() throws Exception {408 String openmrsVersion = "1.4.3";409 String requiredOpenmrsVersion = "1.3.*";410 ModuleUtil.checkRequiredVersion(openmrsVersion, requiredOpenmrsVersion);411 }412 413 /**414 * @see {@link org.openmrs.module.ModuleUtil#checkRequiredVersion(String, String)}415 */416 @Test(expected = ModuleException.class)417 @Verifies(value = "should throw ModuleException if required version beyond openmrs version", method = "checkRequiredVersion(String, String)")418 public void checkRequiredVersion_shouldThrowModuleExceptionIfRequiredVersionBeyondOpenmrsVersion() throws Exception {419 String openmrsVersion = "1.4.3";420 String requiredOpenmrsVersion = "1.5.*";421 ModuleUtil.checkRequiredVersion(openmrsVersion, requiredOpenmrsVersion);422 }423 424 /**425 * @see {@link org.openmrs.module.ModuleUtil#checkRequiredVersion(String, String)}426 */427 @Test(expected = ModuleException.class)428 @Verifies(value = "should throw ModuleException if required version with wild card beyond openmrs version", method = "checkRequiredVersion(String, String)")429 public void checkRequiredVersion_shouldThrowModuleExceptionIfRequiredVersionWithWildCardBeyondOpenmrsVersion()430 throws Exception {431 String openmrsVersion = "1.4.3";432 String requiredOpenmrsVersion = "1.5.* - 1.6.*";433 ModuleUtil.checkRequiredVersion(openmrsVersion, requiredOpenmrsVersion);434 }435 436 /**437 * @see {@link org.openmrs.module.ModuleUtil#checkRequiredVersion(String, String)}438 */439 @Test(expected = ModuleException.class)440 @Verifies(value = "should throw ModuleException if required version with wild card on one end beyond openmrs version", method = "checkRequiredVersion(String, String)")441 public void checkRequiredVersion_shouldThrowModuleExceptionIfRequiredVersionWithWildCardOnOneEndBeyondOpenmrsVersion()442 throws Exception {443 String openmrsVersion = "1.4.3";444 String requiredOpenmrsVersion = "1.4.5 - 1.5.*";445 ModuleUtil.checkRequiredVersion(openmrsVersion, requiredOpenmrsVersion);446 }447 448 /**449 * @see {@link org.openmrs.module.ModuleUtil#checkRequiredVersion(String, String)}450 */451 @Test(expected = ModuleException.class)452 @Verifies(value = "should throw ModuleException if single entry required version beyond openmrs version", method = "checkRequiredVersion(String, String)")453 public void checkRequiredVersion_shouldThrowModuleExceptionIfSingleEntryRequiredVersionBeyondOpenmrsVersion()454 throws Exception {455 String openmrsVersion = "1.4.3";456 String requiredOpenmrsVersion = "1.5.0";457 ModuleUtil.checkRequiredVersion(openmrsVersion, requiredOpenmrsVersion);458 }459 460 /**461 * @see {@link org.openmrs.module.ModuleUtil#compareVersion(String,String)}462 */463 @Test464 @Verifies(value = "should correctly comparing two version numbers", method = "compareVersion(String,String)")465 public void compareVersion_shouldCorrectlyComparingTwoVersionNumbers() throws Exception {466 String olderVersion = "2.1.1";467 String newerVersion = "2.1.10";468 Assert.assertTrue(ModuleUtil.compareVersion(olderVersion, newerVersion) < 0);469 }470 471 /**472 * @see {@link org.openmrs.module.ModuleUtil#compareVersion(String,String)}473 */474 @Test475 @Verifies(value = "treat SNAPSHOT as earliest version", method = "compareVersion(String,String)")476 public void compareVersion_shouldTreatSNAPSHOTAsEarliestVersion() throws Exception {477 String olderVersion = "1.8.3";478 String newerVersion = "1.8.4-SNAPSHOT";479 Assert.assertTrue(ModuleUtil.compareVersion(newerVersion, olderVersion) > 0);480 //should still return the correct value if the arguments are switched481 Assert.assertTrue(ModuleUtil.compareVersion(olderVersion, newerVersion) < 0);482 }483 484 /**485 * @see {@link org.openmrs.module.ModuleUtil#checkRequiredVersion(String, String)}486 */487 @Test(expected = ModuleException.class)488 @Verifies(value = "should throw ModuleException if SNAPSHOT not handled correctly", method = "checkRequiredVersion(String, String)")489 public void checkRequiredVersion_shouldThrowModuleExceptionIfSNAPSHOTNotHandledCorrectly() throws Exception {490 String openmrsVersion = "1.4.3";491 String requiredOpenmrsVersion = "1.4.5-SNAPSHOT";492 ModuleUtil.checkRequiredVersion(openmrsVersion, requiredOpenmrsVersion);493 }494 495 /**496 * @see {@link org.openmrs.module.ModuleUtil#checkRequiredVersion(String, String)}497 */498 @Test499 @Verifies(value = "Should handle SNAPSHOT versions ", method = "checkRequiredVersion(String, String)")500 public void checkRequiredVersion_shouldHandleSnapshotVersion() throws Exception {501 String openMRSVersion = "1.9.2-SNAPSHOT";502 String requiredOpenmrsVersion = "1.9.2-SNAPSHOT";503 ModuleUtil.checkRequiredVersion(openMRSVersion, requiredOpenmrsVersion);504 }505 506 /**507 * @see {@link org.openmrs.module.ModuleUtil#checkRequiredVersion(String, String)}508 */509 @Test510 @Verifies(value = "Should handle UUID suffix versions ", method = "checkRequiredVersion(String, String)")511 public void checkRequiredVersion_shouldHandleUuidSuffixVersion() throws Exception {512 String openMRSVersion = "1.9.9-f4927f";513 String requiredOpenmrsVersion = "1.9.9-SNAPSHOT";514 ModuleUtil.checkRequiredVersion(openMRSVersion, requiredOpenmrsVersion);515 }516 517 @Test518 @Verifies(value = "Should handle ALPHA versions ", method = "checkRequiredVersion(String, String)")519 public void checkRequiredVersion_shouldHandleAlphaVersion() throws Exception {520 String openMRSVersion = "1.9.2-ALPHA";521 String requiredOpenmrsVersion = "1.9.2-ALPHA";522 ModuleUtil.checkRequiredVersion(openMRSVersion, requiredOpenmrsVersion);523 }524 525 private JarFile loadModuleJarFile(String moduleId, String version) throws IOException {526 InputStream moduleStream = null;527 File tempFile = null;528 OutputStream tempFileStream = null;529 JarFile jarFile = null;530 try {531 moduleStream = getClass().getClassLoader().getResourceAsStream(532 "org/openmrs/module/include/" + moduleId + "-" + version + ".omod");533 Assert.assertNotNull(moduleStream);534 tempFile = File.createTempFile("moduleTest", "omod");535 tempFileStream = new FileOutputStream(tempFile);536 IOUtils.copy(moduleStream, tempFileStream);537 jarFile = new JarFile(tempFile);538 }539 finally {540 IOUtils.closeQuietly(moduleStream);541 IOUtils.closeQuietly(tempFileStream);542 if (tempFile != null) {543 tempFile.delete();544 }545 }546 return jarFile;547 }548 549 /**550 * @see ModuleUtil#getResourceFromApi(JarFile,String,String,String)551 */552 @Test553 @Verifies(value = "load file from api as input stream", method = "getResourceFromApi(JarFile,String,String,String)")554 public void getResourceFromApi_shouldLoadFileFromApiAsInputStream() throws Exception {555 String moduleId = "basicmodule";556 String version = "0.1";557 String resource = "messages.properties";558 JarFile moduleJarFile = loadModuleJarFile(moduleId, version);559 Assert.assertNotNull(moduleJarFile);560 InputStream resultStream = ModuleUtil.getResourceFromApi(moduleJarFile, moduleId, version, resource);561 Assert.assertNotNull(resultStream);562 }563 564 /**565 * @see ModuleUtil#getResourceFromApi(JarFile,String,String,String)566 */567 @Test568 @Verifies(value = "return null if api is not found", method = "getResourceFromApi(JarFile,String,String,String)")569 public void getResourceFromApi_shouldReturnNullIfApiIsNotFound() throws Exception {570 String moduleId = "logic";571 String version = "0.2";572 String resource = "messages.properties";573 JarFile moduleJarFile = loadModuleJarFile(moduleId, version);574 Assert.assertNotNull(moduleJarFile);575 InputStream resultStream = ModuleUtil.getResourceFromApi(moduleJarFile, moduleId, version, resource);576 Assert.assertNull(resultStream);577 }578 579 /**580 * @see ModuleUtil#getResourceFromApi(JarFile,String,String,String)581 */582 @Test583 @Verifies(value = "return null if file is not found in api", method = "getResourceFromApi(JarFile,String,String,String)")584 public void getResourceFromApi_shouldReturnNullIfFileIsNotFoundInApi() throws Exception {585 String moduleId = "basicmodule";586 String version = "0.1";587 String resource = "messages_doesnotexist.properties";588 JarFile moduleJarFile = loadModuleJarFile(moduleId, version);589 Assert.assertNotNull(moduleJarFile);590 InputStream resultStream = ModuleUtil.getResourceFromApi(moduleJarFile, moduleId, version, resource);591 Assert.assertNull(resultStream);592 }593}...
Source:ModuleHandlingTest.java
...21import static org.assertj.core.api.Assertions.assertThat;22import static org.assertj.core.api.Assertions.fail;23import static org.hamcrest.core.Is.is;24import static org.junit.Assume.assumeThat;25import static org.mockito.moduletest.ModuleUtil.layer;26import static org.mockito.moduletest.ModuleUtil.modularJar;27@RunWith(Parameterized.class)28public class ModuleHandlingTest {29 @Parameterized.Parameters30 public static Collection<Object[]> data() {31 return Arrays.asList(new Object[][]{32 {true}, {false}33 });34 }35 private final boolean namedModules;36 public ModuleHandlingTest(boolean namedModules) {37 this.namedModules = namedModules;38 }39 @Test40 public void can_define_class_in_open_reading_module() throws Exception {...
Source:ModuleUtil.java
...23import java.util.jar.JarEntry;24import java.util.jar.JarOutputStream;25import java.util.stream.Stream;26import static net.bytebuddy.matcher.ElementMatchers.named;27public class ModuleUtil {28 public static Path modularJar(boolean isPublic, boolean isExported, boolean isOpened) throws IOException {29 return modularJar(isPublic, isExported, isOpened, false);30 }31 public static Path modularJar(boolean isPublic, boolean isExported, boolean isOpened, boolean addField) throws IOException {32 Path jar = Files.createTempFile("sample-module", ".jar");33 try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(jar))) {34 out.putNextEntry(new JarEntry("module-info.class"));35 out.write(moduleInfo(isExported, isOpened));36 out.closeEntry();37 out.putNextEntry(new JarEntry("sample/MyCallable.class"));38 out.write(type(isPublic, addField));39 out.closeEntry();40 }41 return jar;...
Source:ModuleAccessTest.java
...13import java.nio.file.Path;14import java.util.concurrent.Callable;15import static junit.framework.TestCase.fail;16import static org.assertj.core.api.Assertions.assertThat;17import static org.mockito.moduletest.ModuleUtil.layer;18import static org.mockito.moduletest.ModuleUtil.modularJar;19public class ModuleAccessTest {20 @Test21 public void can_access_non_opened_module_with_module_member_accessor() throws Exception {22 Path jar = modularJar(false, false, false);23 ModuleLayer layer = layer(jar, false, true);24 ClassLoader loader = layer.findLoader("mockito.test");25 Class<?> type = loader.loadClass("sample.MyCallable");26 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();27 Thread.currentThread().setContextClassLoader(loader);28 try {29 Class<?> moduleMemberAccessor = loader.loadClass(ModuleMemberAccessor.class.getName());30 Object instance = moduleMemberAccessor.getConstructor().newInstance();31 @SuppressWarnings("unchecked")32 Callable<String> mock = (Callable<String>) moduleMemberAccessor...
ModuleUtil
Using AI Code Generation
1import org.mockito.moduletest.*;2public class TestModuleUtil {3 public static void main(String[] args) {4 ModuleUtil util = new ModuleUtil();5 System.out.println(util.add(10, 20));6 }7}8Note: If you are using a package other than the default package, then you need to specify the package name in the import statement. For example, if you are using a package named org.mockito.moduletest, then you need to specify the package name in the import statement as shown below:9import org.mockito.moduletest.*;
ModuleUtil
Using AI Code Generation
1import org.mockito.moduletest.ModuleUtil;2public class 1 {3 public static void main(String[] args) {4 System.out.println("Hello World!");5 System.out.println(ModuleUtil.getMessage());6 }7}8package org.mockito.moduletest;9public class ModuleUtil {10 public static String getMessage() {11 return "Hello from org.mockito.moduletest";12 }13}14module org.mockito.moduletest {15 exports org.mockito.moduletest;16}
ModuleUtil
Using AI Code Generation
1package org.mockito.moduletestModuleUtil;2public class 1 {3 public static void main(String[] args) {4 System.out.println("Hello World!");5 System.out.println(ModuleUtil.getMessage());6 }7}8package org.mockito.moduletest;9public class ModuleUtil {10 public static String getMessage() {11 return "Hello from org.mockito.moduletest";12 }13}14module org.mockito.moduletest {15 exports org.mockito.moduletest;16}
ModuleUtil
Using AI Code Generation
1import org.mockito.moduletest.*;2import org.mockito.moduletest.*;3public class 1 {4 public static void main(String[] args) {5 ModuleUtil util = new ModuleUtil();6 util.print();7 }8}9package org.mockito.moduletest;10public class ModuleUtil {11 public void print() {12 System.out.println("ModuleUtil");13 }14}15import org.mockito.moduletest.*;The above command will generate the following output:16import org.mockito.moduletest.*;17ModuleUtil util new ModuleUtil();18javac -classpath .;myjar.jar 1.java19javac -classpath .;myjar.jar 1.java
ModuleUtil
Using AI Code Generation
1package org.mockito.moduletest;2import org.mockito.moduletest.util.;;3public class ModuleTest {4 public static void main(String[] args) {5 ModuleUtil util = new ModuleUtil();6 util.printModuleName()7 }8}9packagetorg.mockito.moduletest.util;10public class ModuleUtil {11 public void printModuleName() {12 System.out.println("mockito");13 }14}
ModuleUtil
Using AI Code Generation
1import org.mockito.moduletest.*;2class org.mockito.moduletest.util.*;3public class ModuleTest {4 public static void main(String[] args) {5 ModuleUtil util = new ModuleUtil();6 util.printModuleName();7 }8}9package org.mockito.moduletest.util;10public class ModuleUtil {11 public void printModuleName() {12 System.out.println("mockito");13 }14}
ModuleUtil
Using AI Code Generation
1import org.mockito.moduletest.*;2class 1 {3 public static void main(String args[]){4 ModuleUtil mu = new ModuleUtil();5 int x = mu.add(10,20);6 System.out.println("Addition is "+x);7 }8}9module org.mockito.moduletest {10}
ModuleUtil
Using AI Code Generation
1package org.mockito.moduletest;2import org.mockito.ModuleUtil;3public class ModuleTest {4 public static void main(String[] args) {5 System.out.println(ModuleUtil.getModuleName());6 }7}8package org.mockito.moduletest;9import org.mockito.ModuleUtil;10public class ModuleTest {11 public static void main(String[] args) {12 System.out.println(ModuleUtil.getModuleName());13 }14}15package org.mockito;16public class ModuleUtil {17 public static String getModuleName() {18 return ModuleTest.class.getModule().getName();19 }20}21import org.mockito.moduletest.*;22 (package org.mockito.moduletest is declared in module org.mockito.moduletest, which does not export it to the unnamed module)23import org.mockito.moduletest.*;24 (package org.mockito.moduletest is declared in module org.mockito.moduletest, which does not export it to the unnamed module)
ModuleUtil
Using AI Code Generation
1package org.mockito.moduletest;2import org.mockito.ModuleUtil;3public class ModuleTest {4 public static void main(String[] args) {5 System.out.println(ModuleUtil.getModuleName());6 }7}8package org.mockito.moduletest;9import org.mockito.ModuleUtil;10public class ModuleTest {11 public static void main(String[] args) {12 System.out.println(ModuleUtil.getModuleName());13 }14}15package org.mockito;16public class ModuleUtil {17 public static String getModuleName() {18 return ModuleTest.class.getModule().getName();19 }20}21 public static void main(String args[])
ModuleUtil
Using AI Code Generation
1importorg.mockito.moduletest.ModuleUtil;2classTest{3){4 ModuleUtil util = new ModuleUtil();5 util.print();6 }7}8import org.mockito.moduletest.ModuleUtil;9 ModuleUtil util = new ModuleUtil(;10module org.mockito.moduletest {11 exports org.mockito.moduletest;12 open org.mockito.moduletest;13}
ModuleUtil
Using AI Code Generation
1import org.mockito.moduletest.ModuleUtil;2public class 1 {3public static void main(String[] args) {4ModuleUtil util = new ModuleUtil();5util.sayHello();6}7}
ModuleUtil
Using AI Code Generation
1package org.mockito.moduletest;2import org.mockito.*;3import org.mockito.moduletest.*;4public class Test1 {5 public static void main(String args[]) {6 ModuleUtil m = new ModuleUtil();7 m.print();8 }9}10package org.mockito.moduletest;11import org.mockito.*;12import org.mockito.moduletest.*;13public class Test2 {14 public static void main(String args[]) {15 ModuleUtil m = new ModuleUtil();16 m.print();17 }18}19package org.mockito.moduletest;20import org.mockito.*;21import org.mockito.moduletest.*;22public class Test3 {23 public static void main(String args[]) {24 ModuleUtil m = new ModuleUtil();25 m.print();26 }27}28package org.mockito.moduletest;29import org.mockito.*;30import org.mockito.moduletest.*;31public class Test4 {32 public static void main(String args[]) {33 ModuleUtil m = new ModuleUtil();34 m.print();35 }36}37package org.mockito.moduletest;38import org.mockito.*;39import org.mockito.moduletest.*;40public class Test5 {41 public static void main(String args[]) {42 ModuleUtil m = new ModuleUtil();43 m.print();44 }45}46package org.mockito.moduletest;47import org.mockito.*;48import org.mockito.moduletest.*;49public class Test6 {50 public static void main(String args[]) {51 ModuleUtil m = new ModuleUtil();52 m.print();53 }54}55package org.mockito.moduletest;56import org.mockito.*;57import org.mockito.moduletest.*;58public class Test7 {59 public static void main(String args[]) {60 ModuleUtil m = new ModuleUtil();61 m.print();62 }63}64package org.mockito.moduletest;65import org.mockito.*;66import org.mockito.moduletest.*;67public class Test8 {68 public static void main(String args[])
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!