Best Mockito code snippet using org.mockito.moduletest.ModuleUtil.list
Source:ModuleUtilTest.java
1/**2 * This Source Code Form is subject to the terms of the Mozilla Public License,3 * v. 2.0. If a copy of the MPL was not distributed with this file, You can4 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under5 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.6 *7 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS8 * graphic logo is a trademark of OpenMRS Inc.9 */10package org.openmrs.module;11import org.apache.commons.io.IOUtils;12import org.junit.After;13import org.junit.Assert;14import org.junit.Test;15import org.mockito.Mock;16import org.openmrs.GlobalProperty;17import org.openmrs.api.AdministrationService;18import org.openmrs.api.context.Context;19import org.openmrs.messagesource.MessageSourceService;20import org.openmrs.test.BaseContextMockTest;21import org.openmrs.test.Verifies;22import java.io.File;23import java.io.FileOutputStream;24import java.io.IOException;25import java.io.InputStream;26import java.io.OutputStream;27import java.util.Arrays;28import java.util.Properties;29import java.util.jar.JarFile;30import static org.hamcrest.Matchers.contains;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
1/*2 * Copyright (c) 2018 Mockito contributors3 * This program is made available under the terms of the MIT License.4 */5package org.mockito.moduletest;6import net.bytebuddy.dynamic.loading.ClassInjector;7import org.junit.Test;8import org.junit.runner.RunWith;9import org.junit.runners.Parameterized;10import org.mockito.Mockito;11import org.mockito.exceptions.base.MockitoException;12import org.mockito.internal.configuration.plugins.Plugins;13import org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker;14import org.mockito.stubbing.OngoingStubbing;15import java.lang.reflect.InvocationTargetException;16import java.nio.file.Path;17import java.util.Arrays;18import java.util.Collection;19import java.util.concurrent.Callable;20import java.util.concurrent.locks.Lock;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 {41 assumeThat(Plugins.getMockMaker() instanceof InlineByteBuddyMockMaker, is(false));42 Path jar = modularJar(true, true, true);43 ModuleLayer layer = layer(jar, true, namedModules);44 ClassLoader loader = layer.findLoader("mockito.test");45 Class<?> type = loader.loadClass("sample.MyCallable");46 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();47 Thread.currentThread().setContextClassLoader(loader);48 try {49 Class<?> mockito = loader.loadClass(Mockito.class.getName());50 @SuppressWarnings("unchecked")51 Callable<String> mock = (Callable<String>) mockito.getMethod("mock", Class.class).invoke(null, type);52 Object stubbing = mockito.getMethod("when", Object.class).invoke(null, mock.call());53 loader.loadClass(OngoingStubbing.class.getName()).getMethod("thenCallRealMethod").invoke(stubbing);54 assertThat(mock.getClass().getName()).startsWith("sample.MyCallable$MockitoMock$");55 assertThat(mock.call()).isEqualTo("foo");56 } finally {57 Thread.currentThread().setContextClassLoader(contextLoader);58 }59 }60 @Test61 public void can_define_class_in_open_java_util_module() throws Exception {62 assumeThat(Plugins.getMockMaker() instanceof InlineByteBuddyMockMaker, is(false));63 Path jar = modularJar(true, true, true);64 ModuleLayer layer = layer(jar, true, namedModules);65 ClassLoader loader = layer.findLoader("mockito.test");66 Class<?> type = loader.loadClass("java.util.concurrent.locks.Lock");67 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();68 Thread.currentThread().setContextClassLoader(loader);69 try {70 Class<?> mockito = loader.loadClass(Mockito.class.getName());71 @SuppressWarnings("unchecked")72 Lock mock = (Lock) mockito.getMethod("mock", Class.class).invoke(null, type);73 Object stubbing = mockito.getMethod("when", Object.class).invoke(null, mock.tryLock());74 loader.loadClass(OngoingStubbing.class.getName()).getMethod("thenReturn", Object.class).invoke(stubbing, true);75 boolean relocated = !Boolean.getBoolean("org.mockito.internal.noUnsafeInjection") && ClassInjector.UsingReflection.isAvailable();76 String prefix = relocated ? "org.mockito.codegen.Lock$MockitoMock$" : "java.util.concurrent.locks.Lock$MockitoMock$";77 assertThat(mock.getClass().getName()).startsWith(prefix);78 assertThat(mock.tryLock()).isEqualTo(true);79 } finally {80 Thread.currentThread().setContextClassLoader(contextLoader);81 }82 }83 @Test84 public void inline_mock_maker_can_mock_closed_modules() throws Exception {85 assumeThat(Plugins.getMockMaker() instanceof InlineByteBuddyMockMaker, is(true));86 Path jar = modularJar(false, false, false);87 ModuleLayer layer = layer(jar, false, namedModules);88 ClassLoader loader = layer.findLoader("mockito.test");89 Class<?> type = loader.loadClass("sample.MyCallable");90 Class<?> mockito = loader.loadClass(Mockito.class.getName());91 @SuppressWarnings("unchecked")92 Callable<String> mock = (Callable<String>) mockito.getMethod("mock", Class.class).invoke(null, type);93 Object stubbing = mockito.getMethod("when", Object.class).invoke(null, mock.call());94 loader.loadClass(OngoingStubbing.class.getName()).getMethod("thenCallRealMethod").invoke(stubbing);95 assertThat(mock.getClass().getName()).isEqualTo("sample.MyCallable");96 assertThat(mock.call()).isEqualTo("foo");97 }98 @Test99 public void can_define_class_in_open_reading_private_module() throws Exception {100 assumeThat(Plugins.getMockMaker() instanceof InlineByteBuddyMockMaker, is(false));101 Path jar = modularJar(false, true, true);102 ModuleLayer layer = layer(jar, true, namedModules);103 ClassLoader loader = layer.findLoader("mockito.test");104 Class<?> type = loader.loadClass("sample.MyCallable");105 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();106 Thread.currentThread().setContextClassLoader(loader);107 try {108 Class<?> mockito = loader.loadClass(Mockito.class.getName());109 @SuppressWarnings("unchecked")110 Callable<String> mock = (Callable<String>) mockito.getMethod("mock", Class.class).invoke(null, type);111 Object stubbing = mockito.getMethod("when", Object.class).invoke(null, mock.call());112 loader.loadClass(OngoingStubbing.class.getName()).getMethod("thenCallRealMethod").invoke(stubbing);113 assertThat(mock.getClass().getName()).startsWith("sample.MyCallable$MockitoMock$");114 assertThat(mock.call()).isEqualTo("foo");115 } finally {116 Thread.currentThread().setContextClassLoader(contextLoader);117 }118 }119 @Test120 public void can_define_class_in_open_non_reading_module() throws Exception {121 assumeThat(Plugins.getMockMaker() instanceof InlineByteBuddyMockMaker, is(false));122 Path jar = modularJar(true, true, true);123 ModuleLayer layer = layer(jar, false, namedModules);124 ClassLoader loader = layer.findLoader("mockito.test");125 Class<?> type = loader.loadClass("sample.MyCallable");126 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();127 Thread.currentThread().setContextClassLoader(loader);128 try {129 Class<?> mockito = loader.loadClass(Mockito.class.getName());130 @SuppressWarnings("unchecked")131 Callable<String> mock = (Callable<String>) mockito.getMethod("mock", Class.class).invoke(null, type);132 Object stubbing = mockito.getMethod("when", Object.class).invoke(null, mock.call());133 loader.loadClass(OngoingStubbing.class.getName()).getMethod("thenCallRealMethod").invoke(stubbing);134 assertThat(mock.getClass().getName()).startsWith("sample.MyCallable$MockitoMock$");135 assertThat(mock.call()).isEqualTo("foo");136 } finally {137 Thread.currentThread().setContextClassLoader(contextLoader);138 }139 }140 @Test141 public void can_define_class_in_open_non_reading_non_exporting_module() throws Exception {142 assumeThat(Plugins.getMockMaker() instanceof InlineByteBuddyMockMaker, is(false));143 Path jar = modularJar(true, false, true);144 ModuleLayer layer = layer(jar, false, namedModules);145 ClassLoader loader = layer.findLoader("mockito.test");146 Class<?> type = loader.loadClass("sample.MyCallable");147 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();148 Thread.currentThread().setContextClassLoader(loader);149 try {150 Class<?> mockito = loader.loadClass(Mockito.class.getName());151 @SuppressWarnings("unchecked")152 Callable<String> mock = (Callable<String>) mockito.getMethod("mock", Class.class).invoke(null, type);153 Object stubbing = mockito.getMethod("when", Object.class).invoke(null, mock.call());154 loader.loadClass(OngoingStubbing.class.getName()).getMethod("thenCallRealMethod").invoke(stubbing);155 assertThat(mock.getClass().getName()).startsWith("sample.MyCallable$MockitoMock$");156 assertThat(mock.call()).isEqualTo("foo");157 } finally {158 Thread.currentThread().setContextClassLoader(contextLoader);159 }160 }161 @Test162 public void can_define_class_in_closed_module() throws Exception {163 assumeThat(Plugins.getMockMaker() instanceof InlineByteBuddyMockMaker, is(false));164 Path jar = modularJar(true, true, false);165 ModuleLayer layer = layer(jar, false, namedModules);166 ClassLoader loader = layer.findLoader("mockito.test");167 Class<?> type = loader.loadClass("sample.MyCallable");168 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();169 Thread.currentThread().setContextClassLoader(loader);170 try {171 Class<?> mockito = loader.loadClass(Mockito.class.getName());172 @SuppressWarnings("unchecked")173 Callable<String> mock = (Callable<String>) mockito.getMethod("mock", Class.class).invoke(null, type);174 Object stubbing = mockito.getMethod("when", Object.class).invoke(null, mock.call());175 loader.loadClass(OngoingStubbing.class.getName()).getMethod("thenCallRealMethod").invoke(stubbing);176 boolean relocated = !Boolean.getBoolean("org.mockito.internal.noUnsafeInjection") && ClassInjector.UsingReflection.isAvailable();177 String prefix = relocated ? "sample.MyCallable$MockitoMock$" : "org.mockito.codegen.MyCallable$MockitoMock$";178 assertThat(mock.getClass().getName()).startsWith(prefix);179 assertThat(mock.call()).isEqualTo("foo");180 } finally {181 Thread.currentThread().setContextClassLoader(contextLoader);182 }183 }184 @Test185 public void cannot_define_class_in_non_opened_non_exported_module_if_lookup_injection() throws Exception {186 assumeThat(Plugins.getMockMaker() instanceof InlineByteBuddyMockMaker, is(false));187 assumeThat(!Boolean.getBoolean("org.mockito.internal.noUnsafeInjection") && ClassInjector.UsingReflection.isAvailable(), is(true));188 Path jar = modularJar(false, false, false);189 ModuleLayer layer = layer(jar, false, namedModules);190 ClassLoader loader = layer.findLoader("mockito.test");191 Class<?> type = loader.loadClass("sample.MyCallable");192 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();193 Thread.currentThread().setContextClassLoader(loader);194 try {195 Class<?> mockito = loader.loadClass(Mockito.class.getName());196 @SuppressWarnings("unchecked")197 Callable<String> mock = (Callable<String>) mockito.getMethod("mock", Class.class).invoke(null, type);198 Object stubbing = mockito.getMethod("when", Object.class).invoke(null, mock.call());199 loader.loadClass(OngoingStubbing.class.getName()).getMethod("thenCallRealMethod").invoke(stubbing);200 assertThat(mock.getClass().getName()).startsWith("sample.MyCallable$MockitoMock$");201 assertThat(mock.call()).isEqualTo("foo");202 } finally {203 Thread.currentThread().setContextClassLoader(contextLoader);204 }205 }206 @Test207 public void can_define_class_in_non_opened_non_exported_module_if_unsafe_injection() throws Exception {208 assumeThat(Plugins.getMockMaker() instanceof InlineByteBuddyMockMaker, is(false));209 assumeThat(!Boolean.getBoolean("org.mockito.internal.noUnsafeInjection") && ClassInjector.UsingReflection.isAvailable(), is(false));210 Path jar = modularJar(false, false, false);211 ModuleLayer layer = layer(jar, false, namedModules);212 ClassLoader loader = layer.findLoader("mockito.test");213 Class<?> type = loader.loadClass("sample.MyCallable");214 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();215 Thread.currentThread().setContextClassLoader(loader);216 try {217 Class<?> mockito = loader.loadClass(Mockito.class.getName());218 try {219 mockito.getMethod("mock", Class.class).invoke(null, type);220 fail("Expected mocking to fail");221 } catch (InvocationTargetException e) {222 assertThat(e.getTargetException()).isInstanceOf(loader.loadClass(MockitoException.class.getName()));223 }224 } finally {225 Thread.currentThread().setContextClassLoader(contextLoader);226 }227 }228}...
Source:ModuleUtil.java
...78 if (namedModules) {79 modules.add("org.mockito");80 modules.add("net.bytebuddy");81 modules.add("net.bytebuddy.agent");82 // We do not list all packages but only roots and packages that interact with the mock where83 // we attempt to validate an interaction of two modules. This is of course a bit hacky as those84 // libraries would normally be entirely encapsulated in an automatic module with all their classes85 // but it is sufficient for the test and saves us a significant amount of code.86 moduleFinder = ModuleFinder.compose(moduleFinder,87 automaticModule("org.mockito", "org.mockito", "org.mockito.internal.creation.bytebuddy"),88 automaticModule("net.bytebuddy", "net.bytebuddy"),89 automaticModule("net.bytebuddy.agent", "net.bytebuddy.agent"));90 }91 Configuration configuration = Configuration.resolve(92 moduleFinder,93 Collections.singletonList(ModuleLayer.boot().configuration()),94 ModuleFinder.of(),95 modules96 );97 ClassLoader classLoader = new ReplicatingClassLoader(jar);98 ModuleLayer.Controller controller = ModuleLayer.defineModules(99 configuration,100 Collections.singletonList(ModuleLayer.boot()),101 module -> classLoader102 );103 if (canRead) {104 controller.addReads(105 controller.layer().findModule("mockito.test").orElseThrow(IllegalStateException::new),106 Mockito.class.getModule()107 );108 }109 return controller.layer();110 }111 private static ModuleFinder automaticModule(String moduleName, String... packages) {112 ModuleDescriptor descriptor = ModuleDescriptor.newAutomaticModule(moduleName)113 .packages(new HashSet<>(Arrays.asList(packages)))114 .build();115 ModuleReference reference = new ModuleReference(descriptor, null) {116 @Override117 public ModuleReader open() {118 return new ModuleReader() {119 @Override120 public Optional<URI> find(String name) {121 return Optional.empty();122 }123 @Override124 public Stream<String> list() {125 return Stream.empty();126 }127 @Override128 public void close() {129 }130 };131 }132 };133 return new ModuleFinder() {134 @Override135 public Optional<ModuleReference> find(String name) {136 return name.equals(moduleName) ? Optional.of(reference) : Optional.empty();137 }138 @Override...
list
Using AI Code Generation
1public class ModuleUtilTest {2 public static void main(String[] args) {3 ModuleUtil moduleUtil = new ModuleUtil();4 moduleUtil.list();5 }6}7import org.mockito.moduletest.ModuleUtil;8public class ModuleUtilTest {9 public static void main(String[] args) {10 ModuleUtil moduleUtil = new ModuleUtil();11 moduleUtil.list();12 }13}
list
Using AI Code Generation
1import org.mockito.moduletest.ModuleUtil;2public class Test {3 public static void main(String[] args) {4 ModuleUtil.list();5 }6}7module org.mockito.moduletest {8 requires org.mockito;9}10module org.mockito{11 requires java.logging;12 requires java.sql;13 requires java.xml;14 requires java.xml.bind;15 requires java.xml.ws;16 exports org.mockito;17 exports org.mockito.cglib.core;18 exports org.mockito.cglib.proxy;19 exports org.mockito.cglib.reflect;20 exports org.mockito.cglib.transform;21 exports org.mockito.cglib.util;22 exports org.mockito.cglib.util.ParallelSorter;23 exports org.mockito.cglib.util.ParallelSorter.JDK9;24 exports org.mockito.exceptions;25 exports org.mockito.exceptions.base;26 exports org.mockito.exceptions.misusing;27 exports org.mockito.exceptions.misusing.cannotverify;28 exports org.mockito.exceptions.misusing.missingmethod;29 exports org.mockito.exceptions.misusing.notAMockException;30 exports org.mockito.exceptions.stacktrace;31 exports org.mockito.exceptions.verification;32 exports org.mockito.exceptions.verification.junit.ArgumentsAreDifferent;
list
Using AI Code Generation
1package org.mockito.moduletest;2import java.util.List;3import org.mockito.moduletest.ModuleUtil;4public class MainClass {5public static void main(String[] args) {6 List<String> modules = ModuleUtil.list();7 System.out.println(modules);8}9}10package org.mockito.core;11import java.util.List;12import org.mockito.core.ModuleUtil;13public class MainClass {14public static void main(String[] args) {15 List<String> modules = ModuleUtil.list();16 System.out.println(modules);17}18}
list
Using AI Code Generation
1import org.mockito.moduletest.ModuleUtil;2public class ModuleTest {3 public static void main(String[] args) {4 ModuleUtil util = new ModuleUtil();5 util.list();6 }7}
list
Using AI Code Generation
1package org.mockito.moduletest;2import java.io.File;3import java.util.List;4public class ModuleUtilTest {5public static void main(String[] args) {6List<File> files = ModuleUtil.list(new File("C:\\Users\\user\\Desktop\\test"));7for (File file : files) {8System.out.println(file);9}10}11}
list
Using AI Code Generation
1import org.mockito.moduletest.ModuleUtil;2public class ModuleTest {3 public static void main(String[] args) {4 ModuleUtil.list();5 }6}
list
Using AI Code Generation
1import org.mockito.moduletest.ModuleUtil;2public class Test {3 public static void main(String[] args) {4 System.out.println("Modules: " + ModuleUtil.list());5 }6}
list
Using AI Code Generation
1import org.mockito.moduletest.ModuleUtil;2import java.util.List;3public class ModuleUtilTest{4public static void main(String[] args){5ModuleUtil moduleUtil=new ModuleUtil();6List<String> modules=moduleUtil.getModules();7for(String module:modules){8System.out.println(module);9}10}11}
list
Using AI Code Generation
1import org.mockito.moduletest.ModuleUtil;2import java.util.List;3public class 1 {4public static void main(String[] args) {5List<String> modules = ModuleUtil.list();6System.out.println(modules);7}8}9package org.mockito.moduletest;10import java.util.List;11import java.util.ArrayList;12import java.lang.reflect.Module;13public class ModuleUtil {14public static List<String> list() {15List<String> modules = new ArrayList<>();16Module[] moduleArray = ModuleUtil.class.getModule().getLayer().modules().toArray(Module[]::new);17for (Module module : moduleArray) {18modules.add(module.getName());19}20return modules;21}22}23package org.mockito.moduletest;24import java.util.List;25import java.util.ArrayList;26import java.lang.reflect.Module;27public class ModuleUtil {28public static List<String> list() {29List<String> modules = new ArrayList<>();30Module[] moduleArray = ModuleUtil.class.getModule().getLayer().modules().toArray(Module[]::new);31for (Module module : moduleArray) {32modules.add(module.getName());33}34return modules;35}36}37package org.mockito.moduletest;38import java.util.List;39import java.util.ArrayList;40import java.lang.reflect.Module;41public class ModuleUtil {42public static List<String> list() {43List<String> modules = new ArrayList<>();44Module[] moduleArray = ModuleUtil.class.getModule().getLayer().modules().toArray(Module[]::new);45for (Module module : moduleArray) {46modules.add(module.getName());47}
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!!