merge with fork

This commit is contained in:
Ahmed Tawila 2017-10-27 10:16:18 +02:00
commit e6058445d9
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,9 @@
package com.baeldung.concurrent.daemon;
public class NewThread extends Thread {
public void run() {
for (int i = 0; i < 10; i++)
System.out.println("New Thread is running...");
}
}

View File

@ -0,0 +1,33 @@
package com.baeldung.concurrent.daemon;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class DaemonThreadTest {
@Test
public void whenCallIsDaemon_thenCorrect() {
NewThread daemonThread = new NewThread();
NewThread userThread = new NewThread();
daemonThread.setDaemon(true);
daemonThread.start();
userThread.start();
assertTrue(daemonThread.isDaemon());
assertFalse(userThread.isDaemon());
}
@Test(expected = IllegalThreadStateException.class)
public void givenUserThread_whenSetDaemonWhileRunning_thenIllegalThreadStateException() {
NewThread daemonThread = new NewThread();
daemonThread.start();
daemonThread.setDaemon(true);
}
@Test
public void givenUserThread_whenStartThread_thenFalse() {
NewThread daemonThread = new NewThread();
}
}

View File

@ -5,6 +5,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
<<<<<<< HEAD
=======
import java.io.UnsupportedEncodingException;
>>>>>>> ef4ee45a18de65b0c81bbe8da16c0b063b2201a5
import java.nio.charset.StandardCharsets;
import java.util.IllegalFormatException;
import java.util.regex.PatternSyntaxException;
@ -29,11 +33,25 @@ public class StringTest {
}
@Test
<<<<<<< HEAD
public void whenGetBytes_thenCorrect() {
byte[] byteArray = "abcd".getBytes();
byte[] expected = new byte[] { 97, 98, 99, 100 };
assertArrayEquals(expected, byteArray);
=======
public void whenGetBytes_thenCorrect() throws UnsupportedEncodingException {
byte[] byteArray1 = "abcd".getBytes();
byte[] byteArray2 = "efgh".getBytes(StandardCharsets.US_ASCII);
byte[] byteArray3 = "ijkl".getBytes("UTF-8");
byte[] expected1 = new byte[] { 97, 98, 99, 100 };
byte[] expected2 = new byte[] { 101, 102, 103, 104 };
byte[] expected3 = new byte[] { 105, 106, 107, 108 };
assertArrayEquals(expected1, byteArray1);
assertArrayEquals(expected2, byteArray2);
assertArrayEquals(expected3, byteArray3);
>>>>>>> ef4ee45a18de65b0c81bbe8da16c0b063b2201a5
}
@Test
@ -123,6 +141,7 @@ public class StringTest {
@Test
public void whenCallLastIndexOf_thenCorrect() {
assertEquals(2, "foo".lastIndexOf("o"));
assertEquals(2, "foo".lastIndexOf(111));
}
@Test