Created
June 11, 2013 19:44
-
-
Save dimhold/5759968 to your computer and use it in GitHub Desktop.
Util class for unit tests (gist:5759950) just for understand: What is a true way of unit testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package how.to.use.mockito; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.net.URL; | |
import java.nio.channels.Channels; | |
import java.nio.channels.ReadableByteChannel; | |
public class Util { | |
public static void downloadInFile(String url, String file) { | |
try ( | |
ReadableByteChannel byteChannel = Channels.newChannel(new URL(url).openStream()); | |
FileOutputStream fileOutputStream = new FileOutputStream(file); | |
) { | |
fileOutputStream.getChannel().transferFrom(byteChannel, 0, Long.MAX_VALUE); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
public static boolean isMemoryEnough() { | |
long totalMemory = Runtime.getRuntime().totalMemory(); | |
long freeMemory = Runtime.getRuntime().freeMemory(); | |
double freeMemoryInPercent = (double) freeMemory/(double) totalMemory; | |
if (freeMemoryInPercent > AppConfig.MEMORY_ENOUGH_IN_PERCENT_LIMIT) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
class AppConfig { | |
public static final double MEMORY_ENOUGH_IN_PERCENT_LIMIT = 0.48; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment