Skip to content

Instantly share code, notes, and snippets.

@dbrimley
Created November 22, 2016 14:46
Show Gist options
  • Save dbrimley/e81f05e841e86336a0d13a798773e259 to your computer and use it in GitHub Desktop.
Save dbrimley/e81f05e841e86336a0d13a798773e259 to your computer and use it in GitHub Desktop.
Value Method is called using putIfAbsent
package com.craftedbytes.concurrency;
import org.junit.Test;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by davidbrimley on 22/11/2016.
*/
public class PutIfAbsentTest {
@Test
public void proveValueMethodIsCalledEvenWhenKeyIsPresent() throws Exception {
ConcurrentHashMap<Integer,String> map = new ConcurrentHashMap<Integer, String>();
map.put(1,"Existing Value");
map.putIfAbsent(1,callMethod());
}
private String callMethod() throws Exception {
throw new Exception("Calling the method!!!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment