BAEL-1307 Java Nested Classes (#3157)
* 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 * merge with fork * BAEL-1263 Daemon Threads in Java * fix compilation error * BAEL-1309 Append Data to a File with Java * fix build fails * fix test error * fix build failures * cleanup * fix Sneaky Runnable test * revert sneaky runnable fix attempt * fix test failure * fix test failure * fix all test failures * fix test failure * fix test failures * Nested Classes in Java * enhance nested classes
This commit is contained in:
		
							parent
							
								
									d45a891d4c
								
							
						
					
					
						commit
						42c894e7f9
					
				| @ -1,11 +0,0 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| public class Enclosing { | ||||
| 
 | ||||
|     public static class Nested { | ||||
| 
 | ||||
|         public void test() { | ||||
|             System.out.println("Calling test..."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -1,11 +0,0 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| public class Outer { | ||||
| 
 | ||||
|     public class Inner { | ||||
| 
 | ||||
|         public void test() { | ||||
|             System.out.println("Calling test..."); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -1,5 +0,0 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| abstract class SimpleAbstractClass { | ||||
|     abstract void run(); | ||||
| } | ||||
| @ -2,10 +2,14 @@ package com.baeldung.nestedclass; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class AnonymousInnerTest { | ||||
| abstract class SimpleAbstractClass { | ||||
|     abstract void run(); | ||||
| } | ||||
| 
 | ||||
| public class AnonymousInner { | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenRunAnonymousClass_thenCorrect() { | ||||
|     public void run() { | ||||
|         SimpleAbstractClass simpleAbstractClass = new SimpleAbstractClass() { | ||||
|             void run() { | ||||
|                 System.out.println("Running Anonymous Class..."); | ||||
| @ -0,0 +1,21 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class Enclosing { | ||||
| 
 | ||||
|     private static int x = 1; | ||||
| 
 | ||||
|     public static class StaticNested { | ||||
| 
 | ||||
|         private void run() { | ||||
|             System.out.println("x = " + x); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void test() { | ||||
|         Enclosing.StaticNested nested = new Enclosing.StaticNested(); | ||||
|         nested.run(); | ||||
|     } | ||||
| } | ||||
| @ -1,13 +0,0 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class InnerClassTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenInnerClassWhenInstantiating_thenCorrect() { | ||||
|         Outer outer = new Outer(); | ||||
|         Outer.Inner inner = outer.new Inner(); | ||||
|         inner.test(); | ||||
|     } | ||||
| } | ||||
| @ -1,12 +0,0 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class LocalClassTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenTestingLocalClass_thenCorrect() { | ||||
|         NewEnclosing newEnclosing = new NewEnclosing(); | ||||
|         newEnclosing.run(); | ||||
|     } | ||||
| } | ||||
| @ -1,12 +0,0 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class NestedClassTest { | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenInstantiatingStaticNestedClass_thenCorrect() { | ||||
|         Enclosing.Nested nested = new Enclosing.Nested(); | ||||
|         nested.test(); | ||||
|     } | ||||
| } | ||||
| @ -1,10 +1,11 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class NewEnclosing { | ||||
| 
 | ||||
|     void run() { | ||||
|     private void run() { | ||||
|         class Local { | ||||
| 
 | ||||
|             void run() { | ||||
|                 System.out.println("Welcome to Baeldung!"); | ||||
|             } | ||||
| @ -12,4 +13,10 @@ public class NewEnclosing { | ||||
|         Local local = new Local(); | ||||
|         local.run(); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void test() { | ||||
|         NewEnclosing newEnclosing = new NewEnclosing(); | ||||
|         newEnclosing.run(); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,30 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class NewOuter { | ||||
| 
 | ||||
|     int a = 1; | ||||
|     static int b = 2; | ||||
| 
 | ||||
|     public class InnerClass { | ||||
|         int a = 3; | ||||
|         static final int b = 4; | ||||
| 
 | ||||
|         public void run() { | ||||
|             System.out.println("a = " + a); | ||||
|             System.out.println("b = " + b); | ||||
|             System.out.println("NewOuterTest.this.a = " + NewOuter.this.a); | ||||
|             System.out.println("NewOuterTest.b = " + NewOuter.b); | ||||
|             System.out.println("NewOuterTest.this.b = " + NewOuter.this.b); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void test() { | ||||
|         NewOuter outer = new NewOuter(); | ||||
|         NewOuter.InnerClass inner = outer.new InnerClass(); | ||||
|         inner.run(); | ||||
| 
 | ||||
|     } | ||||
| } | ||||
| @ -1,32 +0,0 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| import static org.junit.Assert.assertEquals; | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class NewOuterTest { | ||||
| 
 | ||||
|     int a = 1; | ||||
|     static int b = 2; | ||||
| 
 | ||||
|     public class InnerClass { | ||||
|         int a = 3; | ||||
|         static final int b = 4; | ||||
| 
 | ||||
|         @Test | ||||
|         public void whenShadowing_thenCorrect() { | ||||
|             assertEquals(3, a); | ||||
|             assertEquals(4, b); | ||||
|             assertEquals(1, NewOuterTest.this.a); | ||||
|             assertEquals(2, NewOuterTest.b); | ||||
|             assertEquals(2, NewOuterTest.this.b); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void shadowingTest() { | ||||
|         NewOuterTest outer = new NewOuterTest(); | ||||
|         NewOuterTest.InnerClass inner = outer.new InnerClass(); | ||||
|         inner.whenShadowing_thenCorrect(); | ||||
| 
 | ||||
|     } | ||||
| } | ||||
							
								
								
									
										20
									
								
								core-java/src/test/java/com/baeldung/nestedclass/Outer.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								core-java/src/test/java/com/baeldung/nestedclass/Outer.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | ||||
| package com.baeldung.nestedclass; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class Outer { | ||||
| 
 | ||||
|     public class Inner { | ||||
| 
 | ||||
|         public void run() { | ||||
|             System.out.println("Calling test..."); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void test() { | ||||
|         Outer outer = new Outer(); | ||||
|         Outer.Inner inner = outer.new Inner(); | ||||
|         inner.run(); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user