forked from spring-attic/spring-roo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ROO-2745: Post 1.2.0.M1 code refactor and clean up - added private co…
…nstructors to util classes; added JavaDoc and a unit test
- Loading branch information
Andrew Swan
committed
Oct 5, 2011
1 parent
2875458
commit c7198e6
Showing
5 changed files
with
128 additions
and
32 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
shell/src/main/java/org/springframework/roo/shell/CliOptionContext.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,40 @@ | ||
package org.springframework.roo.shell; | ||
|
||
/** | ||
* Utility methods relating to shell option contexts | ||
*/ | ||
public final class CliOptionContext { | ||
|
||
// Class fields | ||
private static ThreadLocal<String> optionContextHolder = new ThreadLocal<String>(); | ||
|
||
/** | ||
* Returns the option context for the current thread. | ||
* | ||
* @return <code>null</code> if none has been set | ||
*/ | ||
public static String getOptionContext() { | ||
return optionContextHolder.get(); | ||
} | ||
|
||
/** | ||
* Stores the given option context for the current thread. | ||
* | ||
* @param optionContext the option context to store | ||
*/ | ||
public static void setOptionContext(String optionContext) { | ||
optionContextHolder.set(optionContext); | ||
} | ||
|
||
/** | ||
* Resets the option context for the current thread. | ||
*/ | ||
public static void resetOptionContext() { | ||
optionContextHolder.remove(); | ||
} | ||
|
||
/** | ||
* Constructor is private to prevent instantiation | ||
*/ | ||
private CliOptionContext() {} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
shell/src/test/java/org/springframework/roo/shell/CliOptionContextTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.springframework.roo.shell; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Unit test of {@link CliOptionContext} | ||
* | ||
* @author Andrew Swan | ||
* @since 1.2.0 | ||
*/ | ||
public class CliOptionContextTest { | ||
|
||
// Constants | ||
private static final String OPTION_CONTEXT = "anything"; | ||
|
||
@Test | ||
public void testGetOptionContextWhenNoneSet() { | ||
assertNull(CliOptionContext.getOptionContext()); | ||
} | ||
|
||
@Test | ||
public void testSetAndGetOptionContext() { | ||
// Set up | ||
CliOptionContext.setOptionContext(OPTION_CONTEXT); | ||
|
||
// Invoke and check | ||
assertEquals(OPTION_CONTEXT, CliOptionContext.getOptionContext()); | ||
} | ||
|
||
@Test | ||
public void testResetOptionContext() { | ||
// Set up | ||
CliOptionContext.setOptionContext(OPTION_CONTEXT); | ||
|
||
// Invoke | ||
CliOptionContext.resetOptionContext(); | ||
|
||
// Check | ||
assertNull(CliOptionContext.getOptionContext()); | ||
} | ||
} |
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