1 package org.unicode.cldr.util; 2 3 import static org.junit.jupiter.api.Assertions.assertNotNull; 4 import static org.junit.jupiter.api.Assumptions.assumeTrue; 5 6 import java.io.File; 7 import org.junit.jupiter.api.Test; 8 9 public class TestCLDRPaths { 10 public static String HAS_CLDR_ARCHIVE = "HAS_CLDR_ARCHIVE"; 11 12 @Test TestCanUseArchiveDirectory()13 void TestCanUseArchiveDirectory() { 14 if (!canUseArchiveDirectory()) { 15 // We print this warning once as part of the unit tests. 16 System.err.println( 17 String.format( 18 "WARNING: -D%s=false, so skipping tests which use cldr-archive\n" 19 + "See <%s>", 20 HAS_CLDR_ARCHIVE, CLDRURLS.CLDR_ARCHIVE)); 21 } 22 } 23 24 /** 25 * @return true if it's OK to read CLDRPaths.ARCHIVE_DIRECTORY, false to skip. 26 */ canUseArchiveDirectory()27 public static final boolean canUseArchiveDirectory() { 28 if (!CLDRConfig.getInstance().getProperty("HAS_CLDR_ARCHIVE", true)) { 29 return false; // skip due to property 30 } 31 32 final File archiveDir = new File(CLDRPaths.ARCHIVE_DIRECTORY); 33 if (!archiveDir.isDirectory()) { 34 throw new IllegalArgumentException( 35 String.format( 36 "Could not read archive directory -DARCHIVE=%s … You must either: 1) follow instructions at <%s>, " 37 + "or 2) skip cldr-archive tests by setting -D%s=false", 38 archiveDir.getAbsolutePath(), CLDRURLS.CLDR_ARCHIVE, HAS_CLDR_ARCHIVE)); 39 } 40 return true; // OK to use 41 } 42 43 @Test TestReadPrevSDI()44 void TestReadPrevSDI() { 45 // This is also an example of a test that's skipped (by the next line) if 46 // cldr-archive isn't available. 47 assumeTrue(canUseArchiveDirectory()); 48 SupplementalDataInfo SDI_LAST = 49 SupplementalDataInfo.getInstance( 50 CLDRPaths.LAST_RELEASE_DIRECTORY + "common/supplemental/"); 51 assertNotNull(SDI_LAST); 52 } 53 } 54