BAEL-1171 java.lang.String API (#2874)
* Evaluation article: Different Types of Bean Injection in Spring * added tests & changed configuration to Java-based config * removed xml config files * rename unit tests * BAEL-972 - Apache Commons Text * remove code from evaluation article * remove code from evaluation article * BAEL-972 - Apache Commons Text - added another example * BAEL-972 - Apache Commons Text - just indentation * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java - fix problems * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * fix formatting * BAEL-1033 minor refactor * BAEL-1035 Introduction to Eclipse Collections * format * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * cleanup * cleanup * BAEL-1109 Introduction to JCache * BAEL-1109 Introduction to JCache * remove unneeded property in pom.xml * fix formatting * close cache instances properly * remove latest commit * BAEL-1057 Introduction to rxjava-jdbc * refactor rxjava-jdbc * Refactor rxjava-jdbc * Refactoring rxjava-jdbc * BAEL-1171 java.lang.String API * refactor rxjava-jdbc * refactor String * String API - move multiple classes into a single class * move class into test package * BAEL-1171 String.lang.String API * BAEL-1171 java.lang.String API * BAEL-1250 Initializing Arrays in Java * BAEL-1250 Initializing Arrays in Java * BAEL-1250 Initializing Arrays in Java * small fix * BAEL-1171 java.lang.String API * BAEL-1263 Daemon Threads in Java * BAEL-1263 Daemon Threads in Java
This commit is contained in:
parent
2f060a8f28
commit
dbeb5f8ba4
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.concurrent.daemon;
|
||||
|
||||
public class NewThread extends Thread {
|
||||
|
||||
public void run() {
|
||||
while (true)
|
||||
for (int i = 0; i < 10; i++)
|
||||
System.out.println("New Thread is running...");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.IllegalFormatException;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
@ -29,11 +30,17 @@ public class StringTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void whenGetBytes_thenCorrect() {
|
||||
byte[] byteArray = "abcd".getBytes();
|
||||
byte[] expected = new byte[] { 97, 98, 99, 100 };
|
||||
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(expected, byteArray);
|
||||
assertArrayEquals(expected1, byteArray1);
|
||||
assertArrayEquals(expected2, byteArray2);
|
||||
assertArrayEquals(expected3, byteArray3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -123,6 +130,7 @@ public class StringTest {
|
|||
@Test
|
||||
public void whenCallLastIndexOf_thenCorrect() {
|
||||
assertEquals(2, "foo".lastIndexOf("o"));
|
||||
assertEquals(2, "foo".lastIndexOf(111));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue