Skip to content

Commit

Permalink
dc/TACO-425 updated unit test comments and variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
khappucino committed Aug 5, 2018
1 parent caa9b45 commit cb7a0b4
Showing 1 changed file with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RouteReloaderUnitTest extends Assert {

@Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();

private static final String inputJson = "input.json";
private static final String inputJsonFilename = "input.json";
private static final String helloWorldValue = "helloworld";
private static final String badValue = "badValue";
private static final String changedValue = "changedValue";
Expand Down Expand Up @@ -80,7 +80,7 @@ public void testInitHappyPath() throws Exception {
RouteReloader<TrivialFactory> subject =
new RouteReloader<TrivialFactory>(executor, TrivialFactory::new);
String initialFileContents = helloWorldValue;
String input = rawCreateConf(initialFileContents, inputJson);
String input = rawCreateConf(initialFileContents, inputJsonFilename);
TrivialFactory initialValue = subject.init(input);
assertEquals(initialFileContents, initialValue.inputString);
}
Expand All @@ -92,23 +92,23 @@ public void testInitBadValue() throws Exception {
RouteReloader<TrivialFactory> subject =
new RouteReloader<TrivialFactory>(executor, TrivialFactory::new);
String initialFileContents = badValue;
String input = rawCreateConf(initialFileContents, inputJson);
String input = rawCreateConf(initialFileContents, inputJsonFilename);
TrivialFactory initialValue = subject.init(input);
}

@Test
public void testReload_WhenWatchedFilesDoNotChange() throws Exception {

AtomicBoolean fireUpdatedCalled = new AtomicBoolean(false);
// set initial conditions for applicationConf and includeFileConf
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1);

RouteReloader<TrivialFactory> subject =
new RouteReloader<TrivialFactory>(executor, TrivialFactory::new);
String initialFileContents = helloWorldValue;
String input = rawCreateConf(initialFileContents, inputJson);
// when the input file changes we will get a update fired
String input = rawCreateConf(initialFileContents, inputJsonFilename);
// init the subject with an file that contains the helloworldvalue
TrivialFactory initialValue = subject.init(input);
// the result from the init should be the baseline TrivialFactory output and it should match the helloworldvalue
assertEquals(initialFileContents, initialValue.inputString);

TrivialState state =
Expand All @@ -119,8 +119,10 @@ public void fireUpdated() {
}
};

// start the threaded update
subject.start(state::update);
Thread.sleep(5000);
// since we did not change any files we should not get an update
assertFalse(fireUpdatedCalled.get());
// the update should have never been called and these values should not be set
assertEquals(null, state.oldValue);
Expand All @@ -133,15 +135,15 @@ public void testReload_WhenWatchedFilesChange_Date_Was_Modified_and_Digest_Was_N
throws Exception {

AtomicBoolean fireUpdatedCalled = new AtomicBoolean(false);
// set initial conditions for applicationConf and includeFileConf
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1);

RouteReloader<TrivialFactory> subject =
new RouteReloader<TrivialFactory>(executor, TrivialFactory::new);
String initialFileContents = helloWorldValue;
String input = rawCreateConf(initialFileContents, inputJson);
// when the input file changes we will get a update fired
String input = rawCreateConf(initialFileContents, inputJsonFilename);
// init the subject with an file that contains the helloworldvalue
TrivialFactory initialValue = subject.init(input);
// the result from the init should be the baseline TrivialFactory output and it should match the helloworldvalue
assertEquals(initialFileContents, initialValue.inputString);

TrivialState state =
Expand All @@ -155,10 +157,10 @@ public void fireUpdated() {
subject.start(state::update);
Thread.sleep(5000);
String changedFileContents = helloWorldValue;
// create new file over old file with same value
String changed = rawCreateConf(changedFileContents, inputJson);
// create new file and overwrite the old file with same value
String changed = rawCreateConf(changedFileContents, inputJsonFilename);
Thread.sleep(5000);
// the update should have never been called
// the update should have never been called since the digest (file contents) did not change
assertFalse(fireUpdatedCalled.get());
// these values should not have been set since the update did not occur
assertEquals(null, state.oldValue);
Expand All @@ -171,15 +173,15 @@ public void testReload_WhenWatchedFilesChange_Date_Was_Modified_and_Digest_Was_C
throws Exception {

AtomicBoolean fireUpdatedCalled = new AtomicBoolean(false);
// set initial conditions for applicationConf and includeFileConf
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1);

RouteReloader<TrivialFactory> subject =
new RouteReloader<TrivialFactory>(executor, TrivialFactory::new);
String initialFileContents = helloWorldValue;
String input = rawCreateConf(initialFileContents, inputJson);
// when the input file changes we will get a update fired
String input = rawCreateConf(initialFileContents, inputJsonFilename);
// init the subject with an file that contains the helloworldvalue
TrivialFactory initialValue = subject.init(input);
// the result from the init should be the baseline TrivialFactory output and it should match the helloworldvalue
assertEquals(initialFileContents, initialValue.inputString);

TrivialState state =
Expand All @@ -193,10 +195,10 @@ public void fireUpdated() {
subject.start(state::update);
Thread.sleep(5000);
String changedFileContents = changedValue;
// create new file over old file with different value
String changed = rawCreateConf(changedFileContents, inputJson);
// create new file overwrite the old file with different value
String changed = rawCreateConf(changedFileContents, inputJsonFilename);
Thread.sleep(5000);
// the update should have been called
// the update should have been called since the file contents have changed
assertTrue(fireUpdatedCalled.get());
// the old value in the update should be the original value
assertEquals(initialFileContents, state.oldValue.inputString);
Expand All @@ -209,15 +211,15 @@ public void fireUpdated() {
public void testReload_WhenWatchedFilesChange_BadUpdate() throws Exception {

AtomicBoolean fireUpdatedCalled = new AtomicBoolean(false);
// set initial conditions for applicationConf and includeFileConf
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1);

RouteReloader<TrivialFactory> subject =
new RouteReloader<TrivialFactory>(executor, TrivialFactory::new);
String initialFileContents = helloWorldValue;
String input = rawCreateConf(initialFileContents, inputJson);
// when the input file changes we will get a update fired
String input = rawCreateConf(initialFileContents, inputJsonFilename);
// init the subject with an file that contains the helloworldvalue
TrivialFactory initialValue = subject.init(input);
// the result from the init should be the baseline TrivialFactory output and it should match the helloworldvalue
assertEquals(initialFileContents, initialValue.inputString);

TrivialState state =
Expand All @@ -231,8 +233,8 @@ public void fireUpdated() {
subject.start(state::update);
Thread.sleep(5000);
String changedFileContents = badValue;
// create new file over old file with BAD value
String changed = rawCreateConf(changedFileContents, inputJson);
// create new file overwrite the old file with BAD value
String changed = rawCreateConf(changedFileContents, inputJsonFilename);
Thread.sleep(5000);
// the update should have never been called since the update was BAD
assertFalse(fireUpdatedCalled.get());
Expand All @@ -250,7 +252,7 @@ public void testStartWithoutInit() throws Exception {
RouteReloader<TrivialFactory> subject =
new RouteReloader<TrivialFactory>(executor, TrivialFactory::new);
String initialFileContents = helloWorldValue;
String input = rawCreateConf(initialFileContents, inputJson);
String input = rawCreateConf(initialFileContents, inputJsonFilename);
TrivialState state =
new TrivialState() {
@Override
Expand All @@ -259,22 +261,20 @@ public void fireUpdated() {
}
};

// this should throw an exception
// this should throw an exception since we called start without first calling init
subject.start(state::update);
}

@Test
public void testStartHappyPath() throws Exception {

AtomicBoolean fireUpdatedCalled = new AtomicBoolean(false);
// set initial conditions for applicationConf and includeFileConf
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1);

RouteReloader<TrivialFactory> subject =
new RouteReloader<TrivialFactory>(executor, TrivialFactory::new);
String initialFileContents = helloWorldValue;
String input = rawCreateConf(initialFileContents, inputJson);
// when the input file changes we will get a update fired
String input = rawCreateConf(initialFileContents, inputJsonFilename);
TrivialFactory initialValue = subject.init(input);
assertEquals(initialFileContents, initialValue.inputString);

Expand All @@ -286,7 +286,7 @@ public void fireUpdated() {
}
};

// this should NOT throw an exception
// this should NOT throw an exception because we called init before calling start
subject.start(state::update);
executor.shutdown();
}
Expand Down

0 comments on commit cb7a0b4

Please sign in to comment.