Skip to content

Commit

Permalink
Merge a38e7ee into 2899033
Browse files Browse the repository at this point in the history
  • Loading branch information
Tendonge Ryan committed Mar 17, 2019
2 parents 2899033 + a38e7ee commit 0d6aa09
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/org/openmrs/Cohort.java
Expand Up @@ -401,6 +401,6 @@ public int activeMembershipSize() {
* @return true if no active cohort exists
**/
public boolean hasNoActiveMemberships() {
return getActiveMemberships().isEmpty();
return activeMembershipSize() == 0;
}
}
17 changes: 16 additions & 1 deletion api/src/main/java/org/openmrs/Obs.java
Expand Up @@ -1111,7 +1111,22 @@ public void setValueAsString(String s) throws ParseException {
} else if ("ST".equals(abbrev)) {
setValueText(s);
} else {
throw new RuntimeException("Don't know how to handle " + abbrev);
String[] supportedFormats = { "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS",
"yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ssXXX", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd HH:mm:ss"};
boolean flag = false;
for (int i = 0; i < supportedFormats.length; i++) {
try {
DateFormat dateFormat = new SimpleDateFormat(supportedFormats[i]);
setValueDatetime(dateFormat.parse(s));
flag = false;
break;
}
catch (Exception ex) {
flag = true;
}
}
if (flag)
throw new RuntimeException("Don't know how to handle " + abbrev);
}

} else {
Expand Down
38 changes: 38 additions & 0 deletions api/src/test/java/org/openmrs/ObsTest.java
Expand Up @@ -331,6 +331,44 @@ public void setValueAsString_shouldFailIfTheValueOfTheStringIsNull() throws Exce
Obs obs = new Obs();
obs.setValueAsString(null);
}

/**
* @see Obs#setValueAsString(String)
*/
@Test
public void setValueAsString_shouldSetValueAsDateTimeIfDataTypeOfQuestionConceptIsDateTimeHavingTimeZone()
throws Exception {
Obs obs = new Obs();
ConceptDatatype cdt = new ConceptDatatype();
Concept c = new Concept();
c.setDatatype(cdt);
obs.setConcept(c);

String[] dates1 = { "2016-01-12T06:00:00+05:30", "2016-01-12T06:00:00+0530" };
String[] dates2 = { "2014-02-20T11:00:00.000-05:00", "2014-02-20T11:00:00.000-05" };

for (String date : dates1) {
obs.setValueAsString(date);
}

for (String date : dates2) {
obs.setValueAsString(date);
}
}

/**
* @see Obs#setValueAsString(String)
*/
@Test(expected = RuntimeException.class)
public void setValueAsString_shouldThrowRuntimeExceptionForAbbreviationCWE() throws Exception {
Obs obs = new Obs();
ConceptDatatype cdt = new ConceptDatatype();
cdt.setHl7Abbreviation("CWE");
Concept c = new Concept();
c.setDatatype(cdt);
obs.setConcept(c);
obs.setValueAsString("ABC");
}

/**
* @see Obs#getValueAsBoolean()
Expand Down
48 changes: 0 additions & 48 deletions api/src/test/java/org/openmrs/module/ModuleUtilTest.java
Expand Up @@ -20,10 +20,7 @@
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Collection;
import java.util.Properties;
import java.util.jar.JarFile;

Expand Down Expand Up @@ -708,52 +705,7 @@ public void expandJar_shouldExpandFileWithParentTreeIfNameIsFileAndKeepFullPathI

FileUtils.deleteDirectory(destinationFolder);
}

/**
* @see ModuleUtil#file2url(File)
*/
@Test
public void file2url_shouldReturnNullIfFileIsNull() throws MalformedURLException {
URL nullURL = ModuleUtil.file2url(null);
Assert.assertNull(nullURL);
}

/**
* @see ModuleUtil#file2url(File)
*/
@Test(expected = MalformedURLException.class)
public void file2url_shouldThrowMalformedURLExceptionIfMalformedFilePath() throws MalformedURLException {
ModuleUtil.file2url(new File("org/openmrs/" + "\0" + "/include/test1-1.0-SNAPSHOT.omod"));
}

/**
* @see ModuleUtl#getPackagesFromFile(File)
*/
@Test
public void getPackagesFromFile_shouldReturnEmptyStringSetIfNonJarFile() {
File f = new File(this.getClass().getResource("/org/openmrs/module/include/test1-1.0-SNAPSHOT.omod").getFile());
Collection<String> packageCollection = ModuleUtil.getPackagesFromFile(f);
Assert.assertTrue(packageCollection.isEmpty());
}

/**
* @see ModuleUtl#getPackagesFromFile(File)
*/
@Test
public void getPackagesFromFile_shouldSkipOptionalFoldersIfJarFile() throws IOException{
File f = new File(this.getClass().getResource("/org/openmrs/module/include/test1-1.0-SNAPSHOT.omod").getFile());
File d = new File("/tmp/test1-1.0-SNAPSHOT.jar");
FileUtils.copyFile(f, d);
Collection<String> packageCollection = ModuleUtil.getPackagesFromFile(d);

Assert.assertFalse(packageCollection.isEmpty());
for (String string : packageCollection) {
Assert.assertFalse(string.contains("lib"));
Assert.assertFalse(string.contains("META-INF"));
Assert.assertFalse(string.contains("web/module"));
}
}

/**
* Gets Jar file to be expanded.
*
Expand Down

0 comments on commit 0d6aa09

Please sign in to comment.