Java Runtime.getRuntime(): getting output from executing a command line program

I’m using the runtime to run command prompt commands from my Java program. However, I’m not aware of how I can get the output the command returns. Here is my code: Runtime rt = Runtime.getRuntime(); String[] commands = {“system.exe”, “-send” , argument}; Process proc = rt.exec(commands); I tried doing System.out.println(proc); but that did not return … Read more

How can I lookup a Java enum from its String value?

I would like to lookup an enum from its string value (or possibly any other value). I’ve tried the following code but it doesn’t allow static in initialisers. Is there a simple way? public enum Verbosity { BRIEF, NORMAL, FULL; private static Map<String, Verbosity> stringMap = new HashMap<String, Verbosity>(); private Verbosity() { stringMap.put(this.toString(), this); } … Read more

HashMap – getting First Key value

Below are the values contain in the HashMap statusName {Active=33, Renewals Completed=3, Application=15} Java code to getting the first Key (i.e Active) Object myKey = statusName.keySet().toArray()[0]; How can we collect the first Key “Value” (i.e 33), I want to store both the “Key” and “Value” in separate variable. 11 Answers 11

Mockito + PowerMock LinkageError while mocking system class

I’ve got such a code snippet: @RunWith(PowerMockRunner.class) @PrepareForTest({Thread.class}) public class AllMeasuresDataTest { @Before public void setUp() throws Exception { } @Test public void testGetMeasures() { AllMeasuresData measure = new AllMeasuresData(); assertEquals(measure.getMeasures(), null); HashMap<String, Measure> map = new HashMap<String, Measure>(); measure.setMeasures(map); assertEquals(measure.getMeasures(), map); measure.setMeasures(null); assertEquals(measure.getMeasures(), null); } @Test public void testAllMeasuresData() throws IOException { ClassLoader loader … Read more

How do I get my Maven Integration tests to run

I have a maven2 multi-module project and in each of my child modules I have JUnit tests that are named Test.java and Integration.java for unit tests and integration tests respectively. When I execute: mvn test all of the JUnit tests *Test.java within the child modules are executed. When I execute mvn test -Dtest=**/*Integration none of … Read more